var Spry;if(!Spry){Spry={};}if(!Spry.Data){Spry.Data={};}Spry.Data.PagedView=function(b,a){Spry.Data.DataSet.call(this);this.ds=b;this.pageSize=10;this.pageOffset=0;this.forceFullPages=false;this.pageFirstItemOffset=0;this.useZeroBasedIndexes=false;this.setCurrentRowOnPageChange=false;Spry.Utils.setOptions(this,a);
this.adjustmentValue=1;if(!this.useZeroBasedIndexes){this.adjustmentValue=0;}this.pageStop=this.pageOffset+this.pageSize;this.ds.addObserver(this);this.preProcessData();if(this.pageSize>0){this.filter(this.getFilterFunc());}};Spry.Data.PagedView.prototype=new Spry.Data.DataSet();Spry.Data.PagedView.prototype.constructor=Spry.Data.PagedView;
Spry.Data.PagedView.prototype.setCurrentRow=function(a){if(this.ds){this.ds.setCurrentRow(a);}};Spry.Data.PagedView.prototype.setCurrentRowNumber=function(a){if(this.ds){this.ds.setCurrentRowNumber(a);}};Spry.Data.PagedView.prototype.sort=function(c,b){if(!c){return;}if(typeof c=="string"){c=[c,"ds_RowID"];
}else{if(c.length<2&&c[0]!="ds_RowID"){c.push("ds_RowID");}}if(!b){b="toggle";}if(b=="toggle"){if(this.lastSortColumns.length>0&&this.lastSortColumns[0]==c[0]&&this.lastSortOrder=="ascending"){b="descending";}else{b="ascending";}}var a={oldSortColumns:this.lastSortColumns,oldSortOrder:this.lastSortOrder,newSortColumns:c,newSortOrder:b};
this.notifyObservers("onPreSort",a);this.disableNotifications();Spry.Data.DataSet.prototype.sort.call(this,c,b);this.updatePagerColumns();this.firstPage();this.enableNotifications();this.notifyObservers("onPostSort",a);};Spry.Data.PagedView.prototype.loadData=function(){if(!this.ds||this.ds.getLoadDataRequestIsPending()){return;
}if(!this.ds.getDataWasLoaded()){this.ds.loadData();return;}Spry.Data.DataSet.prototype.loadData.call(this);};Spry.Data.PagedView.prototype.onDataChanged=function(a,b){this.setPageOffset(0);this.preProcessData();};Spry.Data.PagedView.prototype.onCurrentRowChanged=function(b,c){var a=this;setTimeout(function(){a.notifyObservers("onCurrentRowChanged",c);
},0);};Spry.Data.PagedView.prototype.onPostSort=Spry.Data.PagedView.prototype.onDataChanged;Spry.Data.PagedView.prototype.updatePagerColumns=function(){var k=this.getData(true);if(!k||k.length<1){return;}var d=k.length;var f=(this.pageSize>0)?this.pageSize:d;var g=1;var h=g+f-1;h=(h<g)?g:(h>d?d:h);var e=1;
var a=parseInt((d+f-1)/f);var c=Math.min(d,f);for(var b=0;b<d;b++){itemIndex=b+1;if(itemIndex>h){g=itemIndex;h=g+this.pageSize-1;h=(h>d)?d:h;c=Math.min(h-g+1,f);++e;}var j=k[b];if(j){j.ds_PageNumber=e;j.ds_PageSize=this.pageSize;j.ds_PageItemRowNumber=b;j.ds_PageItemNumber=itemIndex;j.ds_PageFirstItemNumber=g;
j.ds_PageLastItemNumber=h;j.ds_PageItemCount=c;j.ds_PageCount=a;j.ds_PageTotalItemCount=d;}}};Spry.Data.PagedView.prototype.preProcessData=function(){if(!this.ds||!this.ds.getDataWasLoaded()){return;}this.notifyObservers("onPreLoad");this.unfilteredData=null;this.data=[];this.dataHash={};var c=this.ds.getData();
if(c){var d=c.length;for(var b=0;b<d;b++){var e=c[b];var a=new Object();Spry.Utils.setOptions(a,e);this.data.push(a);this.dataHash[a.ds_RowID]=a;}if(d>0){this.curRowID=c[0].ds_RowID;}this.updatePagerColumns();}this.loadData();};Spry.Data.PagedView.prototype.getFilterFunc=function(){var a=this;return function(c,d,b){if(b<a.pageOffset||b>=a.pageStop){return null;
}return d;};};Spry.Data.PagedView.prototype.setPageOffset=function(b){var a=this.getData(true).length;this.pageFirstItemOffset=(b<0)?0:b;if(this.forceFullPages&&b>(a-this.pageSize)){b=a-this.pageSize;}if(b<0){b=0;}this.pageOffset=b;this.pageStop=b+this.pageSize;};Spry.Data.PagedView.prototype.filterDataSet=function(b){if(this.pageSize<1){return;
}this.setPageOffset(b);var a=this.getData(true);if(a&&a.length&&a[this.pageFirstItemOffset]){this.curRowID=a[this.pageFirstItemOffset].ds_RowID;}if(this.setCurrentRowOnPageChange){this.ds.setCurrentRow(this.curRowID);}this.filter(this.getFilterFunc());};Spry.Data.PagedView.prototype.getPageCount=function(){return parseInt((this.getData(true).length+this.pageSize-1)/this.pageSize);
};Spry.Data.PagedView.prototype.getCurrentPage=function(){return parseInt((((this.pageFirstItemOffset!=this.pageOffset)?this.pageFirstItemOffset:this.pageOffset)+this.pageSize)/this.pageSize)-this.adjustmentValue;};Spry.Data.PagedView.prototype.goToPage=function(b){b=parseInt(b);var a=this.getPageCount();
if((b+this.adjustmentValue)<1||(b+this.adjustmentValue)>a){return;}var c=(b-1+this.adjustmentValue)*this.pageSize;this.filterDataSet(c);};Spry.Data.PagedView.prototype.goToPageContainingRowID=function(a){this.goToPageContainingRowNumber(this.getRowNumber(this.getRowByID(a),true));};Spry.Data.PagedView.prototype.goToPageContainingRowNumber=function(a){this.goToPage(this.getPageForRowNumber(a));
};Spry.Data.PagedView.prototype.goToPageContainingItemNumber=function(a){this.goToPageContainingRowNumber(a-1);};Spry.Data.PagedView.prototype.firstPage=function(){this.goToPage(1-this.adjustmentValue);};Spry.Data.PagedView.prototype.lastPage=function(){this.goToPage(this.getPageCount()-this.adjustmentValue);
};Spry.Data.PagedView.prototype.previousPage=function(){this.goToPage(this.getCurrentPage()-1);};Spry.Data.PagedView.prototype.nextPage=function(){this.goToPage(this.getCurrentPage()+1);};Spry.Data.PagedView.prototype.getPageForRowID=function(a){return this.getPageForRowNumber(this.getRowNumber(this.getRowByID(a),true));
};Spry.Data.PagedView.prototype.getPageForRowNumber=function(a){return parseInt(a/this.pageSize)+1-this.adjustmentValue;};Spry.Data.PagedView.prototype.getPageForItemNumber=function(a){return this.getPageForRowNumber(a-1);};Spry.Data.PagedView.prototype.getPageSize=function(){return this.pageSize;};Spry.Data.PagedView.prototype.setPageSize=function(a){if(this.pageSize==a){return;
}if(a<1){this.pageSize=0;this.setPageOffset(0);this.updatePagerColumns();this.filter(null);}else{if(this.pageSize<1){this.pageSize=a;this.setPageOffset(0);this.updatePagerColumns();this.filterDataSet(this.pageOffset);}else{this.pageSize=a;this.updatePagerColumns();this.goToPage(this.getPageForRowNumber(this.pageFirstItemOffset));
}}};Spry.Data.PagedView.prototype.getPagingInfo=function(){return new Spry.Data.PagedView.PagingInfo(this);};Spry.Data.PagedView.PagingInfo=function(a){Spry.Data.DataSet.call(this);this.pagedView=a;a.addObserver(this);};Spry.Data.PagedView.PagingInfo.prototype=new Spry.Data.DataSet();Spry.Data.PagedView.PagingInfo.prototype.constructor=Spry.Data.PagedView.PagingInfo;
Spry.Data.PagedView.PagingInfo.prototype.onDataChanged=function(a,b){this.extractInfo();};Spry.Data.PagedView.PagingInfo.prototype.onPostSort=Spry.Data.PagedView.PagingInfo.prototype.onDataChanged;Spry.Data.PagedView.PagingInfo.prototype.extractInfo=function(){var f=this.pagedView;if(!f||!f.getDataWasLoaded()){return;
}this.notifyObservers("onPreLoad");this.unfilteredData=null;this.data=[];this.dataHash={};var k=f.getData(true);if(k){var e=k.length;var c=f.getPageCount();var d=0;var a=0;while(d<e){var j=k[d];var h=new Object();h.ds_RowID=a++;this.data.push(h);this.dataHash[h.ds_RowID]=h;h.ds_PageNumber=j.ds_PageNumber;
h.ds_PageSize=j.ds_PageSize;h.ds_PageCount=j.ds_PageCount;h.ds_PageFirstItemNumber=j.ds_PageFirstItemNumber;h.ds_PageLastItemNumber=j.ds_PageLastItemNumber;h.ds_PageItemCount=j.ds_PageItemCount;h.ds_PageTotalItemCount=j.ds_PageTotalItemCount;d+=h.ds_PageSize;}if(e>0){var g=this;var b=function(m,i,l){if(m!="onPostLoad"){return;
}g.removeObserver(b);g.setCurrentRowNumber(f.getCurrentPage()-(f.useZeroBasedIndexes?0:1));};this.addObserver(b);}}this.loadData();};
