dojo.provide("parus.designerReportCheckListDialog");

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

dojo.require("parus.designerCheckListDialog");
dojo.require("parus.designerCheckDialog");

dojo.require("parus.designerReportPeriodDialog");
dojo.require("parus.designerReportPeriodDateDialog");

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

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

    if (!this.prn) this.prn = this.getParentDialogCondition("PRN"); //editionRN
    if (store && item) {
      this.checkListEdit.attr("value", store.getValue(item, "CODE"));
      this.periodEdit.attr("value", store.getValue(item, "PERIOD"));
      this.mainCheckBox.attr("checked", store.getValue(item, "MAIN") == "1");
    }
  },

  executeInsert: function(duplicate) {
    var response = parus.database.execute("designer.BalanceReportForm.CheckList.Insert", {
      PRN: this.prn,
      CHECKLIST: this.checkListEdit.attr("value"),
      PERIOD: this.periodEdit.attr("value"),
      MAIN: this.mainCheckBox.attr("checked") ? "1" : "0"
    });

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

  executeUpdate: function() {
    var response = parus.database.execute("designer.BalanceReportForm.CheckList.Update", {
      RN: this.rn,
      CHECKLIST: this.checkListEdit.attr("value"),
      PERIOD: this.periodEdit.attr("value"),
      MAIN: this.mainCheckBox.attr("checked") ? "1" : "0"
    });

    return !!response;
  },

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

    return !!response;
  }

});