Ext.ns('ES');

ES.SiteCharacteristicNumberGrid = Ext.extend(Ext.grid.GridPanel, {
  autoload:true,
  frame:true,
  enableHdMenu:false,
  store: new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
      url:'/process/extjs/site/profil/sitecharacteristic/sitecharacteristicnumber.php',
      method: 'POST'
    }),
    baseParams:{cmd: "list"},
    reader: new Ext.data.JsonReader({
      root: 'results',
      totalProperty: 'totalCount',
      id: 'id'
    },[
      {name: 'entry_id', type: 'int', mapping: 'uid'},
      {name: 'date', type: 'int', mapping: 'date'},
      {name: 'value', type: 'int', mapping: 'value'}
    ])
  }),
  initComponent:function() {
    this.rowModify = new Ext.ux.grid.RowActions({
      header:'Modifier'
      ,width: 50
      ,scope:this
      ,autoWidth:false
//      ,hideMode:'display'
      ,keepSelection:true
      ,actions:[{
        iconCls:'icon-edit'
        ,tooltip:'Modifier'
      }]
      ,callbacks:{
        'icon-edit':function(grid, record, action, row, col) {
          this.initEditFormWindow2(grid, record, action, row, col);
        }.createDelegate(this)
      }
    });
    var CheckColumn = new Ext.grid.CheckColumn({
      header: " ",
      dataIndex: 'checkbox',
      hideable:false,
      width: 35
    });
    var config = {
      plugins:[CheckColumn,this.rowModify],
      tbar: new Ext.Toolbar({
        items:[new Ext.Toolbar.Button({
          text: 'Ajout d\'entrée'
          ,iconCls:'add'
      }),
      new Ext.Toolbar.Button({
        text: 'Suppression',
        iconCls:'remove'
      })]}),
      bbar: new Ext.PagingToolbar({
        pageSize: 10,
        store: this.store,
        displayInfo: true,
        items:['->']
      }),
      cm: new Ext.grid.ColumnModel([
        {
          header: 'entry_id',
          dataIndex:'entry_id'
          ,hidden:true
          ,hideable:false
        },
        CheckColumn,
        {
          header: 'Valeur',
          dataIndex: 'value',
          width: 75
        },{
          header: 'Depuis',
          dataIndex: 'date',
          width: 75
        },this.rowModify
        ])
    };
     // apply config
    Ext.apply(this, Ext.apply(this.initialConfig, config));
    // call parent initComponent
    ES.SiteCharacteristicNumberGrid.superclass.initComponent.call(this);
  } // end of function initComponent
  ,onRender:function() {
    ES.SiteCharacteristicNumberGrid.superclass.onRender.apply(this, arguments);
  } // eo function onRender
  ,init:function(type,tabletypeid,tabletypeinfo) {
    this.type = type;
    this.tabletypeinfo = tabletypeinfo;
    this.tabletypeid = tabletypeid;
    this.refresh();
  }
  ,refresh:function() {
    this.store.load({
       url:this.url
      ,waitMsg:'Loading...'
      ,params:{cmd:'list',tabletypeinfo:this.tabletypeinfo,start:0,limit:10}
    });
  }

  ,getCheckBoxValues:function() {
    var entries = [];
    for(i = 0; i< this.getStore().getCount(); i++){
      if(this.getStore().getAt(i).get('checkbox')){
        entries.push(this.getStore().getAt(i).get('entry_id'));
      }
    }
    return entries;
  }
  ,countCheck:function() {
    var check = 0;
    for(i = 0; i< this.getStore().getCount(); i++){
      if(this.getStore().getAt(i).get('checkbox')){
        check++;
      }
    }
    return check;
  }
  ,demoModality: function() {
    var cm= this.colModel;
    cm.setHidden(1, true);
    cm.setHidden(4, true);
    this.topToolbar.items.itemAt(0).disable();
    this.topToolbar.items.itemAt(1).disable();
  }
});

Ext.reg('ESsitecharacteristicnumbergrid', ES.SiteCharacteristicNumberGrid);

