dojo.provide("parus.abonentReportDialog");

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

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

dojo.require("parus.customEdit");

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

  _docprops: null,

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

    this.noteEdit.attr("value", null);
    this._docprops = {};

    if (parus.balance._docprops.length) {

      this.requsitesPane.domNode.style.margin = "0";
      var tabs = new dijit.layout.TabContainer({
        region: "center",
        "class": "balanceInternalPages"
      });
      tabs.addChild(this.requsitesPane);

      var propsPane = new dijit.layout.ContentPane({
        title: "Свойства",
        "class": "dialogContentPane",
        style: "overflow-y:scroll"
      });
      var propsTable = document.createElement("table");
      propsTable.cellSpacing = "5";
      propsTable.width = "100%";

      dojo.forEach(parus.balance._docprops, dojo.hitch(this, function(docprop) {
        var row = propsTable.insertRow(-1);
        var titleCell = row.insertCell(-1);
        titleCell.appendChild(document.createElement("b")).
        appendChild(document.createTextNode(parus.parus8.nodeField(docprop, "PROMPT") + ":"));

        var editCell = row.insertCell(-1);
        editCell.align = "right";

        var params = parus.customEditProperties(
        parus.parus8.nodeField(docprop, "DICTIONARY"), parus.parus8.nodeField(docprop, "DATATYPE") == "3" ? "4" : parus.parus8.nodeField(docprop, "DATATYPE"), parus.parus8.nodeField(docprop, "SUBTYPE"), parus.parus8.nodeField(docprop, "REQUIRE") == "1", parus.parus8.nodeField(docprop, "STRLEN"), parus.parus8.nodeField(docprop, "INTPART"), parus.parus8.nodeField(docprop, "FRACPART"));

        dojo.mixin(params.params, {
          disabled: parus.parus8.nodeField(docprop, "READONLY") == "1"
        });

        var editWidget = new(params.constructor())(params.params, editCell.appendChild(document.createElement("div")));

        this._docprops[parus.parus8.nodeField(docprop, "RN")] = editWidget;
      }));

      propsPane.containerNode.appendChild(propsTable);
      tabs.addChild(propsPane);


      this.mainContainer.addChild(tabs);

      dojo.style(this.mainContainer.domNode, {
        height: (parus.parus8.styleSize(this.mainContainer.domNode.style.height) + 30) + "px"
      });

    };

  },


  propValues: function() {
    var result = {};

    for (var key in this._docprops)
    result["P" + key] = parus._docPropsValueValueFromWidget(this._docprops[key]);

    return {
      DOCPROPS: result
    };
  }


});