dojo.provide("parus.templateDesignColumns");

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

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

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

  postCreate: function() {

    this.inherited(arguments);

    this.grid.setStore(this._getStore());

    this.grid.setQuery({});
    this.grid.selection.select(0);
    this.gridPopupMenu.bindDomNode(this.grid.viewsNode);

    parus.balance._createActionsButton(this.gridPopupMenu, this.headerPane);

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

    setTimeout(dojo.hitch(this, function() {
      this._selected();
    }), 100);
  },

  _getStore: function() {
    return new parus.gridData({
      persistent: true,
      _data: [{num:1,width:50},{num:2,width:60}]
    })
  },

  _selected: function() {
    var item = this.grid.getItem(this.grid.selection.getSelectedIndex());

    dojo.forEach(this.gridPopupMenu.getChildren(), dojo.hitch(this, function(menuItem) {
      var disabled = item ? false : true;
      if (!menuItem.itemAction) disabled = false;

      if (menuItem.declaredClass != "dijit.MenuSeparator") menuItem.attr("disabled", disabled);
    }));
    parus.parus8.checkMenuSeparators(this.gridPopupMenu);

  },

  delete: function() {

    (new parus.confirmationDialog({

      message: "Удалить запись (записи)?",

      onApply: dojo.hitch(this, function() {

        var store = this.grid.store;
        var item = this.grid.selection.getFirstSelected();
        for (var i = 0; i < this.grid.selection.getSelectedCount(); i++) {
   
          ///

          item = this.grid.selection.getNextSelected(item);
        };

        this.grid.attr("store", this._getStore());
        this.grid.setQuery({});
        this.grid.selection.select(0);
        return true;
      })
    })).show();


  },

  settings: function() {
    parus.balance.executeSettings(this.grid, this.gridPopupMenu, this.declaredClass);
  },

  destroy: function() {
    this.store = null;
    this.inherited(arguments);
  },

  gridFilterChanged: function(values, sortInfo) {
    parus.balance.gridFilterChanged(this.declaredClass, values, sortInfo);
  }

});