
(function(){var T=Ext.Toolbar;Ext.PagingToolbar=Ext.extend(Ext.Toolbar,{pageSize:20,displayMsg:'Displaying {0} - {1} of {2}',emptyMsg:'No data to display',beforePageText:'Page',afterPageText:'of {0}',firstText:'First Page',prevText:'Previous Page',nextText:'Next Page',lastText:'Last Page',refreshText:'Refresh',initComponent:function(){var pagingItems=[this.first=new T.Button({tooltip:this.firstText,overflowText:this.firstText,iconCls:'x-tbar-page-first',disabled:true,handler:this.moveFirst,scope:this}),this.prev=new T.Button({tooltip:this.prevText,overflowText:this.prevText,iconCls:'x-tbar-page-prev',disabled:true,handler:this.movePrevious,scope:this}),'-',this.beforePageText,this.inputItem=new Ext.form.NumberField({cls:'x-tbar-page-number',allowDecimals:false,allowNegative:false,enableKeyEvents:true,selectOnFocus:true,submitValue:false,listeners:{scope:this,keydown:this.onPagingKeyDown,blur:this.onPagingBlur}}),this.afterTextItem=new T.TextItem({text:String.format(this.afterPageText,1)}),'-',this.next=new T.Button({tooltip:this.nextText,overflowText:this.nextText,iconCls:'x-tbar-page-next',disabled:true,handler:this.moveNext,scope:this}),this.last=new T.Button({tooltip:this.lastText,overflowText:this.lastText,iconCls:'x-tbar-page-last',disabled:true,handler:this.moveLast,scope:this}),'-',this.refresh=new T.Button({tooltip:this.refreshText,overflowText:this.refreshText,iconCls:'x-tbar-loading',handler:this.doRefresh,scope:this})];var userItems=this.items||this.buttons||[];if(this.prependButtons){this.items=userItems.concat(pagingItems);}else{this.items=pagingItems.concat(userItems);}
delete this.buttons;if(this.displayInfo){this.items.push('->');this.items.push(this.displayItem=new T.TextItem({}));}
Ext.PagingToolbar.superclass.initComponent.call(this);this.addEvents('change','beforechange');this.on('afterlayout',this.onFirstLayout,this,{single:true});this.cursor=0;this.bindStore(this.store,true);},onFirstLayout:function(){if(this.dsLoaded){this.onLoad.apply(this,this.dsLoaded);}},updateInfo:function(){if(this.displayItem){var count=this.store.getCount();var msg=count==0?this.emptyMsg:String.format(this.displayMsg,this.cursor+1,this.cursor+count,this.store.getTotalCount());this.displayItem.setText(msg);}},onLoad:function(store,r,o){if(!this.rendered){this.dsLoaded=[store,r,o];return;}
var p=this.getParams();this.cursor=(o.params&&o.params[p.start])?o.params[p.start]:0;var d=this.getPageData(),ap=d.activePage,ps=d.pages;this.afterTextItem.setText(String.format(this.afterPageText,d.pages));this.inputItem.setValue(ap);this.first.setDisabled(ap==1);this.prev.setDisabled(ap==1);this.next.setDisabled(ap==ps);this.last.setDisabled(ap==ps);this.refresh.enable();this.updateInfo();this.fireEvent('change',this,d);},getPageData:function(){var total=this.store.getTotalCount();return{total:total,activePage:Math.ceil((this.cursor+this.pageSize)/this.pageSize),pages:total<this.pageSize?1:Math.ceil(total/this.pageSize)};},changePage:function(page){this.doLoad(((page-1)*this.pageSize).constrain(0,this.store.getTotalCount()));},onLoadError:function(){if(!this.rendered){return;}
this.refresh.enable();},readPage:function(d){var v=this.inputItem.getValue(),pageNum;if(!v||isNaN(pageNum=parseInt(v,10))){this.inputItem.setValue(d.activePage);return false;}
return pageNum;},onPagingFocus:function(){this.inputItem.select();},onPagingBlur:function(e){this.inputItem.setValue(this.getPageData().activePage);},onPagingKeyDown:function(field,e){var k=e.getKey(),d=this.getPageData(),pageNum;if(k==e.RETURN){e.stopEvent();pageNum=this.readPage(d);if(pageNum!==false){pageNum=Math.min(Math.max(1,pageNum),d.pages)-1;this.doLoad(pageNum*this.pageSize);}}else if(k==e.HOME||k==e.END){e.stopEvent();pageNum=k==e.HOME?1:d.pages;field.setValue(pageNum);}else if(k==e.UP||k==e.PAGEUP||k==e.DOWN||k==e.PAGEDOWN){e.stopEvent();if((pageNum=this.readPage(d))){var increment=e.shiftKey?10:1;if(k==e.DOWN||k==e.PAGEDOWN){increment*=-1;}
pageNum+=increment;if(pageNum>=1&pageNum<=d.pages){field.setValue(pageNum);}}}},getParams:function(){return this.paramNames||this.store.paramNames;},beforeLoad:function(){if(this.rendered&&this.refresh){this.refresh.disable();}},doLoad:function(start){var o={},pn=this.getParams();o[pn.start]=start;o[pn.limit]=this.pageSize;if(this.fireEvent('beforechange',this,o)!==false){this.store.load({params:o});}},moveFirst:function(){this.doLoad(0);},movePrevious:function(){this.doLoad(Math.max(0,this.cursor-this.pageSize));},moveNext:function(){this.doLoad(this.cursor+this.pageSize);},moveLast:function(){var total=this.store.getTotalCount(),extra=total%this.pageSize;this.doLoad(extra?(total-extra):total-this.pageSize);},doRefresh:function(){this.doLoad(this.cursor);},bindStore:function(store,initial){var doLoad;if(!initial&&this.store){if(store!==this.store&&this.store.autoDestroy){this.store.destroy();}else{this.store.un('beforeload',this.beforeLoad,this);this.store.un('load',this.onLoad,this);this.store.un('exception',this.onLoadError,this);}
if(!store){this.store=null;}}
if(store){store=Ext.StoreMgr.lookup(store);store.on({scope:this,beforeload:this.beforeLoad,load:this.onLoad,exception:this.onLoadError});doLoad=true;}
this.store=store;if(doLoad){this.onLoad(store,null,{});}},unbind:function(store){this.bindStore(null);},bind:function(store){this.bindStore(store);},onDestroy:function(){this.bindStore(null);Ext.PagingToolbar.superclass.onDestroy.call(this);}});})();Ext.reg('paging',Ext.PagingToolbar);Ext.ns('Ext.ux.data');Ext.ux.data.PagingStore=Ext.extend(Ext.data.Store,{destroy:function(){if(this.storeId){Ext.StoreMgr.unregister(this);}
this.data=this.allData=this.snapshot=null;Ext.destroy(this.proxy);this.reader=this.writer=null;this.purgeListeners();},add:function(records){records=[].concat(records);if(records.length<1){return;}
for(var i=0,len=records.length;i<len;i++){records[i].join(this);}
var index=this.data.length;this.data.addAll(records);if(this.allData){this.allData.addAll(records);}
if(this.snapshot){this.snapshot.addAll(records);}
this.fireEvent("add",this,records,index);},remove:function(record){var index=this.data.indexOf(record);if(index>-1){this.data.removeAt(index);}
if(this.allData){this.allData.remove(record);}
if(this.snapshot){this.snapshot.remove(record);}
if(this.pruneModifiedRecords){this.modified.remove(record);}
if(index>-1){this.fireEvent("remove",this,record,index);}},removeAll:function(){this.data.clear();if(this.allData){this.allData.clear();}
if(this.snapshot){this.snapshot.clear();}
if(this.pruneModifiedRecords){this.modified=[];}
this.fireEvent("clear",this);},insert:function(index,records){records=[].concat(records);for(var i=0,len=records.length;i<len;i++){this.data.insert(index,records[i]);records[i].join(this);}
if(this.allData){this.allData.addAll(records);}
if(this.snapshot){this.snapshot.addAll(records);}
this.fireEvent("add",this,records,index);},getById:function(id){return(this.snapshot||this.allData||this.data).key(id);},execute:function(action,rs,options){if(!Ext.data.Api.isAction(action)){throw new Ext.data.Api.Error('execute',action);}
options=Ext.applyIf(options||{},{params:{}});var doRequest=true;if(action==="read"){doRequest=this.fireEvent('beforeload',this,options);}
else{if(this.writer.listful===true&&this.restful!==true){rs=(Ext.isArray(rs))?rs:[rs];}
else if(Ext.isArray(rs)&&rs.length==1){rs=rs.shift();}
if((doRequest=this.fireEvent('beforewrite',this,action,rs,options))!==false){this.writer.write(action,options.params,rs);}}
if(doRequest!==false){var params=Ext.apply({},options.params,this.baseParams);if(this.writer&&this.proxy.url&&!this.proxy.restful&&!Ext.data.Api.hasUniqueUrl(this.proxy,action)){params.xaction=action;}
if(action==="read"&&this.isPaging(params)){(function(){if(this.allData){this.data=this.allData;delete this.allData;}
this.applyPaging();this.fireEvent("datachanged",this);var r=[].concat(this.data.items);this.fireEvent("load",this,r,options);if(options.callback){options.callback.call(options.scope||this,r,options,true);}}).defer(1,this);return true;}
this.proxy.request(Ext.data.Api.actions[action],rs,params,this.reader,this.createCallback(action,rs),this,options);}
return doRequest;},loadRecords:function(o,options,success){if(!o||success===false){if(success!==false){this.fireEvent("load",this,[],options);}
if(options.callback){options.callback.call(options.scope||this,[],options,false,o);}
return;}
var r=o.records,t=o.totalRecords||r.length;if(!options||options.add!==true){if(this.pruneModifiedRecords){this.modified=[];}
for(var i=0,len=r.length;i<len;i++){r[i].join(this);}
if(this.allData){this.data=this.allData;delete this.allData;}
if(this.snapshot){this.data=this.snapshot;delete this.snapshot;}
this.data.clear();this.data.addAll(r);this.totalLength=t;this.applySort();if(!this.allData){this.applyPaging();}
if(r.length!=this.getCount()){r=[].concat(this.data.items);}
this.fireEvent("datachanged",this);}else{this.totalLength=Math.max(t,this.data.length+r.length);this.add(r);}
this.fireEvent("load",this,r,options);if(options.callback){options.callback.call(options.scope||this,r,options,true);}},loadData:function(o,append){this.isPaging(Ext.apply({},this.lastOptions?this.lastOptions.params:null,this.baseParams));var r=this.reader.readRecords(o);this.loadRecords(r,{add:append},true);},getTotalCount:function(){return this.allData?this.allData.getCount():this.totalLength||0;},sortData:function(f,direction){direction=direction||'ASC';var st=this.fields.get(f).sortType;var fn=function(r1,r2){var v1=st(r1.data[f]),v2=st(r2.data[f]);return v1>v2?1:(v1<v2?-1:0);};if(this.allData){this.data=this.allData;delete this.allData;}
this.data.sort(direction,fn);if(this.snapshot&&this.snapshot!=this.data){this.snapshot.sort(direction,fn);}
this.applyPaging();},filterBy:function(fn,scope){this.snapshot=this.snapshot||this.allData||this.data;delete this.allData;this.data=this.queryBy(fn,scope||this);this.applyPaging();this.fireEvent("datachanged",this);},queryBy:function(fn,scope){var data=this.snapshot||this.allData||this.data;return data.filterBy(fn,scope||this);},collect:function(dataIndex,allowNull,bypassFilter){var d=(bypassFilter===true?this.snapshot||this.allData||this.data:this.data).items;var v,sv,r=[],l={};for(var i=0,len=d.length;i<len;i++){v=d[i].data[dataIndex];sv=String(v);if((allowNull||!Ext.isEmpty(v))&&!l[sv]){l[sv]=true;r[r.length]=v;}}
return r;},clearFilter:function(suppressEvent){if(this.isFiltered()){this.data=this.snapshot;delete this.allData;delete this.snapshot;this.applyPaging();if(suppressEvent!==true){this.fireEvent("datachanged",this);}}},isFiltered:function(){return this.snapshot&&this.snapshot!=(this.allData||this.data);},isPaging:function(params){var pn=this.paramNames,start=params[pn.start],limit=params[pn.limit];if((typeof start!='number')||(typeof limit!='number')){delete this.start;delete this.limit;this.lastParams=params;return false;}
this.start=start;this.limit=limit;delete params[pn.start];delete params[pn.limit];var lastParams=this.lastParams;this.lastParams=params;if(!this.proxy){return true;}
if(!lastParams){return false;}
for(var param in params){if(params.hasOwnProperty(param)&&(params[param]!==lastParams[param])){return false;}}
for(param in lastParams){if(lastParams.hasOwnProperty(param)&&(params[param]!==lastParams[param])){return false;}}
return true;},applyPaging:function(){var start=this.start,limit=this.limit;if((typeof start=='number')&&(typeof limit=='number')){var allData=this.data,data=new Ext.util.MixedCollection(allData.allowFunctions,allData.getKey);data.items=allData.items.slice(start,start+limit);data.keys=allData.keys.slice(start,start+limit);var len=data.length=data.items.length;var map={};for(var i=0;i<len;i++){var item=data.items[i];map[data.getKey(item)]=item;}
data.map=map;this.allData=allData;this.data=data;}}});Ext.ux.data.PagingDirectStore=function(c){c.batchTransactions=false;Ext.ux.data.PagingDirectStore.superclass.constructor.call(this,Ext.apply(c,{proxy:(typeof(c.proxy)=='undefined')?new Ext.data.DirectProxy(Ext.copyTo({},c,'paramOrder,paramsAsHash,directFn,api')):c.proxy,reader:(typeof(c.reader)=='undefined'&&typeof(c.fields)=='object')?new Ext.data.JsonReader(Ext.copyTo({},c,'totalProperty,root,idProperty'),c.fields):c.reader}));};Ext.extend(Ext.ux.data.PagingDirectStore,Ext.ux.data.PagingStore,{});Ext.reg('pagingdirectstore',Ext.ux.data.PagingDirectStore);Ext.ux.data.PagingJsonStore=Ext.extend(Ext.ux.data.PagingStore,{constructor:function(config){Ext.ux.data.PagingJsonStore.superclass.constructor.call(this,Ext.apply(config,{reader:new Ext.data.JsonReader(config)}));}});Ext.reg('pagingjsonstore',Ext.ux.data.PagingJsonStore);Ext.ux.data.PagingXmlStore=Ext.extend(Ext.ux.data.PagingStore,{constructor:function(config){Ext.ux.data.PagingXmlStore.superclass.constructor.call(this,Ext.apply(config,{reader:new Ext.data.XmlReader(config)}));}});Ext.reg('pagingxmlstore',Ext.ux.data.PagingXmlStore);Ext.ux.data.PagingArrayStore=Ext.extend(Ext.ux.data.PagingStore,{constructor:function(config){Ext.ux.data.PagingArrayStore.superclass.constructor.call(this,Ext.apply(config,{reader:new Ext.data.ArrayReader(config)}));},loadData:function(data,append){if(this.expandData===true){var r=[];for(var i=0,len=data.length;i<len;i++){r[r.length]=[data[i]];}
data=r;}
Ext.ux.data.PagingArrayStore.superclass.loadData.call(this,data,append);}});Ext.reg('pagingarraystore',Ext.ux.data.PagingArrayStore);Ext.ux.data.PagingSimpleStore=Ext.ux.data.PagingArrayStore;Ext.reg('pagingsimplestore',Ext.ux.data.PagingSimpleStore);if(!Array.prototype.map){Array.prototype.map=function(fun){var len=this.length;if(typeof fun!='function'){throw new TypeError();}
var res=new Array(len);var thisp=arguments[1];for(var i=0;i<len;i++){if(i in this){res[i]=fun.call(thisp,this[i],i,this);}}
return res;};}
Ext.ns('Ext.ux.data');Ext.ux.data.PagingMemoryProxy=Ext.extend(Ext.data.MemoryProxy,{constructor:function(data){Ext.ux.data.PagingMemoryProxy.superclass.constructor.call(this);this.data=data;},doRequest:function(action,rs,params,reader,callback,scope,options){params=params||{};var result;try{result=reader.readRecords(this.data);}
catch(e){this.fireEvent('loadexception',this,options,null,e);callback.call(scope,null,options,false);return;}
if(params.filter!==undefined){result.records=result.records.filter(function(el){if(typeof(el)=='object'){var att=params.filterCol||0;return String(el.data[att]).match(params.filter)?true:false;}
else{return String(el).match(params.filter)?true:false;}});result.totalRecords=result.records.length;}
if(params.sort!==undefined){var dir=String(params.dir).toUpperCase()=='DESC'?-1:1;var fn=function(r1,r2){return r1<r2;};result.records.sort(function(a,b){var v=0;if(typeof(a)=='object'){v=fn(a.data[params.sort],b.data[params.sort])*dir;}
else{v=fn(a,b)*dir;}
if(v==0){v=(a.index<b.index?-1:1);}
return v;});}
if(params.start!==undefined&&params.limit!==undefined){result.records=result.records.slice(params.start,params.start+params.limit);}
callback.call(scope,result,options,true);}});Ext.data.PagingMemoryProxy=Ext.ux.data.PagingMemoryProxy;
