From 27d74ce4423d2ec48a9289169c97958526fed77b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 13 Jan 2013 10:14:27 +0100 Subject: o Adding PagingTableService.showNext()/nextDisabled() for better look when searching. --- .../webapp/apps/core/PagingTableService.js | 41 ++++++++++++++++++---- .../webapp/apps/frontPageApp/personList.html | 4 +-- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/main/resources/webapp/apps/core/PagingTableService.js b/src/main/resources/webapp/apps/core/PagingTableService.js index f550a39..f38b6f1 100755 --- a/src/main/resources/webapp/apps/core/PagingTableService.js +++ b/src/main/resources/webapp/apps/core/PagingTableService.js @@ -6,13 +6,16 @@ function PagingTableService() { rows: [], query: "", startIndex: options.startIndex || 0, - count: options.count || 10 + count: options.count || 10, + currentlySearching: false }; var update = function(){ + self.currentlySearching = true; fetchCallback(self.startIndex, self.count, self.query, function(data) { self.rows = data.rows; watcher(); + self.currentlySearching = false; }); }; @@ -22,11 +25,17 @@ function PagingTableService() { }; self.next = function () { + if (self.currentlySearching) { + return; + } self.startIndex += self.count; update(); }; self.prev = function () { + if (self.currentlySearching) { + return; + } if (self.startIndex == 0) { return; } @@ -34,16 +43,35 @@ function PagingTableService() { update(); }; + /* + * The search functions needs to know if there already is a search in progress and if so, do not send the search + * before the previous one completes. + */ + self.onSearch = function () { - console.log("search: " + self.query); update(); }; self.onSearchChange = function () { - console.log("search: " + self.query); update(); }; + self.showPrev = function () { + return self.startIndex > 0; + }; + + self.showNext = function () { + return true; + }; + + self.nextDisabled = function () { + return self.currentlySearching; + }; + + self.prevDisabled = function () { + return self.currentlySearching; + }; + // Do an initial fetch update(); @@ -53,7 +81,7 @@ function PagingTableService() { var defaultCallback = function(Resource, args) { args = args || {}; return function(startIndex, count, query, cb) { - if(startIndex) { + if(startIndex || startIndex == 0) { args.startIndex = startIndex; } if(count) { @@ -62,11 +90,10 @@ function PagingTableService() { if(query) { args.query = query; } - console.log("fetching", args); + console.log("Fetching page. args =", args); Resource.query(args, function(data, headers) { var totalResults = headers("total-results"); - console.log("totalResults", totalResults); - console.log("got data", data); + console.log("Total results =", totalResults, "Data =", data); cb({ totalResults: totalResults, rows: data diff --git a/src/main/resources/webapp/apps/frontPageApp/personList.html b/src/main/resources/webapp/apps/frontPageApp/personList.html index 41f2f63..2c14b01 100755 --- a/src/main/resources/webapp/apps/frontPageApp/personList.html +++ b/src/main/resources/webapp/apps/frontPageApp/personList.html @@ -46,10 +46,10 @@ -- cgit v1.2.3