
Kwo.Alert = {

  onCancel: function(elt) {
    $(elt).up("TD.column").update();
  },

  onDelete: function(elt) {
    elt = $(elt);
    Kwo.exec("alert.delete", elt.up("FORM"),
             {callback:true, confirm:elt});
  },

  onEdit: function(elt) {
    elt = $(elt)
    var args = {id: elt.readAttribute("data-id")};
    Kwo.exec("alert.edit", args,
             {container: elt.up("TD.column").next()});
  },

  onUpdate: function(args) {
    Kwo.exec("alert.update", args,
             {callback: true});
  }

};

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

  submited: false,

  initialize: function($super, elt) {
    elt = $(elt);
    this.name = "alert";
    this.className = "layout-hbox";
    this.args = {};
    if (elt.readAttribute("data-item-key")) {
      this.args = {item_key: elt.readAttribute("data-item-key")};
    }
    else {
      this.args = {keyword: elt.readAttribute("data-keyword")};
    }
    this.width = 400;
    this.height = 250;
    $super(this.onDisplay, this.args);
  },
  
  onDisplay: function() { 
    var type = "item_key" in this.args ? "item" : "keyword"; 
    Kwo.exec("/alert/alert." + type + ".prompt", this.args, 
             {container: this.support});
  },

  onSave: function(args) {
    if (!Kwo.isAuth()) {
      var auth = new Kwo.Class.Auth();
      auth.onCallback = this.onSave.bind(this).curry(args);
      return ;
    }
    if ("item_key" in this.args) {
      args = this.args;
    }
    this.submited = true;
    Kwo.exec("/alert/alert.save", args,
             {container: this.support});
  },

  onAfterClose: function() {
    if (this.submited === true && "_scope" in window && window["_scope"] === "account") {
      Kwo.go("alert.list");
    }
  }

});
