Ext.ns('water');

water.counterInfos = Ext.extend(Ext.Panel,{
  title:"&nbsp;",
  url:'/process/EMBrowser/site/counter/process.water_counter.php'
  ,tpl:new Ext.XTemplate('')
  ,frame:false
  ,bodyStyle: 'padding:2px'
  ,collapsible:true
  ,buttons:[{text:"Modifier",cmd:"update"}]
  ,initComponent:function() {
    var config = {}; // eo config object
    // apply config
    Ext.apply(this, Ext.apply(this.initialConfig, config));
    // call parent initComponent
    water.counterInfos.superclass.initComponent.apply(this, arguments);

  } // end of function initComponent
  ,onRender:function() {
    water.counterInfos.superclass.onRender.apply(this, arguments);
  } // eo function onRender
  ,init_tpl:function(with_division_name) {
    var tplcontent = '<div class="type-1">'
    +'<fieldset class="type-2">'
    +'<legend class="type-2">Compteur eau</legend>'
    +'<table cellspacing="0" cellpadding="0" class="type-1"><tr class="row-c10">'
    +'<td class="label">Nom ou numéro du compteur : </td>'
    +'<td class="data" width="257px">{name}</td>'
    +'</tr><tr class="row-c11">'
    +'<td class="label">Utilisation : </td>'
    +'<td class="data" width="257px">{water_usage_type_name}</td>';
    if(with_division_name) {
      tplcontent = tplcontent+'</tr><tr class="row-c11">'
      +'<td class="label">Division : </td>'
      +'<td class="data" width="257px">{division_name}</td>'
    }
    tplcontent = tplcontent+'</tr></table>'
    +'</fieldset>'
    +'</div>';
    this.tpl=new Ext.XTemplate(tplcontent);
  }
  ,initModifyAction:function() {
    this.height = 252;
  }
  ,init:function(counter_id) {
    this.counter_id = counter_id;
    this.load({
         url:this.url
        ,waitMsg:'Loading...'
        ,scope:this
        ,method:'GET'
        ,params:{cmd:'read',counter_id:counter_id}
        ,callback:function(var1,var2,response,var3) {
          var result = Ext.util.JSON.decode(response.responseText);
          switch(result.success){
            case 1:
              this.tpl.overwrite(this.body, result.data);
              this.setTitle(result.title.countertitle);
              break;
            default:
              Ext.MessageBox.alert('Attention',result.error);
              break;
          }
        }
    });
  }
});

Ext.reg('watercounterinfos', water.counterInfos);

