aboutsummaryrefslogtreecommitdiff
path: root/src/main/webapp/apps/core/PagingTableService.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/webapp/apps/core/PagingTableService.js')
-rw-r--r--src/main/webapp/apps/core/PagingTableService.js64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main/webapp/apps/core/PagingTableService.js b/src/main/webapp/apps/core/PagingTableService.js
new file mode 100644
index 0000000..689a225
--- /dev/null
+++ b/src/main/webapp/apps/core/PagingTableService.js
@@ -0,0 +1,64 @@
+function PagingTableService() {
+ var create = function ($scope, fetchCallback) {
+ var self = {
+ rows: [],
+ startIndex: 0,
+ count: 10
+ };
+
+ var update = function(){
+ fetchCallback(self.startIndex, self.count, function(data) {
+ self.rows = data.rows;
+ });
+ };
+
+ self.first = function () {
+ self.startIndex = 0;
+ update();
+ };
+
+ self.next = function () {
+ this.startIndex += this.count;
+ update();
+ };
+
+ self.prev = function () {
+ if (self.startIndex == 0) {
+ return;
+ }
+ self.startIndex -= self.count;
+ update();
+ };
+
+ // Do an initial fetch
+ update();
+
+ return self;
+ };
+
+ var defaultCallback = function(Resource, args) {
+ return function(startIndex, count, cb) {
+ console.log("fetching", arguments);
+ args.startIndex = startIndex;
+ args.count = count;
+ Resource.query(args, function(data, headers) {
+ var totalResults = headers("total-results");
+ console.log("got data", arguments);
+ console.log("totalResults", totalResults);
+ cb({
+ totalResults: totalResults,
+ rows: data
+ });
+ });
+ };
+ };
+
+ return {
+ create: create,
+ defaultCallback: defaultCallback
+ }
+}
+
+angular.
+ module('pagingTableService', ['ngResource']).
+ factory('PagingTableService', PagingTableService);