From 46015f1a8482b5f605c8817befad4541f1046dde Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 13 Aug 2014 18:02:27 -0400 Subject: 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. --- js/guix-packages.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'js/guix-packages.js') 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)); -- cgit v1.2.3