Ext.ns('parambool0');

parambool0.entriesForm = Ext.extend(Ext.FormPanel,{
  frame:true,
  border:true,
  labelWidth:150
  ,title:"Saisie"
  ,headerCfg:{cls:'x-panel-header-em2'}
  ,height:190
  ,bodyStyle: 'padding:7px'
  ,collapsible:true
  ,buttons: [{text: 'Annuler',cmd:"reset"},{text: 'Ajout',cmd:"add"}]
  ,initComponent:function() {
     var config = {
       layout:'form'
      ,buttonAlign:'right'
      ,frame:false
      ,border:true
      ,items:[{
        xtype:'EMNumber'
        ,name:'value'
        ,fieldLabel:'Valeur'
        ,allowBlank:false
      },{
        xtype:'EMBrowserdatefield'
        ,name:'startdate'
        ,fieldLabel:'Date de début'
      },{
        xtype:'EMNumber'
        ,name:'entry_id'
        ,fieldLabel:'&nbsp;'
        ,hidden: true
        ,hideLabel: true
      }]
    };
     // apply config
    Ext.apply(this, Ext.apply(this.initialConfig, config));
    // call parent initComponent
    parambool0.entriesForm.superclass.initComponent.call(this);
    this.buttons[0].on('click',this._initFields,this);
  } // end of function initComponent
  ,onRender:function() {
    // call parent
    parambool0.entriesForm.superclass.onRender.apply(this, arguments);
    //this.on("afterlayout",this.initDatesId,this,{single: true});
  } // eo function onRender
  ,init:function(counter_id){
    this.counter_id = counter_id;
   
  }
  ,_initFields:function(){
    this.getField('value').reset();
    this.initDates(this.counter_id);
    this.getField('entry_id').reset();
    this.entry_id = 0;
    this.buttons[1].setText("Ajout");
    this.buttons[1].cmd="add";
  }
  ,initDates:function (parameter_type, counter_id) {
    Ext.Ajax.request({
      ownerCt: this,
      waitMsg: 'Please wait...',
      url: '/process/EMBrowser/site/counter/entries/process.parambool0entries.php',
      params: {
        counter_id:counter_id
        ,cmd:'initdates'
      },
      success: function(response,scope){
        var result = Ext.util.JSON.decode(response.responseText);
        scope.ownerCt.setField('startdate',result.startdate);
      },
      failure: function() {
      }
    });
  }
  ,isValid:function (){
    return(this.getField('value').isValid() && this.getField('price').isValid() && this.getField('startdate').isValid() && this.getField('enddate').isValid());
  }
  ,getField:function(fieldName){
    switch(fieldName) {
      case 'value':
        return this.items.itemAt(0);
        break;
      case 'startdate':
        return this.items.itemAt(1);
        break;
      case 'entry_id':
        return this.items.itemAt(2);
        break;
      default:
        return this.getForm().findField(fieldName);
        break;
    }
  }
  ,setField:function(fieldName,value){
    this.getField(fieldName).setValue(value);
  }
});

Ext.reg('parambool0entriesform', parambool0.entriesForm);

