dojo.provide("parus.designerTemplateDialog");

dojo.require("dijit.Dialog");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.DateTextBox");

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

dojo.require("parus.editDictionaryDialog");

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

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

    if (!this.prn) this.prn = this.getParentDialogCondition("PRN"); //editionRN
    if (store && item) {
      this.nameEdit.attr("value", store.getValue(item, "NAME"));
      this.usageSelect.attr("value", store.getValue(item, "USAGE"));
      this.directionSelect.attr("value", store.getValue(item, "DIRECT_TABLE"));
      this.exportToExcelSelect.attr("value", store.getValue(item, "TO_EXCEL_SIGN"));
      this.defaultCheckBox.attr("checked", store.getValue(item, "EDIT_DEFAULT") == "1");

      if (this.editMode) this.directionSelect.attr("disabled", true);
    }
  },

  executeInsert: function(duplicate) {
    var response = parus.database.execute(duplicate ? "duplicateDesignerTemplate" : "insertDesignerTemplate", {
      RN: duplicate ? this.rn : null,
      PRN: this.prn,
      NAME: this.nameEdit.attr("value"),
      USAGE: this.usageSelect.attr("value"),
      DIRECT_TABLE: this.directionSelect.attr("value"),
      TO_EXCEL_SIGN: this.exportToExcelSelect.attr("value"),
      EDIT_DEFAULT: (this.defaultCheckBox.attr("checked") ? "1" : "0")
    });

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

  executeUpdate: function() {
    var response = parus.database.execute("updateDesignerTemplate", {
      RN: this.rn,
      NAME: this.nameEdit.attr("value"),
      USAGE: this.usageSelect.attr("value"),
      TO_EXCEL_SIGN: this.exportToExcelSelect.attr("value"),
      EDIT_DEFAULT: (this.defaultCheckBox.attr("checked") ? "1" : "0")
    });

    return !!response;
  },

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

    return !!response;
  }

});