]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/common/li_table_pager.js
Really add *entire* selection list to a purchase order, when desired,
[Evergreen.git] / Open-ILS / web / 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.liTable.isUni = true;
8         this.liTable.pager = this;  /* XXX memory leak waiting to happen? */
9
10         this.displayLimit = limit || 15;
11         this.displayOffset = offset || 0;
12
13         dojo.byId("acq-litpager-controls-prev").onclick =
14             function() { self.go(-1); }
15         dojo.byId("acq-litpager-controls-next").onclick =
16             function() { self.go(1); }
17     };
18
19     this.go = function(n /* generally (-1, 0, 1) */) {
20         if (n) this.displayOffset += n * this.displayLimit;
21
22         this.show();
23         this.dataLoader(this); /* not a normal method, but a callback */
24         this.enableControls(true);
25         this.relabelControls();
26     };
27
28     this.show = function() {
29         this.liTable.reset(/* keep_selectors */ true);
30         this.liTable.show("list");
31     };
32
33     this.enableControls = function(yes) {
34         dojo.byId("acq-litpager-controls-prev").disabled =
35             (!yes) || this.displayOffset < 1;
36         dojo.byId("acq-litpager-controls-next").disabled =
37             (!yes) || (
38                 (typeof(this.total) != "undefined") &&
39                     this.displayOffset + this.displayLimit >= this.total
40             );
41         dojo.attr("acq-litpager-controls", "disabled", String(!yes));
42     }
43
44     this.relabelControls = function() {
45         if (typeof(this.total) != "undefined") {
46             dojo.byId("acq-litpager-controls-total").innerHTML = this.total;
47             openils.Util.show("acq-litpager-controls-total-holder", "inline");
48         } else {
49             openils.Util.hide("acq-litpager-controls-total-holder");
50         }
51
52         if (this.batch_length) {
53             dojo.byId("acq-litpager-controls-batch-start").innerHTML =
54                 this.displayOffset + 1;
55             dojo.byId("acq-litpager-controls-batch-end").innerHTML =
56                 this.displayOffset + this.batch_length;
57             openils.Util.show("acq-litpager-controls-batch-range", "inline");
58         } else {
59             openils.Util.hide("acq-litpager-controls-batch-range");
60         }
61     };
62
63     this.getAllLineitemIDs = function(callback) {
64         this.dataLoader({
65             "id_list": true,
66             "atomic": true,
67             "skip_paging": true,
68             "onresponse": null,
69             "oncomplete": callback
70         });
71     };
72
73     this.init.apply(this, arguments);
74 }