diff options
-rwxr-xr-x | src/main/resources/webapp/apps/core/PagingTableService.js | 41 | ||||
-rwxr-xr-x | src/main/resources/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 @@ </div> </div> <ul class="pager"> - <li class="previous" ng-show="persons.startIndex > 0"> + <li ng-show="persons.showPrev()" class="previous {{{true: 'disabled', false: ''}[persons.prevDisabled()]}}"> <a ng-click="persons.prev()">← Prev</a> </li> - <li class="next"> + <li ng-show="persons.showNext()" class="next {{{true: 'disabled', false: ''}[persons.nextDisabled()]}}"> <a ng-click="persons.next()">Next →</a> </li> </ul> |