1 function LiTablePager() {
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? */
10 this.displayLimit = limit || 15;
11 this.displayOffset = offset || 0;
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); }
19 this.go = function(n /* generally (-1, 0, 1) */) {
20 if (n) this.displayOffset += n * this.displayLimit;
23 this.dataLoader(this); /* not a normal method, but a callback */
24 this.enableControls(true);
25 this.relabelControls();
28 this.show = function() {
30 this.liTable.show("list");
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 =
38 (typeof(this.total) != "undefined") &&
39 this.displayOffset + this.displayLimit >= this.total
41 dojo.attr("acq-litpager-controls", "disabled", String(!yes));
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");
49 openils.Util.hide("acq-litpager-controls-total-holder");
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");
59 openils.Util.hide("acq-litpager-controls-batch-range");
63 this.focusLi = function() {
64 var liId = this.liTable.focusLineitem;
65 if (liId && this.liTable.liCache[liId] && dojo.byId('li-title-ref-' + liId))
66 this.liTable.focusLi();
69 /* given a lineitem to focus, this will determine what page in
70 * the results set the lineitem sits, then fetch that page
71 * of results. Returns false if no focus requested.
73 this.loadFocusLi = function() {
74 var liId = this.liTable.focusLineitem;
75 if (!liId) return false;
78 this.getAllLineitemIDs(
80 var allIds = openils.Util.readResponse(r);
81 var idx = dojo.indexOf(allIds, liId);
82 // if li not found, result is loading page 1
85 while ( idx >= (page * _this.displayLimit) ) {
89 _this.displayOffset = (_this.displayLimit * (page - 1));
97 this.getAllLineitemIDs = function(callback) {
103 "oncomplete": callback
107 this.init.apply(this, arguments);