otsdaq_utilities  v2_05_02_indev
page.min.js
1 /* Tabulator v4.5.3 (c) Oliver Folkerd */
2 var Page=function(e){this.table=e,this.mode="local",this.progressiveLoad=!1,this.size=0,this.page=1,this.count=5,this.max=1,this.displayIndex=0,this.pageSizes=[],this.createElements()};Page.prototype.createElements=function(){var e;this.element=document.createElement("span"),this.element.classList.add("tabulator-paginator"),this.pagesElement=document.createElement("span"),this.pagesElement.classList.add("tabulator-pages"),e=document.createElement("button"),e.classList.add("tabulator-page"),e.setAttribute("type","button"),e.setAttribute("role","button"),e.setAttribute("aria-label",""),e.setAttribute("title",""),this.firstBut=e.cloneNode(!0),this.firstBut.setAttribute("data-page","first"),this.prevBut=e.cloneNode(!0),this.prevBut.setAttribute("data-page","prev"),this.nextBut=e.cloneNode(!0),this.nextBut.setAttribute("data-page","next"),this.lastBut=e.cloneNode(!0),this.lastBut.setAttribute("data-page","last"),this.table.options.paginationSizeSelector&&(this.pageSizeSelect=document.createElement("select"),this.pageSizeSelect.classList.add("tabulator-page-size"))},Page.prototype.generatePageSizeSelectList=function(){var e=this,t=[];if(this.pageSizeSelect){if(Array.isArray(this.table.options.paginationSizeSelector))t=this.table.options.paginationSizeSelector,this.pageSizes=t,-1==this.pageSizes.indexOf(this.size)&&t.unshift(this.size);else if(-1==this.pageSizes.indexOf(this.size)){t=[];for(var a=1;a<5;a++)t.push(this.size*a);this.pageSizes=t}else t=this.pageSizes;for(;this.pageSizeSelect.firstChild;)this.pageSizeSelect.removeChild(this.pageSizeSelect.firstChild);t.forEach(function(t){var a=document.createElement("option");a.value=t,a.innerHTML=t,e.pageSizeSelect.appendChild(a)}),this.pageSizeSelect.value=this.size}},Page.prototype.initialize=function(e){var t,a=this;for(var i in a.table.options.paginationDataSent)a.paginationDataSentNames[i]=a.table.options.paginationDataSent[i];for(var n in a.table.options.paginationDataReceived)a.paginationDataReceivedNames[n]=a.table.options.paginationDataReceived[n];a.table.modules.localize.bind("pagination|first",function(e){a.firstBut.innerHTML=e}),a.table.modules.localize.bind("pagination|first_title",function(e){a.firstBut.setAttribute("aria-label",e),a.firstBut.setAttribute("title",e)}),a.table.modules.localize.bind("pagination|prev",function(e){a.prevBut.innerHTML=e}),a.table.modules.localize.bind("pagination|prev_title",function(e){a.prevBut.setAttribute("aria-label",e),a.prevBut.setAttribute("title",e)}),a.table.modules.localize.bind("pagination|next",function(e){a.nextBut.innerHTML=e}),a.table.modules.localize.bind("pagination|next_title",function(e){a.nextBut.setAttribute("aria-label",e),a.nextBut.setAttribute("title",e)}),a.table.modules.localize.bind("pagination|last",function(e){a.lastBut.innerHTML=e}),a.table.modules.localize.bind("pagination|last_title",function(e){a.lastBut.setAttribute("aria-label",e),a.lastBut.setAttribute("title",e)}),a.firstBut.addEventListener("click",function(){a.setPage(1)}),a.prevBut.addEventListener("click",function(){a.previousPage()}),a.nextBut.addEventListener("click",function(){a.nextPage().then(function(){}).catch(function(){})}),a.lastBut.addEventListener("click",function(){a.setPage(a.max)}),a.table.options.paginationElement&&(a.element=a.table.options.paginationElement),this.pageSizeSelect&&(t=document.createElement("label"),a.table.modules.localize.bind("pagination|page_size",function(e){a.pageSizeSelect.setAttribute("aria-label",e),a.pageSizeSelect.setAttribute("title",e),t.innerHTML=e}),a.element.appendChild(t),a.element.appendChild(a.pageSizeSelect),a.pageSizeSelect.addEventListener("change",function(e){a.setPageSize(a.pageSizeSelect.value),a.setPage(1).then(function(){}).catch(function(){})})),a.element.appendChild(a.firstBut),a.element.appendChild(a.prevBut),a.element.appendChild(a.pagesElement),a.element.appendChild(a.nextBut),a.element.appendChild(a.lastBut),a.table.options.paginationElement||e||a.table.footerManager.append(a.element,a),a.mode=a.table.options.pagination,a.size=a.table.options.paginationSize||Math.floor(a.table.rowManager.getElement().clientHeight/24),a.count=a.table.options.paginationButtonCount,a.generatePageSizeSelectList()},Page.prototype.initializeProgressive=function(e){this.initialize(!0),this.mode="progressive_"+e,this.progressiveLoad=!0},Page.prototype.setDisplayIndex=function(e){this.displayIndex=e},Page.prototype.getDisplayIndex=function(){return this.displayIndex},Page.prototype.setMaxRows=function(e){this.max=e?Math.ceil(e/this.size):1,this.page>this.max&&(this.page=this.max)},Page.prototype.reset=function(e){return("local"==this.mode||e)&&(this.page=1),!0},Page.prototype.setMaxPage=function(e){e=parseInt(e),this.max=e||1,this.page>this.max&&(this.page=this.max,this.trigger())},Page.prototype.setPage=function(e){var t=this,a=this;return new Promise(function(i,n){e=parseInt(e),e>0&&e<=t.max?(t.page=e,t.trigger().then(function(){i()}).catch(function(){n()}),a.table.options.persistence&&a.table.modExists("persistence",!0)&&a.table.modules.persistence.config.page&&a.table.modules.persistence.save("page")):(console.warn("Pagination Error - Requested page is out of range of 1 - "+t.max+":",e),n())})},Page.prototype.setPageToRow=function(e){var t=this;return new Promise(function(a,i){var n=t.table.rowManager.getDisplayRows(t.displayIndex-1),s=n.indexOf(e);if(s>-1){var o=Math.ceil((s+1)/t.size);t.setPage(o).then(function(){a()}).catch(function(){i()})}else console.warn("Pagination Error - Requested row is not visible"),i()})},Page.prototype.setPageSize=function(e){e=parseInt(e),e>0&&(this.size=e),this.pageSizeSelect&&this.generatePageSizeSelectList(),this.table.options.persistence&&this.table.modExists("persistence",!0)&&this.table.modules.persistence.config.page&&this.table.modules.persistence.save("page")},Page.prototype._setPageButtons=function(){for(var e=this,t=Math.floor((this.count-1)/2),a=Math.ceil((this.count-1)/2),i=this.max-this.page+t+1<this.count?this.max-this.count+1:Math.max(this.page-t,1),n=this.page<=a?Math.min(this.count,this.max):Math.min(this.page+a,this.max);e.pagesElement.firstChild;)e.pagesElement.removeChild(e.pagesElement.firstChild);1==e.page?(e.firstBut.disabled=!0,e.prevBut.disabled=!0):(e.firstBut.disabled=!1,e.prevBut.disabled=!1),e.page==e.max?(e.lastBut.disabled=!0,e.nextBut.disabled=!0):(e.lastBut.disabled=!1,e.nextBut.disabled=!1);for(var s=i;s<=n;s++)s>0&&s<=e.max&&e.pagesElement.appendChild(e._generatePageButton(s));this.footerRedraw()},Page.prototype._generatePageButton=function(e){var t=this,a=document.createElement("button");return a.classList.add("tabulator-page"),e==t.page&&a.classList.add("active"),a.setAttribute("type","button"),a.setAttribute("role","button"),a.setAttribute("aria-label","Show Page "+e),a.setAttribute("title","Show Page "+e),a.setAttribute("data-page",e),a.textContent=e,a.addEventListener("click",function(a){t.setPage(e)}),a},Page.prototype.previousPage=function(){var e=this;return new Promise(function(t,a){e.page>1?(e.page--,e.trigger().then(function(){t()}).catch(function(){a()})):(console.warn("Pagination Error - Previous page would be less than page 1:",0),a())})},Page.prototype.nextPage=function(){var e=this;return new Promise(function(t,a){e.page<e.max?(e.page++,e.trigger().then(function(){t()}).catch(function(){a()})):(e.progressiveLoad||console.warn("Pagination Error - Next page would be greater than maximum page of "+e.max+":",e.max+1),a())})},Page.prototype.getPage=function(){return this.page},Page.prototype.getPageMax=function(){return this.max},Page.prototype.getPageSize=function(e){return this.size},Page.prototype.getMode=function(){return this.mode},Page.prototype.getRows=function(e){var t,a,i;if("local"==this.mode){t=[],a=this.size*(this.page-1),i=a+parseInt(this.size),this._setPageButtons();for(var n=a;n<i;n++)e[n]&&t.push(e[n]);return t}return this._setPageButtons(),e.slice(0)},Page.prototype.trigger=function(){var e,t=this;return new Promise(function(a,i){switch(t.mode){case"local":e=t.table.rowManager.scrollLeft,t.table.rowManager.refreshActiveData("page"),t.table.rowManager.scrollHorizontal(e),t.table.options.pageLoaded.call(t.table,t.getPage()),a();break;case"remote":case"progressive_load":case"progressive_scroll":t.table.modules.ajax.blockActiveRequest(),t._getRemotePage().then(function(){a()}).catch(function(){i()});break;default:console.warn("Pagination Error - no such pagination mode:",t.mode),i()}})},Page.prototype._getRemotePage=function(){var e,t,a=this,i=this;return new Promise(function(n,s){if(i.table.modExists("ajax",!0)||s(),e=Tabulator.prototype.helpers.deepClone(i.table.modules.ajax.getParams()||{}),t=i.table.modules.ajax.getParams(),t[a.paginationDataSentNames.page]=i.page,a.size&&(t[a.paginationDataSentNames.size]=a.size),a.table.options.ajaxSorting&&a.table.modExists("sort")){var o=i.table.modules.sort.getSort();o.forEach(function(e){delete e.column}),t[a.paginationDataSentNames.sorters]=o}if(a.table.options.ajaxFiltering&&a.table.modExists("filter")){var r=i.table.modules.filter.getFilters(!0,!0);t[a.paginationDataSentNames.filters]=r}i.table.modules.ajax.setParams(t),i.table.modules.ajax.sendRequest(a.progressiveLoad).then(function(e){i._parseRemoteData(e),n()}).catch(function(e){s()}),i.table.modules.ajax.setParams(e)})},Page.prototype._parseRemoteData=function(e){var t,e,a,i=this;if(void 0===e[this.paginationDataReceivedNames.last_page]&&console.warn("Remote Pagination Error - Server response missing '"+this.paginationDataReceivedNames.last_page+"' property"),e[this.paginationDataReceivedNames.data])if(this.max=parseInt(e[this.paginationDataReceivedNames.last_page])||1,this.progressiveLoad)switch(this.mode){case"progressive_load":this.table.rowManager.addRows(e[this.paginationDataReceivedNames.data]),this.page<this.max&&setTimeout(function(){i.nextPage().then(function(){}).catch(function(){})},i.table.options.ajaxProgressiveLoadDelay);break;case"progressive_scroll":e=this.table.rowManager.getData().concat(e[this.paginationDataReceivedNames.data]),this.table.rowManager.setData(e,!0),a=this.table.options.ajaxProgressiveLoadScrollMargin||2*this.table.rowManager.element.clientHeight,i.table.rowManager.element.scrollHeight<=i.table.rowManager.element.clientHeight+a&&i.nextPage().then(function(){}).catch(function(){})}else t=this.table.rowManager.scrollLeft,this.table.rowManager.setData(e[this.paginationDataReceivedNames.data]),this.table.rowManager.scrollHorizontal(t),this.table.columnManager.scrollHorizontal(t),this.table.options.pageLoaded.call(this.table,this.getPage());else console.warn("Remote Pagination Error - Server response missing '"+this.paginationDataReceivedNames.data+"' property")},Page.prototype.footerRedraw=function(){var e=this.table.footerManager.element;Math.ceil(e.clientWidth)-e.scrollWidth<0?this.pagesElement.style.display="none":(this.pagesElement.style.display="",Math.ceil(e.clientWidth)-e.scrollWidth<0&&(this.pagesElement.style.display="none"))},Page.prototype.paginationDataSentNames={page:"page",size:"size",sorters:"sorters",filters:"filters"},Page.prototype.paginationDataReceivedNames={current_page:"current_page",last_page:"last_page",data:"data"},Tabulator.prototype.registerModule("page",Page);