Add OldSchoolSpinner for loading animation
[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         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         this.stopLoadAnimation();
19     },
20     loadMore: function() {
21         if (this.lastRecord == 0)
22             return;
23
24         if (this.lastRecord != null) {
25             var to = this.lastRecord - 1;
26             var from = this.lastRecord - 50;
27             if (from < 0)
28                 from = 0;
29             this.loadItems(from, to);
30         } else {
31             this.loadItems();
32         }
33     },
34     loadItems: function(from, to) {
35         this.startLoadAnimation();
36     },
37     startLoadAnimation: function() {
38         this.$.spinner.show();
39         this.$.spinner.start();
40     },
41     stopLoadAnimation: function() {
42         this.$.spinner.hide();
43         this.$.spinner.stop();
44     }
45 });