Make Account Center only usable when logged in
[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: "spinner", kind: "OldSchoolSpinner", showing: false}
9     ],
10     addItems: function(items) {
11         if (items.length > 0) {
12             this.$.records.createComponents(items, {kind: this.listKind});
13             for (var i = 0; i < items.length; i++) {
14                 var r = parseInt(items[i].record);
15                 if (r < this.lastRecord || this.lastRecord == null)
16                     this.lastRecord = r;
17             }
18         } else {
19             this.$.records.createComponent({content: "No items"});
20         }
21         this.$.records.render();
22         this.stopLoadAnimation();
23     },
24     loadMore: function() {
25         if (this.lastRecord == 0)
26             return;
27
28         if (this.lastRecord != null) {
29             var to = this.lastRecord - 1;
30             var from = this.lastRecord - 50;
31             if (from < 0)
32                 from = 0;
33             this.loadItems(from, to);
34         } else {
35             this.loadItems();
36         }
37     },
38     loadItems: function(from, to) {
39         this.startLoadAnimation();
40     },
41     startLoadAnimation: function() {
42         this.$.spinner.show();
43         this.$.spinner.start();
44     },
45     stopLoadAnimation: function() {
46         this.$.spinner.hide();
47         this.$.spinner.stop();
48     }
49 });