if (!Kwo) var Kwo = {};

Kwo.Alert = {

  onAdd: function () {
    Kwo.Alert.onEdit(0);
  },

  onCallback: function (res) {
    if (Kwo.hasError(res)) return Kwo.error(res);
    Kwo.go("alert.list");
  },

  onCancel: function () {
    $("alert-panel").update();
  },

  onDestroy: function (args) {
    args = $(args).up("FORM");
    Kwo.exec("alert.destroy", args,
             {callback: true, confirm: args});
  },

  onEdit: function (id) {
    Kwo.exec("alert.edit", {"id": id},
             {container: $("alert-panel")});
  },

  onSave: function (args) {
    var hash = $(args).serialize(true);
    if (hash["term"].blank()) return ;
    var dialog = Kwo.getDialog("alert");
    dialog.args = {term: hash["term"]};
    dialog.refresh();
  },

  onSubmit: function (args) {
    Kwo.exec("alert.store", args,
             {callback: Kwo.Alert.onCallback});
  }

}

Kwo.Class.Alert = Class.create(Kwo.Dialog, {

  initialize: function($super, args) {
    this.name = "alert";
    this.className = "layout-hbox";
    this.args = args;
    $super(this.refresh, this.args, {width: 500, height: 300});
  },
  
  refresh: function() {
    var action = this.args ? "alert.save" : "alert.prompt";
    Kwo.exec("/alert/" + action, this.args, 
             {container: this.support});
  }

});