mirror of
https://github.com/openMF/community-app.git
synced 2026-02-06 09:37:29 +00:00
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
(function(module) {
|
|
mifosX.services = _.extend(module, {
|
|
PaginatorService: function(scope, httpService) {
|
|
|
|
this.paginate = function(fetchFunction, pageSize) {
|
|
var paginator = {
|
|
hasNextVar: false,
|
|
next: function() {
|
|
if (this.hasNextVar) {
|
|
this.currentOffset += pageSize;
|
|
this._load();
|
|
}
|
|
},
|
|
_load: function() {
|
|
var self = this;
|
|
fetchFunction(this.currentOffset, pageSize + 1, function(items) {
|
|
self.currentPageItems = items.pageItems;
|
|
self.hasNextVar = items.pageItems.length === pageSize + 1;;
|
|
});
|
|
},
|
|
hasNext: function() {
|
|
return this.hasNextVar;
|
|
},
|
|
previous: function() {
|
|
if(this.hasPrevious()) {
|
|
this.currentOffset -= pageSize;
|
|
this._load();
|
|
}
|
|
},
|
|
hasPrevious: function() {
|
|
return this.currentOffset !== 0;
|
|
},
|
|
currentPageItems: [],
|
|
currentOffset: 0
|
|
};
|
|
// Load the first page
|
|
paginator._load();
|
|
return paginator;
|
|
};
|
|
|
|
}
|
|
});
|
|
mifosX.ng.services.service('PaginatorService', ['$rootScope', 'HttpService', mifosX.services.PaginatorService]).run(function($log) {
|
|
$log.info("PaginatorService initialized");
|
|
});
|
|
}(mifosX.services || {}));
|