Initial dev repository
[kcls-web.git] / js / ui / default / acq / common / li_table_pager.js
1 function LiTablePager() {
2     var self = this;
3
4     this.init = function(dataLoader, liTable, offset, limit) {
5         this.dataLoader = dataLoader;
6         this.liTable = liTable;
7         this.displayLimit = limit || 15;
8         this.displayOffset = offset || 0;
9
10         dojo.byId("acq-litpager-controls-prev").onclick =
11             function() { self.go(-1); }
12         dojo.byId("acq-litpager-controls-next").onclick =
13             function() { self.go(1); }
14     };
15
16     this.go = function(n /* generally (-1, 0, 1) */) {
17         if (n) this.displayOffset += n * this.displayLimit;
18
19         this.show();
20         this.dataLoader(this); /* not a normal method, but a callback */
21         this.enableControls(true);
22         this.relabelControls();
23     };
24
25     this.show = function() {
26         this.liTable.reset(/* keep_selectors */ true);
27         this.liTable.show("list");
28     };
29
30     this.enableControls = function(yes) {
31         dojo.byId("acq-litpager-controls-prev").disabled =
32             (!yes) || this.displayOffset < 1;
33         dojo.byId("acq-litpager-controls-next").disabled =
34             (!yes) || (
35                 (typeof(this.total) != "undefined") &&
36                     this.displayOffset + this.displayLimit >= this.total
37             );
38         dojo.attr("acq-litpager-controls", "disabled", String(!yes));
39     }
40
41     this.relabelControls = function() {
42         if (typeof(this.total) != "undefined") {
43             dojo.byId("acq-litpager-controls-total").innerHTML = this.total;
44             openils.Util.show("acq-litpager-controls-total-holder", "inline");
45         } else {
46             openils.Util.hide("acq-litpager-controls-total-holder");
47         }
48
49         if (this.batch_length) {
50             dojo.byId("acq-litpager-controls-batch-start").innerHTML =
51                 this.displayOffset + 1;
52             dojo.byId("acq-litpager-controls-batch-end").innerHTML =
53                 this.displayOffset + this.batch_length;
54             openils.Util.show("acq-litpager-controls-batch-range", "inline");
55         } else {
56             openils.Util.hide("acq-litpager-controls-batch-range");
57         }
58     };
59
60     this.init.apply(this, arguments);
61 }