dojo.provide("parus.balanceReportsExchangeExportDialog");

dojo.require("dojo.io.iframe");

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

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

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

  kind: null,

  _lastValues: null,

  applyProgressLabel: "Обмен отчетностью. Выгрузка.",

  onShow: function() {
    this.restoreFormLastValues();
  },

  onClose: function() {
    this.saveFormLastValues();
  },

  useJournalChanged: function() {
    if (this.useJournal.attr("checked")) {
      this.journalCatalog.attr("disabled", false);
      this.reportTypeEdit.attr("disabled", true);
      this.reportTypeEdit.attr("value", "0");

    }
    else {
      this.journalCatalog.attr("disabled", true);
      this.journalCatalog.attr("value", null);
      this.reportTypeEdit.attr("disabled", false);

    }
  },

  exchangeKindChanged: function() {

    var response = parus.database.execute("BalanceReportExchangeKindInfo", {
      CODE: this.exchangeKind.value
    });

    if (!response) return;

    var node = parus.parus8.rowNodes(response)[0];

    if (parus.parus8.nodeField(node, "NWEB_SIGN") == "1") {
      this.journalCatalog.attr("disabled", false);
      this.useJournal.attr("disabled", true);
      this.useJournal.attr("checked", true);
      this.useJournalLabel.style.color = "#808080";

      this.reportTypeEdit.attr("disabled", true);
      this.reportTypeEdit.attr("value", "0");

    }
    else {
      this.journalCatalog.attr("disabled", true);
      this.journalCatalog.attr("value", null);
      this.useJournal.attr("disabled", false);
      this.useJournal.attr("checked", false);
      this.useJournalLabel.style.color = "";

      this.reportTypeEdit.attr("disabled", false);

    }
  },

  saveFormLastValues: function() {

    this._lastValues["useJournal"] = this.useJournal.checked;
    this._lastValues["exchangeKind"] = this.exchangeKind.value;
    this._lastValues["versionNumber"] = this.versionNumber.value;
    this._lastValues["periodEdit"] = this.periodEdit.value;
    this._lastValues["reportEdit"] = this.reportEdit.value;
    this._lastValues["reportTypeEdit"] = this.reportTypeEdit.value;
    this._lastValues["archiveEdit"] = this.archiveEdit.value;
    this._lastValues["archiveNameEdit"] = this.archiveNameEdit.value;
    this._lastValues["journalCatalog"] = this.journalCatalog.value;

    this._lastValues["userSize"] = this.userSize;

    parus.userdata.set(this.declaredClass, this._lastValues)
  },

  restoreFormLastValues: function() {

    this._lastValues = parus.userdata.get(this.declaredClass) || {};
    this.exchangeKind.attr("value", this._lastValues["exchangeKind"]);
    setTimeout(dojo.hitch(this, function() {

      this.useJournal.attr("checked", this._lastValues["useJournal"]);
      setTimeout(dojo.hitch(this, function() {

        this.versionNumber.attr("value", this._lastValues["versionNumber"]);
        this.periodEdit.attr("value", this._lastValues["periodEdit"]);
        this.reportEdit.attr("value", this._lastValues["reportEdit"]);
        this.reportTypeEdit.attr("value", this._lastValues["reportTypeEdit"]);
        this.archiveEdit.attr("value", this._lastValues["archiveEdit"]);
        this.archiveNameEdit.attr("value", this._lastValues["archiveNameEdit"]);
        this.journalCatalog.attr("value", this._lastValues["journalCatalog"]);
      }), 100);

    }), 100);
    this.userSize = this._lastValues["userSize"] || null;

  }

});