dojo.provide("parus.designerReportTableIndexDialog");

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.formats");
dojo.require("parus.controlActions");

dojo.require("parus.editableDictionaryDialog");
dojo.require("parus.editDictionaryDialog");

dojo.require("parus.designerTableModelIndexDialog");

dojo.require("parus.designerReportIndexDialog"); //UI is the same
dojo.require("parus.designerReportTableNotIncludedIndexesDictionaryDialog");

dojo.declare("parus.designerReportTableIndexDialog", [parus.designerReportIndexDialog], {

  getIndexCondition: function() {
    return {
      PRN: this.prn
    };
  },

  executeInsert: function(duplicate) {
    var response = parus.database.execute("designer.BalanceTables.Indexes.Insert", {
      PRN: this.prn,
      BALANCEINDEX: this.indexEdit.attr("value"),
      DICTIONARY: this.dictionaryEdit.attr("value"),
      PRIORITY: this.priorityEdit.attr("value"),
      AGR_FUNC: this.agrFuncSelect.attr("value"),
      NULLABLE: this.nullableCheckBox.attr("checked") ? "1" : "0",
      DICT_CHECK: this.dictCheckCheckBox.attr("checked") ? "1" : "0",
      DICT_VAL_NOTE: this.dictValNoteCheckBox.attr("checked") ? "1" : "0"
    });

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

  executeUpdate: function() {
    var response = parus.database.execute("designer.BalanceTables.Indexes.Update", {
      RN: this.rn,
      BALANCEINDEX: this.indexEdit.attr("value"),
      DICTIONARY: this.dictionaryEdit.attr("value"),
      PRIORITY: this.priorityEdit.attr("value"),
      AGR_FUNC: this.agrFuncSelect.attr("value"),
      NULLABLE: this.nullableCheckBox.attr("checked") ? "1" : "0",
      DICT_CHECK: this.dictCheckCheckBox.attr("checked") ? "1" : "0",
      DICT_VAL_NOTE: this.dictValNoteCheckBox.attr("checked") ? "1" : "0"
    });

    return !!response;
  },

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

    return !!response;
  },

  //static
  executeInsertList: function(prn, selectedList) {
    var response = parus.database.execute("designer.BalanceTables.Indexes.InsertList", {
      PRN: prn,
      RN: selectedList
    });

    return response;
  },

  //static
  executeChangePriority: function(prn, priority) {
    var response = parus.database.execute("designer.BalanceTables.Indexes.ChangePriority", {
      PRN: prn,
      PRIORITY: priority
    });

    return !!response;
  }

});