dojo.provide("parus.designerTableModelDialog");

dojo.require("dijit.Dialog");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.ValidationTextBox");
dojo.require("dijit.form.SimpleTextarea");

dojo.require("parus.parus8");
dojo.require("parus.dialog");
dojo.require("parus.dictEdit");

dojo.require("parus.editDictionaryDialog");

dojo.declare("parus.designerTableModelDialog", [parus.editDictionaryDialog], {

  onLoadParams: function(store, item, editMode) {
    this.inherited(arguments);

    if (store && item) {
      this.codeEdit.attr("value", store.getValue(item, "CODE"));
      this.nameEdit.attr("value", store.getValue(item, "NAME"));
    }
  },

  executeInsert: function(duplicate) {
    var response = parus.database.execute("designer.BalanceTableModels.Insert", {
      RN: duplicate ? this.rn : null,
      CRN: this.crn,
      CODE: this.codeEdit.attr("value"),
      NAME: this.nameEdit.attr("value")
    });

    if (response) return parus.parus8.nodeField(parus.parus8.rowNodes(response)[0], "NRN");
  },

  executeUpdate: function() {
    var response = parus.database.execute("designer.BalanceTableModels.Update", {
      RN: this.rn,
      CODE: this.codeEdit.attr("value"),
      NAME: this.nameEdit.attr("value")
    });

    return !!response;
  },

  executeDelete: function(store, item) {
    var response = parus.database.execute("designer.BalanceTableModels.Delete", {
      RN: store.getValue(item, "RN")
    });

    return !!response;
  }

});