summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-08-13 18:02:27 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-08-13 18:02:27 -0400
commit46015f1a8482b5f605c8817befad4541f1046dde (patch)
tree251dde5fc1d5d18c22f5d59d94a11d0f69f05f82
parentaac5496a16a65e1206877281ffe8fd81212b0049 (diff)
Move pagination function to controller prototype.
* js/guix-packages.js (guix.paginate): Delete it. (guix.controller): Use new paginate method. (guix.controller.prototype.paginate): New method.
-rw-r--r--js/guix-packages.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/js/guix-packages.js b/js/guix-packages.js
index c9a61ca..3a3518a 100644
--- a/js/guix-packages.js
+++ b/js/guix-packages.js
@@ -31,10 +31,6 @@ guix.chunk = function(array, size) {
}, []);
};
-guix.paginate = function(array, pageSize) {
- return guix.chunk(array, pageSize);
-};
-
guix.Packages = function() {
return m.request({ method: "GET", url: "packages.json" });
};
@@ -50,10 +46,14 @@ guix.controller = function() {
// All packages are visible initially
this.packages.then(function(packages) {
- self.pages(guix.paginate(packages, self.pageSize));
+ self.pages(self.paginate(packages, self.pageSize));
});
};
+guix.controller.prototype.paginate = function(array, pageSize) {
+ return guix.chunk(this.sorter.sort(array), pageSize);
+};
+
guix.controller.prototype.currentPage = function() {
return this.pages()[this.currentPageIndex] || [];
};
@@ -79,7 +79,7 @@ guix.controller.prototype.packageCount = function() {
guix.controller.prototype.doSearch = function() {
var regexp = new RegExp(this.searchTerm(), "i");
- this.pages(guix.paginate(this.packages().filter(function(package) {
+ this.pages(this.paginate(this.packages().filter(function(package) {
return regexp.test(package.name) ||
regexp.test(package.synopsis);
}), this.pageSize));