Ext.ns('ES');

ES.SiteCharacteristicMainPanel = Ext.extend(Ext.Panel,{
  width: 700,
  layout:'table',
  layoutConfig:{columns:2},
  frame:false,
  height:810,
  initComponent:function() {
// hard coded config - cannot be changed from outside
    var config = {
      items:[{
        xtype:'ESsitecharacteristicgrid',
        height:798,
        width:400
      },{
        xtype:'ESsitecharacteristicrightpanel',
        height:792,
        width:298
      }]
    };
    // apply config
    Ext.apply(this, Ext.apply(this.initialConfig, config));
    ES.SiteCharacteristicMainPanel.superclass.initComponent.apply(this, arguments);
    this.siteCharacteristicGrid = this.items.itemAt(0);
    this.siteCharacteristicRightPanel = this.items.itemAt(1);
    this.siteCharacteristicYearGrid = this.siteCharacteristicRightPanel.items.itemAt(0);
    this.siteCharacteristicBoolGrid = this.siteCharacteristicRightPanel.items.itemAt(1);
    this.siteCharacteristicNumberGrid = this.siteCharacteristicRightPanel.items.itemAt(2);
    this.siteCharacteristicSolarHeatingGrid = this.siteCharacteristicRightPanel.items.itemAt(3);
    this.isSiteCharacteristicsDemo();
    this.siteCharacteristicYearGrid.topToolbar.items.itemAt(0).on('click',this.initAddYearFormWindow,this);
    this.siteCharacteristicYearGrid.topToolbar.items.itemAt(1).on('click',this.deleteYearEntries,this);
    this.siteCharacteristicBoolGrid.topToolbar.items.itemAt(0).on('click',this.initAddBoolFormWindow,this);
    this.siteCharacteristicBoolGrid.topToolbar.items.itemAt(1).on('click',this.deleteBoolEntries,this);
    this.siteCharacteristicNumberGrid.topToolbar.items.itemAt(0).on('click',this.initAddNumberFormWindow,this);
    this.siteCharacteristicNumberGrid.topToolbar.items.itemAt(1).on('click',this.deleteNumberEntries,this);
    this.siteCharacteristicSolarHeatingGrid.topToolbar.items.itemAt(0).on('click',this.initAddSolarHeatingFormWindow,this);
    this.siteCharacteristicSolarHeatingGrid.topToolbar.items.itemAt(1).on('click',this.deleteSolarHeatingEntries,this);
    this.siteCharacteristicYearGrid.rowModify.callbacks = {
      'icon-edit':function(grid, record, action, row, col) {
        this.initEditYearFormWindow(grid, row);
      }.createDelegate(this)
    }
    this.siteCharacteristicBoolGrid.rowModify.callbacks = {
      'icon-edit':function(grid, record, action, row, col) {
        this.initEditBoolFormWindow(grid, row);
      }.createDelegate(this)
    }
    this.siteCharacteristicNumberGrid.rowModify.callbacks = {
      'icon-edit':function(grid, record, action, row, col) {
        this.initEditNumberFormWindow(grid, row);
      }.createDelegate(this)
    }
    this.siteCharacteristicSolarHeatingGrid.rowModify.callbacks = {
      'icon-edit':function(grid, record, action, row, col) {
        this.initEditSolarHeatingFormWindow(grid, row);
      }.createDelegate(this)
    }
    this.siteCharacteristicGrid.on('rowclick', this.showBuildingInfos, this);
// replaced by row click //
//    this.siteCharacteristicGrid.rowActionDetails.callbacks = {
//      'icon-management':function(grid, record, action, row, col) {
//        var record = grid.getStore().getAt(row);
//        var tabletype = record.get('tabletype');
//        var tabletypeid = record.get('tabletypeid');
//        var tabletypeinfo = record.get('tabletypeinfo');
//        var type = record.get('type');
//        var layout = '';
//        switch(row) {
//          case 0:case 1:case 2:case 3:case 4:case 5:
//            layout = 'yeargrid';
//          break;
//          case 6:
//            layout = 'numbergrid';
//          break;
//          case 7:case 8:case 9:
//            layout = 'boolgrid';
//          break;
//          case 10:
//            layout = 'solarheatinggrid';
//          break;
//        }
//        this.siteCharacteristicRightPanel.init(type,tabletype,tabletypeid,tabletypeinfo,layout);
//      }.createDelegate(this)
//    }
    this.doLayout();
  }
  ,onRender:function() {
    ES.SiteCharacteristicMainPanel.superclass.onRender.apply(this, arguments);
  } // eo function onRender
  ,showBuildingInfos:function (grid, row, action){
    var record = grid.getStore().getAt(row);
        var tabletype = record.get('tabletype');
        var tabletypeid = record.get('tabletypeid');
        var tabletypeinfo = record.get('tabletypeinfo');
        var type = record.get('type');
        var layout = '';
        switch(row) {
          case 0:case 1:case 2:case 3:case 4:case 5:
            layout = 'yeargrid';
          break;
          case 6:
            layout = 'numbergrid';
          break;
          case 7:case 8:case 9:
            layout = 'boolgrid';
          break;
          case 10:
            layout = 'solarheatinggrid';
          break;
        }
        this.siteCharacteristicRightPanel.init(type,tabletype,tabletypeid,tabletypeinfo,layout);
      }

  ,initAddYearFormWindow:function () {
    if(this.SiteCharacteristicYearFormWindow == null || !this.SiteCharacteristicYearFormWindow.isVisible()){
      this.siteCharacteristicYearFormWindow = new ES.SiteCharacteristicYearFormWindow();
      this.siteCharacteristicYearForm = this.siteCharacteristicYearFormWindow.items.itemAt(0);
      this.siteCharacteristicYearFormWindow.setTitle(this.siteCharacteristicYearGrid.type);
      this.siteCharacteristicYearFormButton = this.siteCharacteristicYearForm.buttons[0];
      var scope_siteCharacteristicYearForm = this;
      this.siteCharacteristicYearFormButton.on({
         scope:scope_siteCharacteristicYearForm,
         click:function(scope){
           this.addYearEntry();
         }
      });
      this.siteCharacteristicYearFormWindow.show();
    } else {
      this.siteCharacteristicYearFormWindow.toFront();
    }
  }
  ,addYearEntry: function() {
    if(this.siteCharacteristicYearForm.isValid()){
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristicyear.php',
        params: {
          cmd:"add",
          tabletypeid:this.siteCharacteristicYearGrid.tabletypeid,
          year: this.siteCharacteristicYearForm.getField('year').getValue()
        },
        success: function(response,scope){
          var result = Ext.util.JSON.decode(response.responseText);
          switch(result.success){
          case 1:
//            Ext.MessageBox.alert(
//              'Saisie'
//              ,'Donnée insérée.'
//              ,function(){
                scope.ownerCt.siteCharacteristicYearGrid.refresh();
                scope.ownerCt.siteCharacteristicGrid.refresh();
                scope.ownerCt.siteCharacteristicYearFormWindow.close();
//              }
//            ,scope);
            break;
          default:
            Ext.MessageBox.alert('Attention',result.error);
            break;
          }
        },
        failure: function(response) {
          Ext.MessageBox.alert('error','L application n a pas pu se connecter a la base de données. Veuillez réessayer plus tard');
        }
      });
    } else {
      Ext.MessageBox.alert('Attention','Le formulaire n est pas valide');
    }
  }
  ,deleteYearEntries: function() {
    if(this.siteCharacteristicYearGrid.countCheck() > 0) {
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristicyear.php',
        params: {
          entry_ids:Ext.util.JSON.encode(this.siteCharacteristicYearGrid.getCheckBoxValues())
          ,cmd:'delete'
        },
        success: function(response,scope){
          scope.ownerCt.siteCharacteristicYearGrid.refresh();
          scope.ownerCt.siteCharacteristicGrid.refresh();
        },
        failure: function() {
        }
      });
    } else {
      Ext.MessageBox.show({
        title: 'Aucun élément sélectionné',
        msg: 'Pour supprimer, veuillez sélectionner les éléments à supprimer avec les checkbox',
        width: 300
      });
    }
  }
  ,initEditYearFormWindow: function (grid, rowIndex){
    var record = grid.getStore().getAt(rowIndex);

    if(this.SiteCharacteristicYearFormWindow == null || !this.SiteCharacteristicYearFormWindow.isVisible()){
      this.siteCharacteristicYearFormWindow = new ES.SiteCharacteristicYearFormWindow();
      //this.siteCharacteristicYearFormWindow.title = "Modification";
      this.siteCharacteristicYearForm = this.siteCharacteristicYearFormWindow.items.itemAt(0);
      this.siteCharacteristicYearFormWindow.setTitle( "Modification : "+this.siteCharacteristicYearGrid.type);
      this.siteCharacteristicYearFormButton = this.siteCharacteristicYearForm.buttons[0];
      var scope_siteCharacteristicYearForm = this;
      this.siteCharacteristicYearFormButton.on({
        scope:scope_siteCharacteristicYearForm,
        click:function(scope){
          this.editYearEntry();
        }
      });
      this.siteCharacteristicYearFormWindow.show();
    } else {
      this.siteCharacteristicYearFormWindow.toFront();
    }
    this.siteCharacteristicYearForm.setField('year',record.get('value'));
    this.siteCharacteristicYearForm.setField('entry_id',record.get('entry_id'));
  }
  ,editYearEntry: function() {
    if(this.siteCharacteristicYearForm.isValid()){
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristicyear.php',
        params: {
          cmd:"update",
          tabletypeinfo:this.siteCharacteristicYearGrid.tabletypeinfo,
          tabletypeid:this.siteCharacteristicYearGrid.tabletypeid,
          entry_id:this.siteCharacteristicYearForm.getField('entry_id').getValue(),
          year: this.siteCharacteristicYearForm.getField('year').getValue()
        },
        success: function(response,scope){
          var result = Ext.util.JSON.decode(response.responseText);
          switch(result.success){
          case 1:
            Ext.MessageBox.alert(
              'Modification'
              ,'Donnée modifiée.'
              ,function(){
                scope.ownerCt.siteCharacteristicYearGrid.refresh();
                scope.ownerCt.siteCharacteristicGrid.refresh();
                scope.ownerCt.siteCharacteristicYearFormWindow.close();
              }
            ,scope);
            break;
          default:
            Ext.MessageBox.alert('Attention',result.error);
            break;
          }
        },
        failure: function(response) {
          Ext.MessageBox.alert('error','L application n a pas pu se connecter a la base de données. Veuillez réessayer plus tard');
        }
      });
    } else {
      Ext.MessageBox.alert('Attention','Le formulaire n est pas valide');
    }
  }
  ,initAddBoolFormWindow:function (){
    if(this.SiteCharacteristicBoolFormWindow == null || !this.SiteCharacteristicBoolFormWindow.isVisible()){
      this.siteCharacteristicBoolFormWindow = new ES.SiteCharacteristicBoolFormWindow();
      this.siteCharacteristicBoolForm = this.siteCharacteristicBoolFormWindow.items.itemAt(0);
      this.siteCharacteristicBoolFormWindow.setTitle(this.siteCharacteristicBoolGrid.type);
      this.siteCharacteristicBoolFormButton = this.siteCharacteristicBoolForm.buttons[0];
      var scope_siteCharacteristicBoolForm = this;
      this.siteCharacteristicBoolFormButton.on({
         scope:scope_siteCharacteristicBoolForm,
         click:function(scope){
           this.addBoolEntry();
         }
      });
      this.siteCharacteristicBoolFormWindow.show();
    } else {
      this.siteCharacteristicBoolFormWindow.toFront();
    }
  }
  ,addBoolEntry: function() {
    if(this.siteCharacteristicBoolForm.isValid()){
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristicbool.php',
        params: {
          cmd:"add",
          tabletypeid:this.siteCharacteristicBoolGrid.tabletypeid,
          value: this.siteCharacteristicBoolForm.getField('boolvalue').getValue(),
          year: this.siteCharacteristicBoolForm.getField('year').getValue()
        },
        success: function(response,scope){
          var result = Ext.util.JSON.decode(response.responseText);
          switch(result.success){
          case 1:
//            Ext.MessageBox.alert(
//              'Saisie'
//              ,'Donnée insérée.'
//              ,function(){
                scope.ownerCt.siteCharacteristicBoolGrid.refresh();
                scope.ownerCt.siteCharacteristicGrid.refresh();
                scope.ownerCt.siteCharacteristicBoolFormWindow.close();
                
//              }
//            ,scope);
            break;
          default:
            Ext.MessageBox.alert('Attention',result.error);
            break;
          }
        },
        failure: function(response) {
          Ext.MessageBox.alert('error','L application n a pas pu se connecter a la base de données. Veuillez réessayer plus tard');
        }
      });
    } else {
      Ext.MessageBox.alert('Attention','Le formulaire n est pas valide');
    }
  }
  ,deleteBoolEntries: function() {
    if(this.siteCharacteristicBoolGrid.countCheck() > 0) {
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristicbool.php',
        params: {
          entry_ids:Ext.util.JSON.encode(this.siteCharacteristicBoolGrid.getCheckBoxValues())
          ,cmd:'delete'
        },
        success: function(response,scope){
          scope.ownerCt.siteCharacteristicBoolGrid.refresh();
          scope.ownerCt.siteCharacteristicGrid.refresh();
        },
        failure: function() {
        }
      });
    } else {
      Ext.MessageBox.alert('Aucun élément sélectionné','Pour supprimer, veuillez sélectionner les éléments à supprimer avec les checkbox');
    }
  }
  ,initEditBoolFormWindow: function (grid, rowIndex){
    var record = grid.getStore().getAt(rowIndex);

    if(this.SiteCharacteristicBoolFormWindow == null || !this.SiteCharacteristicBoolFormWindow.isVisible()){
      this.siteCharacteristicBoolFormWindow = new ES.SiteCharacteristicBoolFormWindow();
      //this.siteCharacteristicBoolFormWindow.title = "Modification";
      this.siteCharacteristicBoolForm = this.siteCharacteristicBoolFormWindow.items.itemAt(0);
      this.siteCharacteristicBoolFormWindow.setTitle( "Modification : "+this.siteCharacteristicBoolGrid.type);
      this.siteCharacteristicBoolFormButton = this.siteCharacteristicBoolForm.buttons[0];
      var scope_siteCharacteristicBoolForm = this;
      this.siteCharacteristicBoolFormButton.on({
        scope:scope_siteCharacteristicBoolForm,
        click:function(scope){
          this.editBoolEntry();
        }
      });
      this.siteCharacteristicBoolFormWindow.show();
    } else {
      this.siteCharacteristicBoolFormWindow.toFront();
    }
    if(record.get('DBvalue') == 1){
      this.siteCharacteristicBoolForm.setField('boolvaluetrue',true);
    } else {
      this.siteCharacteristicBoolForm.setField('boolvaluefalse', true);
    }
    this.siteCharacteristicBoolForm.setField('year',record.get('date'));
    this.siteCharacteristicBoolForm.setField('entry_id',record.get('entry_id'));
  }
  ,editBoolEntry: function() {
    if(this.siteCharacteristicBoolForm.isValid()){
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristicbool.php',
        params: {
          cmd:"update",
          tabletypeinfo:this.siteCharacteristicBoolGrid.tabletypeinfo,
          tabletypeid:this.siteCharacteristicBoolGrid.tabletypeid,
          entry_id:this.siteCharacteristicBoolForm.getField('entry_id').getValue(),
          value: this.siteCharacteristicBoolForm.getField('boolvalue').getValue(),
          year: this.siteCharacteristicBoolForm.getField('year').getValue()
        },
        success: function(response,scope){
          var result = Ext.util.JSON.decode(response.responseText);
          switch(result.success){
          case 1:
            Ext.MessageBox.alert(
              'Modification'
              ,'Donnée modifiée.'
              ,function(){
                scope.ownerCt.siteCharacteristicBoolGrid.refresh();
                scope.ownerCt.siteCharacteristicGrid.refresh();
                scope.ownerCt.siteCharacteristicBoolFormWindow.close();
              }
            ,scope);
            break;
          default:
            Ext.MessageBox.alert('Attention',result.error);
            break;
          }
        },
        failure: function(response) {
          Ext.MessageBox.alert('error','L application n a pas pu se connecter a la base de données. Veuillez réessayer plus tard');
        }
      });
    } else {
      Ext.MessageBox.alert('Attention','Le formulaire n est pas valide');
    }
  }
  ,initAddNumberFormWindow:function (){
    if(this.SiteCharacteristicNumberFormWindow == null || !this.SiteCharacteristicNumberFormWindow.isVisible()){
      this.siteCharacteristicNumberFormWindow = new ES.SiteCharacteristicNumberFormWindow();
      this.siteCharacteristicNumberForm = this.siteCharacteristicNumberFormWindow.items.itemAt(0);
      this.siteCharacteristicNumberFormWindow.setTitle(this.siteCharacteristicNumberGrid.type);
      this.siteCharacteristicNumberFormButton = this.siteCharacteristicNumberForm.buttons[0];
      var scope_siteCharacteristicNumberForm = this;
      this.siteCharacteristicNumberFormButton.on({
         scope:scope_siteCharacteristicNumberForm,
         click:function(scope){
           this.addNumberEntry();
         }
      });
      this.siteCharacteristicNumberFormWindow.show();
    } else {
      this.siteCharacteristicNumberFormWindow.toFront();
    }
  }
  ,addNumberEntry: function() {
    if(this.siteCharacteristicNumberForm.isValid()){
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristicnumber.php',
        params: {
          cmd:"add",
          tabletypeid:this.siteCharacteristicNumberGrid.tabletypeid,
          value: this.siteCharacteristicNumberForm.getField('value').getValue(),
          year: this.siteCharacteristicNumberForm.getField('year').getValue()
        },
        success: function(response,scope){
          var result = Ext.util.JSON.decode(response.responseText);
          switch(result.success){
          case 1:
//            Ext.MessageBox.alert(
//              'Saisie'
//              ,'Donnée insérée.'
//              ,function(){
                scope.ownerCt.siteCharacteristicNumberGrid.refresh();
                scope.ownerCt.siteCharacteristicGrid.refresh();
                scope.ownerCt.siteCharacteristicNumberFormWindow.close();
                
//              }
//            ,scope);
            break;
          default:
            Ext.MessageBox.alert('Attention',result.error);
            break;
          }
        },
        failure: function(response) {
          Ext.MessageBox.alert('error','L application n a pas pu se connecter a la base de données. Veuillez réessayer plus tard');
        }
      });
    } else {
      Ext.MessageBox.alert('Attention','Le formulaire n est pas valide');
    }
  }
  ,deleteNumberEntries: function() {
    if(this.siteCharacteristicNumberGrid.countCheck() > 0) {
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristicbool.php',
        params: {
          entry_ids:Ext.util.JSON.encode(this.siteCharacteristicNumberGrid.getCheckBoxValues())
          ,cmd:'delete'
        },
        success: function(response,scope){
          scope.ownerCt.siteCharacteristicNumberGrid.refresh();
          scope.ownerCt.siteCharacteristicGrid.refresh();
        },
        failure: function() {
        }
      });
    } else {
      Ext.MessageBox.show({
        title: 'Aucun élément sélectionné',
        msg: 'Pour supprimer, veuillez sélectionner les éléments à supprimer avec les checkbox',
        width: 300
      });
    }
  }
  ,initEditNumberFormWindow: function (grid, rowIndex){
    var record = grid.getStore().getAt(rowIndex);

    if(this.SiteCharacteristicNumberFormWindow == null || !this.SiteCharacteristicNumberFormWindow.isVisible()){
      this.siteCharacteristicNumberFormWindow = new ES.SiteCharacteristicNumberFormWindow();
      //this.siteCharacteristicNumberFormWindow.title = "Modification";
      this.siteCharacteristicNumberForm = this.siteCharacteristicNumberFormWindow.items.itemAt(0);
      this.siteCharacteristicNumberFormWindow.setTitle( "Modification : "+this.siteCharacteristicNumberGrid.type);
      this.siteCharacteristicNumberFormButton = this.siteCharacteristicNumberForm.buttons[0];
      var scope_siteCharacteristicNumberForm = this;
      this.siteCharacteristicNumberFormButton.on({
        scope:scope_siteCharacteristicNumberForm,
        click:function(scope){
          this.editNumberEntry();
        }
      });
      this.siteCharacteristicNumberFormWindow.show();
    } else {
      this.siteCharacteristicNumberFormWindow.toFront();
    }
    this.siteCharacteristicNumberForm.setField('value',record.get('value'));
    this.siteCharacteristicNumberForm.setField('year',record.get('date'));
    this.siteCharacteristicNumberForm.setField('entry_id',record.get('entry_id'));
  }
  ,editNumberEntry: function() {
    if(this.siteCharacteristicNumberForm.isValid()){
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristicnumber.php',
        params: {
          cmd:"update",
          tabletypeinfo:this.siteCharacteristicNumberGrid.tabletypeinfo,
          tabletypeid:this.siteCharacteristicNumberGrid.tabletypeid,
          entry_id:this.siteCharacteristicNumberForm.getField('entry_id').getValue(),
          value: this.siteCharacteristicNumberForm.getField('value').getValue(),
          year: this.siteCharacteristicNumberForm.getField('year').getValue()
        },
        success: function(response,scope){
          var result = Ext.util.JSON.decode(response.responseText);
          switch(result.success){
          case 1:
            Ext.MessageBox.alert(
              'Modification'
              ,'Donnée modifiée.'
              ,function(){
                scope.ownerCt.siteCharacteristicNumberGrid.refresh();
                scope.ownerCt.siteCharacteristicGrid.refresh();
                scope.ownerCt.siteCharacteristicNumberFormWindow.close();
              }
            ,scope);
            break;
          default:
            Ext.MessageBox.alert('Attention',result.error);
            break;
          }
        },
        failure: function(response) {
          Ext.MessageBox.alert('error','L application n a pas pu se connecter a la base de données. Veuillez réessayer plus tard');
        }
      });
    } else {
      Ext.MessageBox.alert('Attention','Le formulaire n est pas valide');
    }
  }
  ,initAddSolarHeatingFormWindow:function (){
    if(this.SiteCharacteristicSolarHeatingFormWindow == null || !this.SiteCharacteristicSolarHeatingFormWindow.isVisible()){
      this.siteCharacteristicSolarHeatingFormWindow = new ES.SiteCharacteristicSolarHeatingFormWindow();
      this.siteCharacteristicSolarHeatingForm = this.siteCharacteristicSolarHeatingFormWindow.items.itemAt(0);
      this.siteCharacteristicSolarHeatingFormWindow.setTitle(this.siteCharacteristicSolarHeatingGrid.type);
      this.siteCharacteristicSolarHeatingFormButton = this.siteCharacteristicSolarHeatingForm.buttons[0];
      var scope_siteCharacteristicSolarHeatingForm = this;
      this.siteCharacteristicSolarHeatingFormButton.on({
         scope:scope_siteCharacteristicSolarHeatingForm,
         click:function(scope){
           this.addSolarHeatingEntry();
         }
      });
      this.siteCharacteristicSolarHeatingFormWindow.show();
    } else {
      this.siteCharacteristicSolarHeatingFormWindow.toFront();
    }
  }
  ,addSolarHeatingEntry: function() {
    if(this.siteCharacteristicSolarHeatingForm.isValid()){
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristicsolarheating.php',
        params: {
          cmd:"add",
          tabletypeid:this.siteCharacteristicSolarHeatingGrid.tabletypeid,
          boolvalue: this.siteCharacteristicSolarHeatingForm.getField('boolvalue').getValue(),
          solararea: this.siteCharacteristicSolarHeatingForm.getField('solararea').getValue(),
          year: this.siteCharacteristicSolarHeatingForm.getField('year').getValue()
        },
        success: function(response,scope){
          var result = Ext.util.JSON.decode(response.responseText);
          switch(result.success){
          case 1:
//            Ext.MessageBox.alert(
//              'Saisie'
//              ,'Donnée insérée.'
//              ,function(){
                scope.ownerCt.siteCharacteristicSolarHeatingGrid.refresh();
                scope.ownerCt.siteCharacteristicGrid.refresh();
                scope.ownerCt.siteCharacteristicSolarHeatingFormWindow.close();
                
//              }
//            ,scope);
            break;
          default:
            Ext.MessageBox.alert('Attention',result.error);
            break;
          }
        },
        failure: function(response) {
          Ext.MessageBox.alert('error','L application n a pas pu se connecter a la base de données. Veuillez réessayer plus tard');
        }
      });
    } else {
      Ext.MessageBox.alert('Attention','Le formulaire n est pas valide');
    }
  }
  ,deleteSolarHeatingEntries: function() {
    if(this.siteCharacteristicSolarHeatingGrid.countCheck() > 0) {
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristicsolarheating.php',
        params: {
          entry_ids:Ext.util.JSON.encode(this.siteCharacteristicSolarHeatingGrid.getCheckBoxValues())
          ,cmd:'delete'
        },
        success: function(response,scope){
          scope.ownerCt.siteCharacteristicSolarHeatingGrid.refresh();
          scope.ownerCt.siteCharacteristicGrid.refresh();
        },
        failure: function() {
        }
      });
    } else {
      Ext.MessageBox.show({
        title: 'Aucun élément sélectionné',
        msg: 'Pour supprimer, veuillez sélectionner les éléments à supprimer avec les checkbox',
        width: 300
      });
    }
  }
  ,initEditSolarHeatingFormWindow: function (grid, rowIndex){
    var record = grid.getStore().getAt(rowIndex);

    if(this.SiteCharacteristicSolarHeatingFormWindow == null || !this.SiteCharacteristicSolarHeatingFormWindow.isVisible()){
      this.siteCharacteristicSolarHeatingFormWindow = new ES.SiteCharacteristicSolarHeatingFormWindow();
      //this.siteCharacteristicSolarHeatingFormWindow.title = "Modification";
      this.siteCharacteristicSolarHeatingForm = this.siteCharacteristicSolarHeatingFormWindow.items.itemAt(0);
      this.siteCharacteristicSolarHeatingFormWindow.setTitle( "Modification : "+this.siteCharacteristicSolarHeatingGrid.type);
      this.siteCharacteristicSolarHeatingFormButton = this.siteCharacteristicSolarHeatingForm.buttons[0];
      var scope_siteCharacteristicSolarHeatingForm = this;
      this.siteCharacteristicSolarHeatingFormButton.on({
        scope:scope_siteCharacteristicSolarHeatingForm,
        click:function(scope){
          this.editSolarHeatingEntry();
        }
      });
      this.siteCharacteristicSolarHeatingFormWindow.show();
    } else {
      this.siteCharacteristicSolarHeatingFormWindow.toFront();
    }
    if(record.get('DBvalue') == '0'){
      this.siteCharacteristicSolarHeatingForm.setField('boolno',true);
    } else {
      this.siteCharacteristicSolarHeatingForm.setField('boolyes',true);
      this.siteCharacteristicSolarHeatingForm.setField('solararea',record.get('area_value'));
    }
    this.siteCharacteristicSolarHeatingForm.setField('year',record.get('date'));
    this.siteCharacteristicSolarHeatingForm.setField('entry_id',record.get('entry_id'));
    this.siteCharacteristicSolarHeatingForm.setField('area_id',record.get('area_id'));
  }
  ,editSolarHeatingEntry: function() {
    if(this.siteCharacteristicSolarHeatingForm.isValid()){
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristicsolarheating.php',
        params: {
          cmd:"update",
          tabletypeinfo:this.siteCharacteristicSolarHeatingGrid.tabletypeinfo,
          tabletypeid:this.siteCharacteristicSolarHeatingGrid.tabletypeid,
          entry_id:this.siteCharacteristicSolarHeatingForm.getField('entry_id').getValue(),
          area_id:this.siteCharacteristicSolarHeatingForm.getField('area_id').getValue(),
          boolvalue: this.siteCharacteristicSolarHeatingForm.getField('boolvalue').getValue(),
          solararea: this.siteCharacteristicSolarHeatingForm.getField('solararea').getValue(),
          year: this.siteCharacteristicSolarHeatingForm.getField('year').getValue()
        },
        success: function(response,scope){
          var result = Ext.util.JSON.decode(response.responseText);
          switch(result.success){
          case 1:
            Ext.MessageBox.alert(
              'Modification'
              ,'Donnée modifiée.'
              ,function(){
                scope.ownerCt.siteCharacteristicSolarHeatingGrid.refresh();
                scope.ownerCt.siteCharacteristicGrid.refresh();
                scope.ownerCt.siteCharacteristicSolarHeatingFormWindow.close();
              }
            ,scope);
            break;
          default:
            Ext.MessageBox.alert('Attention',result.error);
            break;
          }
        },
        failure: function(response) {
          Ext.MessageBox.alert('error','L application n a pas pu se connecter a la base de données. Veuillez réessayer plus tard');
        }
      });
    } else {
      Ext.MessageBox.alert('Attention','Le formulaire n est pas valide');
    }
  },isSiteCharacteristicsDemo: function(){
      Ext.Ajax.request({
        ownerCt: this,
        waitMsg: 'Please wait...',
        url: '/process/extjs/site/profil/sitecharacteristic/sitecharacteristic.php',
        params: {cmd: 'demo'}
        ,
        success: function(response,scope){
          var result = Ext.util.JSON.decode(response.responseText);
          switch(result.success){
            case 1:
               scope.ownerCt.siteCharacteristicRightPanel.demoModality();
            break;          }
        },
        failure: function(response) {
          Ext.MessageBox.alert('error','L application n a pas pu se connecter a la base de données. Veuillez réessayer plus tard');
        }
      });
   }
});

Ext.reg('ESsitecharacteristicmainpanel', ES.SiteCharacteristicMainPanel);
