//>>built
define("dgrid/extensions/Pagination","../_StoreMixin dojo/_base/declare dojo/_base/array dojo/_base/lang dojo/dom-construct dojo/dom-class dojo/on dojo/query dojo/string dojo/has dojo/when ../util/misc dojo/i18n!./nls/pagination dojo/_base/sniff".split(" "),function(v,w,x,y,e,z,r,t,A,E,B,F,C){function D(b){b.noDataNode?(e.destroy(b.noDataNode),delete b.noDataNode):b.cleanup();b.contentNode.innerHTML=""}function p(b){if(b.loadingNode)e.destroy(b.loadingNode),delete b.loadingNode;else if(b._oldPageNodes){for(var a in b._oldPageNodes)b.removeRow(b._oldPageNodes[a]);
delete b._oldPageNodes}delete b._isLoading}return w(v,{rowsPerPage:10,pagingTextBox:!1,previousNextArrows:!0,firstLastArrows:!1,pagingLinks:2,pageSizeOptions:null,showLoadingMessage:!0,i18nPagination:C,showFooter:!0,_currentPage:1,buildRendering:function(){this.inherited(arguments);var b=this,a=this.paginationNode=e.create("div",{className:"dgrid-pagination"},this.footerNode),c=this.paginationStatusNode=e.create("div",{className:"dgrid-status"},a),d=this.i18nPagination;c.tabIndex=0;this._updatePaginationSizeSelect();
this._updateRowsPerPageOption();this._updatePaginationStatus(this._total);a=this.paginationNavigationNode=e.create("div",{className:"dgrid-navigation"},a);this.firstLastArrows&&(this.paginationFirstNode=e.create("span",{"aria-label":d.gotoFirst,className:"dgrid-first dgrid-page-link",innerHTML:"\u00ab",tabIndex:0},a));this.previousNextArrows&&(this.paginationPreviousNode=e.create("span",{"aria-label":d.gotoPrev,className:"dgrid-previous dgrid-page-link",innerHTML:"\u2039",tabIndex:0},a));this.paginationLinksNode=
e.create("span",{className:"dgrid-pagination-links"},a);this.previousNextArrows&&(this.paginationNextNode=e.create("span",{"aria-label":d.gotoNext,className:"dgrid-next dgrid-page-link",innerHTML:"\u203a",tabIndex:0},a));this.firstLastArrows&&(this.paginationLastNode=e.create("span",{"aria-label":d.gotoLast,className:"dgrid-last dgrid-page-link",innerHTML:"\u00bb",tabIndex:0},a));this._listeners.push(r(a,".dgrid-page-link:click,.dgrid-page-link:keydown",function(a){if("keydown"!==a.type||13===a.keyCode){a=
this.className;var c,d;b._isLoading||-1<a.indexOf("dgrid-page-disabled")||(c=b._currentPage,d=Math.ceil(b._total/b.rowsPerPage),this===b.paginationPreviousNode?b.gotoPage(c-1):this===b.paginationNextNode?b.gotoPage(c+1):this===b.paginationFirstNode?b.gotoPage(1):this===b.paginationLastNode?b.gotoPage(d):"dgrid-page-link"===a&&b.gotoPage(+this.innerHTML))}}))},destroy:function(){this.inherited(arguments);this._pagingTextBoxHandle&&this._pagingTextBoxHandle.remove()},_updatePaginationSizeSelect:function(){var b=
this.pageSizeOptions,a=this.paginationSizeSelect,c;if(b&&b.length){a||(a=this.paginationSizeSelect=e.create("select",{"aria-label":this.i18nPagination.rowsPerPage,className:"dgrid-page-size"},this.paginationNode),c=this._paginationSizeChangeHandle=r(a,"change",y.hitch(this,function(){this.set("rowsPerPage",+this.paginationSizeSelect.value)})),this._listeners.push(c));for(c=a.options.length=0;c<b.length;c++)e.create("option",{innerHTML:b[c],selected:this.rowsPerPage===b[c],value:b[c]},a);this._updateRowsPerPageOption()}else b&&
b.length||!a||(e.destroy(a),this.paginationSizeSelect=null,this._paginationSizeChangeHandle.remove())},_setPageSizeOptions:function(b){this.pageSizeOptions=b&&b.sort(function(a,b){return a-b});this._updatePaginationSizeSelect()},_updateRowsPerPageOption:function(){var b=this.rowsPerPage,a=this.pageSizeOptions,c=this.paginationSizeSelect;c&&(0>x.indexOf(a,b)?this._setPageSizeOptions(a.concat([b])):c.value=""+b)},_setRowsPerPage:function(b){this.rowsPerPage=b;this._updateRowsPerPageOption();this.gotoPage(1)},
_updateNavigation:function(b){function a(a,b){var c,d;m.pagingTextBox&&a===f&&1<k?(c=e.create("input",{"aria-label":q.jumpPage,className:"dgrid-page-input",type:"text",value:f},n),m._pagingTextBoxHandle=r(c,"change",function(){var a=+this.value;!isNaN(a)&&0<a&&a<=k&&m.gotoPage(+this.value)}),g&&"INPUT"===g.tagName&&c.focus()):(d=a===f,c=e.create("span",{"aria-label":q.gotoPage,className:"dgrid-page-link"+(d?" dgrid-page-disabled":""),innerHTML:a+(b?" ":""),tabIndex:d?-1:0},n),u===a&&(d?a<k?u++:p.focus():
c.focus()),d||(p=c))}function c(a,b){z.toggle(a,"dgrid-page-disabled",b);a.tabIndex=b?-1:0}function d(){e.create("span",{className:"dgrid-page-skip",innerHTML:"..."},n)}var m=this,q=this.i18nPagination,n=this.paginationLinksNode,f=this._currentPage,l=this.pagingLinks,h=this.paginationNavigationNode,k=Math.ceil(b/this.rowsPerPage);b=this._pagingTextBoxHandle;var g=document.activeElement,u,p;g&&this.paginationNavigationNode.contains(g)?"dgrid-page-link"===g.className&&(u=+g.innerHTML):g=null;b&&b.remove();
n.innerHTML="";t(".dgrid-first, .dgrid-previous",h).forEach(function(a){c(a,1===f)});t(".dgrid-last, .dgrid-next",h).forEach(function(a){c(a,f>=k)});if(l&&0<k){a(1,!0);h=f-l;for(2<h?d():h=2;h<Math.min(f+l+1,k);h++)a(h,!0);f+l+1<k&&d();1<k&&a(k)}else m.pagingTextBox&&a(f);g&&-1===g.tabIndex&&(l=t('[tabindex\x3d"0"]',this.paginationNavigationNode),g===this.paginationPreviousNode||g===this.paginationFirstNode?g=l[0]:l.length&&(g=l[l.length-1]),g&&g.focus())},_updatePaginationStatus:function(b){var a=
this.rowsPerPage,c=Math.min(b,(this._currentPage-1)*a+1);this.paginationStatusNode.innerHTML=A.substitute(this.i18nPagination.status,{start:c,end:Math.min(b,c+a-1),total:b})},refresh:function(b){var a=this,c=b&&b.keepCurrentPage?Math.min(this._currentPage,Math.ceil(this._total/this.rowsPerPage)):1;this.inherited(arguments);return this.gotoPage(c).then(function(b){a._emitRefreshComplete();return b})},_onNotification:function(b,a,c){b=this.rowsPerPage;var d=this._currentPage*b;"add"===a.type&&a.index<
d||"delete"===a.type&&a.previousIndex<d||"update"===a.type&&Math.floor(a.index/b)!==Math.floor(a.previousIndex/b)?this.gotoPage(Math.min(this._currentPage,Math.ceil(a.totalLength/this.rowsPerPage))||1):c===this._renderedCollection&&a.totalLength!==this._total&&(this._updatePaginationStatus(a.totalLength),this._updateNavigation(a.totalLength))},renderQueryResults:function(b,a){var c=this,d=this.inherited(arguments);a||(this._topLevelRequest&&(this._topLevelRequest.cancel(),delete this._topLevelRequest),
"function"===typeof d.cancel&&(this._topLevelRequest=d),d.then(function(){c._topLevelRequest&&delete c._topLevelRequest}));return d},insertRow:function(){var b=this._oldPageNodes,a=this.inherited(arguments);b&&a===b[a.id]&&delete b[a.id];return a},gotoPage:function(b){var a=this,c=(this._currentPage-1)*this.rowsPerPage;if(!this._renderedCollection)return B([]);this._renderedCollection.releaseRange&&this._renderedCollection.releaseRange(c,c+this.rowsPerPage);return this._trackError(function(){var c=
a.rowsPerPage,m=(b-1)*c,q={start:m,count:c},n,f=a.contentNode,l,h,k;if(a.showLoadingMessage)D(a),a.loadingNode=e.create("div",{className:"dgrid-loading",innerHTML:a.loadingMessage},f);else for(a._oldPageNodes=l={},f=f.children,h=0,k=f.length;h<k;h++)l[f[h].id]=f[h];a._isLoading=!0;n=a._renderedCollection.fetchRange({start:m,end:m+c});return a.renderQueryResults(n,null,q).then(function(d){p(a);a.scrollTo({y:0});a._rows&&(a._rows.min=m,a._rows.max=m+c-1);n.totalLength.then(function(c){c||(a.noDataNode&&
(e.destroy(a.noDataNode),delete a.noDataNode),a._insertNoDataNode());a._total=c;a._currentPage=b;a._rowsOnPage=d.length;a._updatePaginationStatus(c);a._updateNavigation(c)});return n},function(b){p(a);throw b;})})}})});
//# sourceMappingURL=Pagination.js.map