From 8ced57e86f518cecea4fa5c6499ad33459823b77 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 16 Oct 2014 22:20:04 -0400 Subject: js: Extract pagination model. * js/utils.js (guix.clamp): New function. * js/controller/packages.js (guix.packages.controller): Remove 'pages', 'currentPageIndex', and 'pageSize' properties. Add 'pager' prop. Delete 'paginate', 'currentPage', 'isFirstPage', 'isLastPage', and 'isCurrentPage' methods. * js/model/packages.js (guix.packages.Pager): New function. * js/view/packages.js (guix.packages.view): Use new Pager API. --- js/view/packages.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'js/view') diff --git a/js/view/packages.js b/js/view/packages.js index e202471..7c55486 100644 --- a/js/view/packages.js +++ b/js/view/packages.js @@ -15,7 +15,8 @@ // License along with this program. If not, see // . -(function(packages) { +(function() { + var packages = guix.packages; var spinner = m(".spinner-container", m(".spinner")); packages.view = function(ctrl) { @@ -75,7 +76,7 @@ ]) ]), m("tbody", [ - ctrl.currentPage().map(function(package) { + ctrl.pager().currentPage().map(function(package) { return m("tr", [ m("td", renderName(package)), m("td", package.version), @@ -100,30 +101,27 @@ return m("div", m("ul.pagination", [ // Back page renderPage("«", { - class: ctrl.isFirstPage() ? "disabled" : "", + class: ctrl.pager().isFirstPage() ? "disabled" : "", onclick: function() { - ctrl.currentPageIndex--; - + ctrl.pager().previousPage(); return false; } }) - ].concat(ctrl.pages().map(function(page, i) { + ].concat(ctrl.pager().pages.map(function(page, i) { // Jump to page return renderPage(i + 1, { - class: ctrl.isCurrentPage(i) ? "active" : "", + class: ctrl.pager().isCurrentPage(i) ? "active" : "", onclick: function() { - ctrl.currentPageIndex = i; - + ctrl.pager().gotoPage(i); return false; } }); })).concat([ // Forward page renderPage("»", { - class: ctrl.isLastPage() ? "disabled" : "", + class: ctrl.pager().isLastPage() ? "disabled" : "", onclick: function() { - ctrl.currentPageIndex++; - + ctrl.pager().nextPage(); return false; } }) @@ -239,7 +237,7 @@ return null; } - return guix.withLayout(_.isEmpty(ctrl.pages()) ? spinner : [ + return guix.withLayout(ctrl.pager().isEmpty() ? spinner : [ m("h2", [ "Packages", m("span.badge", ctrl.packageCount()) @@ -250,4 +248,4 @@ renderPagination() ]); }; -})(guix.packages); +})(); -- cgit v1.2.3