dojo.provide("parus.designerTemplatesCheckDialog");

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

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

dojo.declare("parus.designerTemplatesCheckDialog", [parus.Dialog], {

  rn: null,

  _lastValues: null,

  onShow: function() {
    this._lastValues = parus.userdata.get(this.declaredClass) || {};
    this.autoInsertCheckBox.attr("checked", this._lastValues["autoInsert"]);
    this.autoDeleteCheckBox.attr("checked", this._lastValues["autoDelete"]);
    this.userSize = this._lastValues["userSize"] || null;
  },

  onClose: function() {
    if (this.applied) {
      this._lastValues["autoInsert"] = this.autoInsertCheckBox.attr("checked");
      this._lastValues["autoDelete"] = this.autoDeleteCheckBox.attr("checked");
      this._lastValues["userSize"] = this.userSize;
      parus.userdata.set(this.declaredClass, this._lastValues);
    }
  },

  clear: function() {
    this.autoInsertCheckBox.attr("checked", false);
    this.autoDeleteCheckBox.attr("checked", false);
  },

  onApply: function() {
    var response = parus.database.execute("designer.BalanceReportFormEdition.Check", {
      RN: this.rn,
      AUTO_INS: this.autoInsertCheckBox.attr("checked") ? 1 : 0,
      AUTO_DEL: this.autoDeleteCheckBox.attr("checked") ? 1 : 0
    });

    if (response) {
      var log = parus.parus8.nodeField(parus.parus8.rowNodes(response)[0], "clobWARNINGS");
      parus.parus8.notificationMessage(log);
    }

    return !!response;
  }

});