From b36da4a84d0742c0fce7d0f4891f078aa230079e Mon Sep 17 00:00:00 2001 From: Jason Skomorowski Date: Tue, 5 Aug 2014 11:58:57 -0400 Subject: [PATCH] Template for Pager --- src/mkws-widget-main.js | 91 ++++++++++------------- src/mkws-widget-main.templates/Pager.handlebars | 46 ++++++++++++ 2 files changed, 84 insertions(+), 53 deletions(-) create mode 100644 src/mkws-widget-main.templates/Pager.handlebars diff --git a/src/mkws-widget-main.js b/src/mkws-widget-main.js index 91c2d93..35cfb16 100644 --- a/src/mkws-widget-main.js +++ b/src/mkws-widget-main.js @@ -11,7 +11,9 @@ mkws.registerWidgetType('Targets', function() { this.node.css("display", "none"); this.team.queue("targets").subscribe(function(data) { - // There is a bug in pz2.js + // There is a bug in pz2.js wherein it makes each data object an array but + // simply assigns properties to it. + // TODO: remove this when PAZ-946 is addressed. var cleandata = []; for (var i = 0; i < data.length; i++) { var cur = {}; @@ -43,61 +45,44 @@ mkws.registerWidgetType('Pager', function() { var M = mkws.M; this.team.queue("pager").subscribe(function(data) { - that.node.html(drawPager(data)) - - function drawPager(data) { - var teamName = that.team.name(); - var s = '
' + M('Displaying') + ': ' - + (data.start + 1) + ' ' + M('to') + ' ' + (data.start + data.num) + - ' ' + M('of') + ' ' + data.merged + ' (' + M('found') + ': ' - + data.total + ')
'; - - //client indexes pages from 1 but pz2 from 0 - var onsides = 6; - var pages = Math.ceil(that.team.totalRecordCount() / that.team.perpage()); - var currentPage = that.team.currentPage(); - - var firstClkbl = (currentPage - onsides > 0) - ? currentPage - onsides - : 1; - - var lastClkbl = firstClkbl + 2*onsides < pages - ? firstClkbl + 2*onsides - : pages; - - var prev = '<< ' + M('Prev') + ' | '; - if (currentPage > 1) - prev = '' - +'<< ' + M('Prev') + ' | '; - - var middle = ''; - for(var i = firstClkbl; i <= lastClkbl; i++) { - var numLabel = i; - if(i == currentPage) - numLabel = '' + i + ''; - - middle += ' ' - + numLabel + ' '; + var teamName = that.team.name(); + var output = {}; + output.first = data.start + 1; + output.last = data.start + data.num; + output.count = data.merged; + output.found = data.total; + + //client indexes pages from 1 but pz2 from 0 + var onsides = 6; + var pages = Math.ceil(that.team.totalRecordCount() / that.team.perpage()); + var currentPage = that.team.currentPage(); + + var firstClkbl = (currentPage - onsides > 0) + ? currentPage - onsides + : 1; + var lastClkbl = firstClkbl + 2*onsides < pages + ? firstClkbl + 2*onsides + : pages; + + if (firstClkbl > 1) output.morePrev = true; + if (lastClkbl < pages) output.moreNext = true; + + if (currentPage > 1) output.prevClick = "mkws.pagerPrev(\'" + teamName + "\');"; + + output.pages = []; + for(var i = firstClkbl; i <= lastClkbl; i++) { + var o = {}; + o.number = i; + if (i !== currentPage) { + o.click = "mkws.showPage(\'" + teamName + "\', " + i + ");"; } + output.pages.push(o); + } - var next = ' | ' + M('Next') + ' >>'; - if (pages - currentPage > 0) - next = ' | ' - + M('Next') + ' >>'; - - var predots = ''; - if (firstClkbl > 1) - predots = '...'; - - var postdots = ''; - if (lastClkbl < pages) - postdots = '...'; - - s += '
' - + prev + predots + middle + postdots + next + '
'; + if (pages - currentPage > 0) output.nextClick = "mkws.pagerNext(\'" + teamName + "\')"; - return s; - } + var template = that.team.loadTemplate(that.config.template || "Pager"); + that.node.html(template(output)); }); }); diff --git a/src/mkws-widget-main.templates/Pager.handlebars b/src/mkws-widget-main.templates/Pager.handlebars new file mode 100644 index 0000000..18ce332 --- /dev/null +++ b/src/mkws-widget-main.templates/Pager.handlebars @@ -0,0 +1,46 @@ +{{! +Pager + +nextClick - handler script for "next" button, only available if there is a next page +prevClick - handler script for "previous" button if there is a previous page +moreNext - indicates there are more pages following those displayed +morePrev - indicates there are more pages preceding +first - first record displayed +last - last record displayed +count - number of records available +found - number of records found +pages: + number - page number + click - script to go to this page unless it is the current one +}} +
+ {{mkws-translate "Displaying"}}: + {{first}} {{mkws-translate "to"}} {{last}} + {{mkws-translate "of"}} {{count}} (found: {{found}}) +
+ +
+ {{#if prevClick}} + << {{mkws-translate "Prev"}} | + {{else}} + << {{mkws-translate "Prev"}} | + {{/if}} + + {{#if morePrev}}...{{/if}} + + {{#each pages}} + {{#if click}} + {{number}} + {{else}} + {{number}} + {{/if}} + {{/each}} + + {{#if moreNext}}...{{/if}} + + {{#if nextClick}} + | {{mkws-translate "Next"}} >> + {{else}} + | {{mkws-translate "Next"}} >> + {{/if}} +
-- 1.7.10.4