summaryrefslogtreecommitdiff
path: root/js/view
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-10-16 22:20:04 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-10-16 22:20:04 -0400
commit8ced57e86f518cecea4fa5c6499ad33459823b77 (patch)
tree333082b73c768c6e1854f613070dc32649bcc8b3 /js/view
parent93921cef3d2e76b53789140fad7153c025a7c340 (diff)
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.
Diffstat (limited to 'js/view')
-rw-r--r--js/view/packages.js26
1 files changed, 12 insertions, 14 deletions
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
// <http://www.gnu.org/licenses/>.
-(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);
+})();