/* * Admin - Results paging. */ (function (win, doc, undef) { "use strict"; let rp = sax.resultsPaging = sax.resultsPaging || { fn: {}, msg: {}, contexts: [] }; //-------------------------------------------------------------- rp.fn.refreshPaging = function (paging, contextSel, refreshFn) { let context = rp.fn.getContext(contextSel, refreshFn); rp.fn.init(context); context.paging = paging = paging || {}; context.$rp.toggle(paging.paged); context.$pageNo.val(paging.pageNo); context.$pageLen.val(paging.pageLength); $('.sax-paging-info', context.$rp).text(sax.resultsPaging.msg.pageInfo.format(paging.pageNo, paging.pageCount)); //$('.sax-paging-first,.sax-paging-prev', context.$rp).toggle(paging.pageNo > 1); //$('.sax-paging-next,.sax-paging-last', context.$rp).toggle(paging.pageNo < paging.pageCount); } //-------------------------------------------------------------- rp.fn.getContext = function (contextSel, refreshFn) { for (let idx = 0; idx < rp.contexts.length; idx++) { if (rp.contexts[idx].sel == contextSel) return rp.contexts[idx]; } //sax.debug('getContext Creating new context for: ', contextSel); let context = { sel: contextSel, refreshFn: refreshFn } rp.contexts.push(context); return context; } //-------------------------------------------------------------- rp.fn.firstPage = function (context) { let page = context.$pageNo.val() * 1; if (page < 2) return; context.$pageNo.val(1); context.refreshFn(); } rp.fn.prevPage = function (context) { let page = context.$pageNo.val() * 1; if (page < 2) return; context.$pageNo.val(page - 1); context.refreshFn(); } rp.fn.nextPage = function (context) { let page = context.$pageNo.val() * 1; if (page > context.paging.pageCount - 1) return; context.$pageNo.val(page + 1); context.refreshFn(); } rp.fn.lastPage = function (context) { let page = context.$pageNo.val() * 1; if (page > context.paging.pageCount - 1) return; context.$pageNo.val(context.paging.pageCount); context.refreshFn(); } //-------------------------------------------------------------- rp.fn.init = function (context) { if (context.$rp) return; //sax.debug('resultsPaging.init Initialising Paging.', context); context.$rp = $('.sax-results-paging', $(context.sel)); context.$pageNo = $('.PagingPageNo', context.$rp); context.$pageLen = $('.PagingPageLength', context.$rp); $('.sax-paging-first', context.$rp).off('click').on('click', function () { rp.fn.firstPage(context); }); $('.sax-paging-prev', context.$rp).off('click').on('click', function () { rp.fn.prevPage(context); }); $('.sax-paging-next', context.$rp).off('click').on('click', function () { rp.fn.nextPage(context); }); $('.sax-paging-last', context.$rp).off('click').on('click', function () { rp.fn.lastPage(context); }); } }(window, window.document)); /* The End */