AutoRefresher_wev8.js 1.55 KB
Ext.namespace("Ext.ux.grid");Ext.ux.grid.AutoRefresher=function(a){Ext.apply(this,a)};Ext.extend(Ext.ux.grid.AutoRefresher,Ext.util.Observable,{intervals:[[-1,"从不"],[1,"1"],[2,"2"],[5,"5"],[10,"10"],[15,"15"]],beforeText:"刷新间隔",afterText:"",addBefore:"-",addAfter:null,interval:5,combo:null,init:function(a){this.Toolbar=a;if(a.store){this.store=a.store}a.on("render",this.onRender,this);this.store.startAutoRefresh=function(b){if(this.autoRefreshProcId){clearInterval(this.autoRefreshProcId)}this.autoRefreshProcId=setInterval(function(){var c=a.getPageData().activePage;var d={start:(c-1)*a.pageSize,limit:a.pageSize};this.store.load({params:d})},b*1000)};this.store.stopAutoRefresh=function(){if(this.autoRefreshProcId){clearInterval(this.autoRefreshProcId)}}},update:function(b){var a=b.getValue();if(a>0){this.store.startAutoRefresh(a*60)}else{this.store.stopAutoRefresh()}},start:function(){this.update(combo)},onRender:function(){var a={maskRe:/^d*$/,store:new Ext.data.SimpleStore({fields:["id","text"],data:this.intervals}),displayField:"text",typeAhead:true,mode:"local",forceSelection:true,triggerAction:"all",selectOnFocus:true,value:this.interval,width:50};Ext.apply(a,this.comboCfg);combo=new Ext.form.ComboBox(a);combo.on("change",this.update,this);combo.on("select",this.update,this);if(this.addBefore){this.Toolbar.add(this.addBefore)}this.Toolbar.add(this.beforeText,combo,this.afterText);if(this.addAfter){this.Toolbar.add(this.addAfter)}combo.getEl().on("keydown",function(c){var b=c.getKey();switch(b){case Ext.EventObject.ENTER:this.update(combo)}},this)}});