dojo.provide("parus.designerReportTableTotalDialog");

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

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

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

dojo.require("parus.designerReportTableIndexDialog");
dojo.require("parus.designerReportTableIndexesDictionaryDialog");

dojo.declare("parus.designerReportTableTotalDialog", [parus.designerTableModelTotalDialog], {

  postMixInProperties: function() {
    this.templateString = dojo.cache(dojo.moduleUrl("parus", "designerTableModelTotalDialog.html"));
    this.inherited(arguments);
  },

  postCreate: function() {
    this.inherited(arguments);

    dojo.mixin(this.indexEdit, {
      dictionary: "DesignerBalanceTableIndexesWithUnits",
      dialogClass: parus.designerReportTableIndexesDictionaryDialog,
      editDialogClass: parus.designerReportTableIndexDialog
      //editDetailDialogClass: parus.designerReportTableIndexDialog //qqq
    });
  },

  executeInsert: function(duplicate) {
    var response = parus.database.execute("designer.BalanceTables.Totals.Insert", dojo.mixin(this.getExecParams(), {
      PRN: this.prn
    }));

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

  executeUpdate: function() {
    var response = parus.database.execute("designer.BalanceTables.Totals.Update", dojo.mixin(this.getExecParams(), {
      RN: this.rn
    }));

    return !!response;
  },

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

    return !!response;
  },

  //static
  executeChangePriority: function(store, item, directUp) {
    var response = parus.database.execute("designer.BalanceTables.Totals.ChangePriority", {
      RN: store.getValue(item, "RN"),
      DIRECT: directUp ? "-1" : "1"
    });

    return !!response;
  },

  executeGetNextPriority: function() {
    var response = parus.database.execute("designer.BalanceTables.Totals.GetNextPriority", {
      PRN: this.prn
    });

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

});