Ext.define("MyApp.controller.GridController",{extend:Ext.app.Controller,refs:[{ref:"usageTypeGrid",selector:"#usageTypeGrid"},{ref:"btnSave",selector:"#btnSave"},{ref:"btnReset",selector:"#btnReset"}],init:function(a){this.control({"#usageTypeGrid":{selectionchange:this.selectionchange},"#btnSave":{click:this.save},"#btnReset":{click:this.reset}})},selectionchange:function(a,e){this.getBtnSave().disable();this.getBtnReset().disable();var d=true;for(var c in e){if(!e[c].get("selected")){d=false}}if(d){var g=this.getUsageTypeGrid().getStore().queryBy(function(){return true}).getRange();for(var c in g){if(g[c].get("selected")){var b=false;for(var f in e){if(e[f].get("type")==g[c].get("type")){b=true}}if(!b){d=false}}}}if(!d){this.getBtnSave().enable();this.getBtnReset().enable()}},save:function(c){c.blur();this.getBtnSave().disable();this.getBtnReset().disable();var d=this.getUsageTypeGrid().getSelectionModel().getSelection();var f=this.getUsageTypeGrid().getStore().queryBy(function(){return true}).getRange();for(var b in f){var a=false;for(var e in d){if(d[e].get("type")==f[b].get("type")){a=true}}if(!a&&f[b].get("selected")){f[b].set("selected",false)}else{if(a&&!f[b].get("selected")){f[b].set("selected",true)}}}this.getUsageTypeGrid().getStore().sync({callback:function(){this.getUsageTypeGrid().getStore().load()},scope:this})},reset:function(b){b.blur();this.getUsageTypeGrid().getSelectionModel().deselectAll();var c=this.getUsageTypeGrid().getStore().queryBy(function(){return true}).getRange();for(var a in c){if(c[a].get("selected")){this.getUsageTypeGrid().getSelectionModel().doMultiSelect(c[a],true,true)}}this.getBtnSave().disable();this.getBtnReset().disable()}});Ext.define("MyApp.model.UsageType",{extend:Ext.data.Model,fields:[{name:"type"},{name:"description"},{name:"selected",type:"boolean"}]});Ext.define("MyApp.store.UsageTypes",{extend:Ext.data.Store,constructor:function(a){var b=this;a=a||{};b.callParent([Ext.apply({autoLoad:true,model:"MyApp.model.UsageType",storeId:"UsageTypes",proxy:{type:"ajax",url:"../../service/settings_usage_types.php",reader:{type:"json",root:"result"}},listeners:{beforeload:{fn:b.onJsonstoreBeforeLoad,scope:b},load:{fn:b.onJsonstoreLoad,scope:b}}},a)])},onJsonstoreBeforeLoad:function(b,a,c){b.getProxy().extraParams=Ext.Object.fromQueryString(document.location.search)},onJsonstoreLoad:function(b,a,d,c){}});Ext.define("MyApp.view.Main",{extend:Ext.panel.Panel,bodyPadding:10,title:"Usage Types",layout:{type:"vbox",align:"stretch",defaultMargins:{top:0,right:0,bottom:0,left:0}},initComponent:function(){var a=this;Ext.applyIf(a,{items:[{xtype:"form",flex:1,border:false,itemId:"settingsForm",margin:0,header:false,trackResetOnLoad:true,layout:{type:"vbox",align:"stretch"},items:[{xtype:"fieldset",flex:1,formBind:true,disabled:true,padding:"3 10 10 10",layout:"fit",title:"Available usage types",items:[{xtype:"gridpanel",border:false,itemId:"usageTypeGrid",bodyBorder:false,header:false,title:"My Grid Panel",store:"UsageTypes",columns:[{xtype:"gridcolumn",cls:"setLeft",width:50,align:"center",dataIndex:"type",text:"Type"},{xtype:"gridcolumn",dataIndex:"description",text:"Description",flex:1},{xtype:"gridcolumn",renderer:function(g,d,c,h,f,e,b){if(g){b.getSelectionModel().doMultiSelect(c,true,true);return'<img src="../gfx/check.png" title="'+CCS.Translator.getText("Type is included in usage collector.")+'" />'}else{return""}},cls:"setLeft",align:"center",dataIndex:"selected",text:"Included"}],selModel:Ext.create("Ext.selection.RowModel",{mode:"MULTI"})}]},{xtype:"container",layout:{type:"hbox",align:"stretch"},items:[{xtype:"button",disabled:true,itemId:"btnSave",icon:"../gfx/save.png",scale:"medium",text:"Save"},{xtype:"tbspacer",flex:1},{xtype:"button",disabled:true,itemId:"btnReset",icon:"../gfx/fav_no.png",scale:"medium",text:"Reset"}]}]}]});a.callParent(arguments)}});