Ext.define("MyApp.controller.BackgroundStatus",{extend:Ext.app.Controller,refs:[{ref:"statusWindow",selector:"#statusLoadingContainer"},{ref:"statusFormPanel",selector:"#statusForm"},{ref:"taskId",selector:"#statusTaskId"},{ref:"autoUpdateWindow",selector:"#autoUpdateWindow"},{ref:"btnBgRefresh",selector:"#btnBgRefresh"},{ref:"btnBgKick",selector:"#btnBgKick"},{ref:"btnBgKill",selector:"#btnBgKill"}],init:function(a){this.control({"#btnBgRefresh":{click:function(b){this.refreshStatus(b,{},"Re-freshing...")}},"#autoUpdateWindow":{change:function(d,c,b){if(c){this.windowAutoUpdate=true;this.trigger(1)}else{this.windowAutoUpdate=false}d.blur()}},"#btnBgKick":{click:function(b){this.refreshStatus(b,{command:"kick"},"Kick-starting...")}},"#btnBgKill":{click:function(b){var c=this.getTaskId().getValue();if(c>0){this.refreshStatus(b,{command:"kill",taskId:c},"Stopping...")}}},"#statusForm":{close:function(){this.windowAutoUpdate=false}}})},onLaunch:function(){this.refreshStatus(this.getBtnBgRefresh(),{},"Loading...")},getTask:function(a){if(!this._task){this._task=new Ext.util.DelayedTask(this.refreshStatus,this)}return this._task},trigger:function(a){this.getTask().delay(a)},refreshStatus:function(a,d,b){if(!Ext.isEmpty(a)){a.blur()}if(this.getStatusFormPanel()!==undefined){if(!this.windowAutoUpdate){this.getStatusWindow().setLoading(b||CCS.Translator.getText("Refreshing..."))}var c=Ext.Object.fromQueryString(document.location.search);Ext.Object.merge(c,d);Ext.Ajax.request({url:"../../../common/service/report_background_status.php",method:"GET",params:c,success:function(f,g){if(this.getStatusFormPanel()!==undefined){var h=f.responseText;var e=Ext.JSON.decode(h);this.getStatusFormPanel().getForm().reset();this.getStatusFormPanel().getForm().setValues(e);this.getStatusWindow().setLoading(false);if(this.windowAutoUpdate){this.trigger(2500)}}},failure:function(e,f){console.log("Refresh step fail");this.getStatusWindow().setLoading(false);if(this.windowAutoUpdate){this.trigger(9999)}var g=e.responseText;Ext.Error.raise({msg:"Failed to refresh background processing status",option:g,object:f})},scope:this})}else{console.log("GUI not ready")}}});Ext.define("MyApp.view.StatusWindow",{extend:Ext.container.Container,itemId:"statusLoadingContainer",initComponent:function(){var a=this;Ext.applyIf(a,{items:[{xtype:"panel",border:false,bodyPadding:"10 10 0 10",header:false,title:"My Panel",items:[{xtype:"form",border:false,itemId:"statusForm",header:false,title:"My Form",layout:{type:"vbox",align:"stretch"},items:[{xtype:"textfield",fieldLabel:"Status",labelSeparator:" ",name:"runStatus"},{xtype:"textfield",flex:1,fieldLabel:"Name",labelSeparator:" ",name:"name"},{xtype:"textfield",fieldLabel:"Details",labelSeparator:" ",name:"status"},{xtype:"textfield",flex:1,fieldLabel:"System / Client",labelSeparator:" ",name:"syscli"},{xtype:"textfield",flex:1,fieldLabel:"User",labelSeparator:" ",name:"user"},{xtype:"textfield",flex:1,fieldLabel:"Duration",labelSeparator:" ",name:"duration",fieldCls:"x-form-field setRight"},{xtype:"textfield",flex:1,fieldLabel:"Estimated",labelSeparator:" ",name:"eta",fieldCls:"x-form-field setRight"},{xtype:"textfield",fieldLabel:"Created",labelSeparator:" ",name:"created",fieldCls:"x-form-field setRight"},{xtype:"textfield",fieldLabel:"Started",labelSeparator:" ",name:"started",fieldCls:"x-form-field setRight"},{xtype:"textfield",flex:1,itemId:"statusTaskId",fieldLabel:"ID",labelSeparator:" ",name:"id",fieldCls:"x-form-field setRight"},{xtype:"textfield",flex:1,fieldLabel:"Type",labelSeparator:" ",name:"type"}]},{xtype:"container",items:[{xtype:"checkboxfield",itemId:"autoUpdateWindow",fieldLabel:"Refresh status",labelSeparator:" ",boxLabel:"automatically"}]}]},{xtype:"toolbar",border:false,layout:{type:"hbox",defaultMargins:{top:0,right:0,bottom:0,left:0},padding:5},items:[{xtype:"container",flex:1,layout:{type:"hbox",align:"stretch"},items:[{xtype:"button",itemId:"btnBgRefresh",icon:"../gfx/restart.png",text:"Refresh"},{xtype:"tbspacer",flex:1},{xtype:"button",itemId:"btnBgKick",icon:"../gfx/critical.png",text:"Kick-start"},{xtype:"tbspacer",flex:1},{xtype:"button",itemId:"btnBgKill",icon:"../gfx/red_minus.png",text:"Kill task"}]}]}]});a.callParent(arguments)}});