Ext.ns('parameter1');

parameter1.entriesGrid = Ext.extend(Ext.grid.GridPanel, {
  height:350,
  autoload:false,
  enableHdMenu:false,
  store: new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
      url:'/process/EMBrowser/site/counter/entries/process.parameterentries.php',
      method: 'POST'
    }),
    baseParams:{cmd: "list"},
    reader: new Ext.data.JsonReader({
      root: 'results',
      totalProperty: 'totalCount'
    },[
      {name: 'entry_id', type: 'int', mapping: 'entry_id'},
      {name: 'value', type: 'string', mapping: 'value'},
      {name: 'data', type: 'int', mapping: 'data'},
      {name: 'start_date', type: 'string', mapping: 'start_date'},
      {name: 'end_date', type: 'string', mapping: 'end_date'}
    ])
  }),
  initComponent:function() {
    this.actionEdit = new Ext.ux.grid.RowActions({
      header:'&nbsp;'
      ,width: 50
      ,scope:this
      ,autoWidth:false
      ,hideMode:'display'
      ,keepSelection:true
      ,actions:[{
        iconCls:'icon-edit'
        ,tooltip:'Modifier'
      }]
    });
    var CheckColumn = new Ext.grid.CheckColumn({
      header: " ",
      dataIndex: 'checkbox',
      hideable:false,
      width: 35
    });
    var config = {
      plugins:[CheckColumn,this.actionEdit],
      tbar: new Ext.Toolbar({
        items:[new Ext.Toolbar.Button({
          text: 'Suppression',
          iconCls:'remove'
      })]}),
      bbar: new Ext.PagingToolbar({
        pageSize: 10,
        ownerCt: this,
        store: this.store,
        displayInfo: true,
        items:['->']
      }),
      cm: new Ext.grid.ColumnModel([
        {
          header: 'entry_id',
          dataIndex:'entry_id'
          ,hidden:true
          ,hideable:false
        },
        CheckColumn,
        {
          header: 'data',
          dataIndex:'data'
          ,hidden:true
          ,hideable:false
        },{
          header: 'Valeur',
          dataIndex: 'value',
          width: 150
        },{
          header: 'Début',
          dataIndex: 'start_date',
          width: 90
        },{
          header: 'Fin',
          dataIndex: 'end_date',
          width: 90
        }
        ,this.actionEdit
        ])
    };
     // apply config
    Ext.apply(this, Ext.apply(this.initialConfig, config));
    // call parent initComponent
    parameter1.entriesGrid.superclass.initComponent.call(this);
  } // end of function initComponent
  ,onRender:function() {
    parameter1.entriesGrid.superclass.onRender.apply(this, arguments);
  } // eo function onRender
  ,refresh:function(parameter_id, parameter_type) {
    this.parameter_id = parameter_id;
    this.parameter_type= parameter_type;
    this.store.load({
       url:this.url
      ,waitMsg:'Loading...'
      ,params:{cmd:'list',parameter_id:this.parameter_id,parameter_type:this.parameter_type,start:0,limit:10}
    });
  }
  ,getCheckBoxValues:function() {
    var wentries = [];
    for(i = 0; i< this.getStore().getCount(); i++){
      if(this.getStore().getAt(i).get('checkbox')){
        wentries.push(this.getStore().getAt(i).get('entry_id'));
      }
    }
    return wentries;
  }
  ,countCheck:function() {
    var check = 0;
    for(i = 0; i< this.getStore().getCount(); i++){
      if(this.getStore().getAt(i).get('checkbox')){
        check++;
      }
    }
    return check;
  }
});

Ext.reg('parameter1entriesgrid', parameter1.entriesGrid);

