dojo.provide("parus.balancePreparedConsolidationDialog");

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

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

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

  data: null,

  _attrDescriptors: null,

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

    this._attrDescriptors = parus.parus8._attrDescriptors ? parus.parus8.rowNodes(parus.database.execute("attrDescriptors", {
      "UNITCODE": "BalanceReportsConstition"
    }).documentElement.childNodes[0].childNodes[0].childNodes[0]) || [] : [];

    var structure = dojo.clone(this.grid.structure);

    dojo.forEach(this._attrDescriptors, dojo.hitch(this, function(descriptor) {

      structure[0].cells[0].push({
        colSpan: 1,
        attrRN: parus.parus8.nodeField(descriptor, "RN"),
        dataType: parus.parus8.nodeField(descriptor, "DATATYPE"),
        dataSubType: 0,
        field: "attr" + parus.parus8.nodeField(descriptor, "RN"),
        name: parus.parus8.nodeField(descriptor, "NAME"),
        formatter: parus.balance.formatAttrValue,
        width: (parus.parus8.nodeField(descriptor, "ACTIVE") == "1") ? "121px" : "0px",
        hidden: (parus.parus8.nodeField(descriptor, "ACTIVE") != "1"),
        styles: "text-align:" + ((parus.parus8.nodeField(descriptor, "DATATYPE") == 0) ? "left" : "right") + ";",
        sortField: (parus.parus8.nodeField(descriptor, "PARAMCOUNT") == "2") ? (parus.parus8.nodeField(descriptor, "STOREDPROC") + "(T.COMPANY, T.RN)") : (parus.parus8.nodeField(descriptor, "STOREDPROC") + "(T.RN)")
      })

    }));

    this.grid.attr("structure", structure);



    this.grid.rowsPerPage = this.data.length + 25;
    this.grid.attr("store", new parus.gridData({
      persistent: true,
      _data: this.data,
      onComplete: dojo.hitch(this, function() {
        this.grid.selection.selectRange(0, this.data.length - 1);
      })
    }));
    this.grid.setQuery({});



    this.popupMenu.bindDomNode(this.grid.viewsNode);
    parus.balance._createActionsButton(this.popupMenu, this.headerPane);

    var settings = parus.userdata.get(this.declaredClass);
    if (settings) {
      parus.gridSettingsDialog.mergeGridSettings(this.grid, settings.gridSettings);
      parus.gridSettingsDialog.mergeColorConditions(this.grid, settings.colorConditions);
      parus.gridSettingsDialog.mergeMenuSettings(this.popupMenu, settings.actionSettings, settings.userProcsActions, settings.userReportsActions, settings.userAppsActions);
      parus.gridSettingsDialog.mergeFilterBar(this.grid, settings.showFilterBar, settings.filterValues, settings.sortInfo);
    };


  }

});