9ae703b07d56c17c2950331c6b0d333d8ddba094
[blerg.git] / www / jssrc / blerg / Pager.js
1 enyo.kind({
2         name: "blerg.Pager",
3         kind: "Control",
4         listKind: "Control",
5         lastRecord: null,
6         components: [
7                 {name: "records"},
8                 {name: "loadMoreButton", kind: "onyx.Button", onclick: "loadMore", content: "Load More"}
9         ],
10         addItems: function(items) {
11                 this.$.records.createComponents(items, {kind: this.listKind});
12                 for (var i = 0; i < items.length; i++) {
13                         var r = parseInt(items[i].record);
14                         if (r < this.lastRecord || this.lastRecord == null)
15                                 this.lastRecord = r;
16                 }
17                 this.$.records.render();
18                 if (this.lastRecord == 0)
19                         this.$.loadMoreButton.hide();
20         },
21         loadMore: function() {
22                 if (this.lastRecord == 0)
23                         return;
24
25                 if (this.lastRecord != null) {
26                         var to = this.lastRecord - 1;
27                         var from = this.lastRecord - 50;
28                         if (from < 0)
29                                 from = 0;
30                         this.loadItems(from, to);
31                 } else {
32                         this.loadItems();
33                 }
34         },
35         loadItems: function(from, to) { }
36 });