From 19ab5ab2b372a924407ce2fbb3cde3830189c84f Mon Sep 17 00:00:00 2001 From: senator Date: Mon, 17 May 2010 21:33:46 +0000 Subject: [PATCH] Acq: back/next result paging through unified search interfaces git-svn-id: svn://svn.open-ils.org/ILS/trunk@16446 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../ui/default/acq/common/li_table_pager.js | 39 ++-- .../js/ui/default/acq/picklist/from_bib.js | 26 ++- .../web/js/ui/default/acq/search/unified.js | 206 ++++++++++-------- .../templates/default/acq/search/unified.tt2 | 1 + 4 files changed, 144 insertions(+), 128 deletions(-) diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table_pager.js b/Open-ILS/web/js/ui/default/acq/common/li_table_pager.js index ba92d94d2b..53d942a51f 100644 --- a/Open-ILS/web/js/ui/default/acq/common/li_table_pager.js +++ b/Open-ILS/web/js/ui/default/acq/common/li_table_pager.js @@ -1,11 +1,11 @@ function LiTablePager() { var self = this; - this.init = function(fetcher, liTable, offset, limit) { - this.fetcher = fetcher; + this.init = function(dataLoader, liTable, offset, limit) { + this.dataLoader = dataLoader; this.liTable = liTable; - this.limit = limit || 10; - this.offset = offset || 0; + this.displayLimit = limit || 15; + this.displayOffset = offset || 0; dojo.byId("acq-litpager-controls-prev").onclick = function() { self.go(-1); } @@ -14,29 +14,26 @@ function LiTablePager() { }; this.go = function(n /* generally (-1, 0, 1) */) { - if (n) this.offset += n * this.limit; + if (n) this.displayOffset += n * this.displayLimit; - this.enableControls(false); - - [this.batch, this.total] = this.fetcher(this.offset, this.limit); - - if (this.batch.length) { - this.liTable.reset(/* keep_selectors */ true); - this.liTable.show("list"); - this.batch.forEach(function(li) { self.liTable.addLineitem(li); }); - } - - this.relabelControls(); + this.show(); + this.dataLoader(this); /* not a normal method, but a callback */ this.enableControls(true); + this.relabelControls(); + }; + + this.show = function() { + this.liTable.reset(/* keep_selectors */ true); + this.liTable.show("list"); }; this.enableControls = function(yes) { dojo.byId("acq-litpager-controls-prev").disabled = - (!yes) || this.offset < 1; + (!yes) || this.displayOffset < 1; dojo.byId("acq-litpager-controls-next").disabled = (!yes) || ( (typeof(this.total) != "undefined") && - this.offset + this.limit >= this.total + this.displayOffset + this.displayLimit >= this.total ); dojo.attr("acq-litpager-controls", "disabled", String(!yes)); } @@ -49,11 +46,11 @@ function LiTablePager() { openils.Util.hide("acq-litpager-controls-total-holder"); } - if (this.batch && this.batch.length) { + if (this.batch_length) { dojo.byId("acq-litpager-controls-batch-start").innerHTML = - this.offset + 1; + this.displayOffset + 1; dojo.byId("acq-litpager-controls-batch-end").innerHTML = - this.offset + this.batch.length; + this.displayOffset + this.batch_length; openils.Util.show("acq-litpager-controls-batch-range", "inline"); } else { openils.Util.hide("acq-litpager-controls-batch-range"); diff --git a/Open-ILS/web/js/ui/default/acq/picklist/from_bib.js b/Open-ILS/web/js/ui/default/acq/picklist/from_bib.js index 64befd5c38..9a4329f3d4 100644 --- a/Open-ILS/web/js/ui/default/acq/picklist/from_bib.js +++ b/Open-ILS/web/js/ui/default/acq/picklist/from_bib.js @@ -6,18 +6,20 @@ var liTable = null; var pager = null; var usingPl = null; -function fetchRecords(offset, limit) { +function fetchRecords() { var data = termLoader.attr("value"); - var results = []; - var total = data.length; - if (offset < 0 || offset >= data.length) return [results, total]; + var result_count = 0; + pager.total = data.length; progressDialog.show(true); - /* notice this call is synchronous */ fieldmapper.standardRequest( ["open-ils.acq", "open-ils.acq.biblio.create_by_id"], { "params": [ - openils.User.authtoken, data.slice(offset, offset + limit), { + openils.User.authtoken, + data.slice( + pager.displayOffset, + pager.displayOffset + pager.displayLimit + ), { "flesh_attrs": true, "flesh_cancel_reason": true, "flesh_notes": true, @@ -26,11 +28,13 @@ function fetchRecords(offset, limit) { ], "onresponse": function(r) { if (r = openils.Util.readResponse(r)) { - if (typeof(r) != "object") + if (typeof(r) != "object") { usingPl = r; - else if (r.classname && r.classname == "jub") - results.push(r); - /* XXX the ML method is buggy and sometimes responds with + } else if (r.classname && r.classname == "jub") { + result_count++; + liTable.addLineitem(r); + } + /* The ML method is buggy and sometimes responds with * more objects that we don't want, hence the specific * conditionals above that don't necesarily consume all * responses. */ @@ -38,8 +42,8 @@ function fetchRecords(offset, limit) { } } ); + pager.batch_length = result_count; progressDialog.hide(); - return [results, total]; } function beginSearch() { diff --git a/Open-ILS/web/js/ui/default/acq/search/unified.js b/Open-ILS/web/js/ui/default/acq/search/unified.js index e319504d09..f5769392ea 100644 --- a/Open-ILS/web/js/ui/default/acq/search/unified.js +++ b/Open-ILS/web/js/ui/default/acq/search/unified.js @@ -568,11 +568,11 @@ function TermManager() { * layer, and it chooses which ML method to call as well as what widgets to use * to display the results. */ -function ResultManager(liTable, poGrid, plGrid, invGrid) { +function ResultManager(liPager, poGrid, plGrid, invGrid) { var self = this; - this.liTable = liTable; - this.liTable.isUni = true; + this.liPager = liPager; + this.liPager.liTable.isUni = true; this.poGrid = poGrid; this.plGrid = plGrid; @@ -589,9 +589,19 @@ function ResultManager(liTable, poGrid, plGrid, invGrid) { "flesh_notes": true }, "revealer": function() { - self.liTable.reset(); - self.liTable.show("list"); - } + self.liPager.show(); + progressDialog.show(true); + }, + "finisher": function() { + self.liPager.batch_length = self.count_results; + self.liPager.relabelControls(); + self.liPager.enableControls(true); + progressDialog.hide(); + }, + "adder": function(li) { + self.liPager.liTable.addLineitem(li); + }, + "interface": self.liPager }, "purchase_order": { "search_options": { @@ -599,8 +609,17 @@ function ResultManager(liTable, poGrid, plGrid, invGrid) { }, "revealer": function() { self.poGrid.resetStore(); + self.poGrid.showLoadProgressIndicator(); self.poCache = {}; - } + }, + "finisher": function() { + self.poGrid.hideLoadProgressIndicator(); + }, + "adder": function(po) { + self.poCache[po.id()] = po; + self.poGrid.store.newItem(acqpo.toStoreItem(po)); + }, + "interface": self.poGrid }, "picklist": { "search_options": { @@ -609,62 +628,71 @@ function ResultManager(liTable, poGrid, plGrid, invGrid) { }, "revealer": function() { self.plGrid.resetStore(); + self.plGrid.showLoadProgressIndicator(); self.plCache = {}; - } + }, + "finisher": function() { + self.plGrid.hideLoadProgressIndicator(); + }, + "adder": function(pl) { + self.plCache[pl.id()] = pl; + self.plGrid.store.newItem(acqpl.toStoreItem(pl)); + }, + "interface": self.plGrid }, "invoice": { "search_options": { "no_flesh_misc": true }, + "finisher": function() { + self.invGrid.hideLoadProgressIndicator(); + }, "revealer": function() { self.invGrid.resetStore(); self.invCache = {}; - } + }, + "adder": function(inv) { + self.invCache[inv.id()] = inv; + self.invGrid.store.newItem(acqinv.toStoreItem(inv)); + }, + "interface": self.invGrid }, "no_results": { "revealer": function() { alert(localeStrings.NO_RESULTS); } } }; - this._add_lineitem = function(li) { - this.liTable.addLineitem(li); - }; - - this._add_purchase_order = function(po) { - this.poCache[po.id()] = po; - this.poGrid.store.newItem(acqpo.toStoreItem(po)); - }; - - this._add_picklist = function(pl) { - this.plCache[pl.id()] = pl; - this.plGrid.store.newItem(acqpl.toStoreItem(pl)); - }; - - this._add_invoice = function(inv) { - this.invCache[inv.id()] = inv; - this.invGrid.store.newItem(acqinv.toStoreItem(inv)); - }; - - this._finish_purchase_order = function() { - this.poGrid.hideLoadProgressIndicator(); - }; - - this._finish_picklist = function() { - this.plGrid.hideLoadProgressIndicator(); - }; + this._dataLoader = function() { + /* This function must contain references to "self" only, not "this." */ + var grid = self.result_types[self.result_type].interface; + self.count_results = 0; + self.params[4].offset = grid.displayOffset; + self.params[4].limit = grid.displayLimit; - this._finish_invoice = function() { - this.invGrid.hideLoadProgressIndicator(); + fieldmapper.standardRequest( + ["open-ils.acq", self.method_name], { + "params": self.params, + "async": true, + "onresponse": function(r) { + if (r = openils.Util.readResponse(r)) { + if (!self.count_results++) + self.show(self.result_type); + self.add(self.result_type, r); + } + }, + "oncomplete": function() { self.resultsComplete(); } + } + ); }; this.add = function(which, what) { - var name = "_add_" + which; - if (this[name]) this[name](what); + var f = this.result_types[which].adder; + if (f) f(what); }; this.finish = function(which) { - var name = "_finish_" + which; - if (this[name]) this[name](); + var f = this.result_types[which].finisher; + if (f) f(); }; this.show = function(which) { @@ -678,6 +706,12 @@ function ResultManager(liTable, poGrid, plGrid, invGrid) { this.result_types[which].revealer(); }; + this.resultsComplete = function() { + if (!this.count_results) + this.show("no_results"); + else this.finish(this.result_type); + }; + this.go = function(search_object) { location.href = oilsBasePath + "/acq/search/unified?" + "so=" + base64Encode(search_object) + @@ -686,76 +720,56 @@ function ResultManager(liTable, poGrid, plGrid, invGrid) { }; this.search = function(search_object, termManager) { - var count_results = 0; var bib_search_string = null; - var result_type = dojo.byId("acq-unified-result-type").getValue(); - var conjunction = dojo.byId("acq-unified-conjunction").getValue(); + this.count_results = 0; + this.result_type = dojo.byId("acq-unified-result-type").getValue(); /* lineitem_and_bib: a special case */ - if (result_type == "lineitem_and_bib") { - result_type = "lineitem"; + if (this.result_type == "lineitem_and_bib") { + this.result_type = "lineitem"; bib_search_string = termManager.buildBibSearchString(); } - function result_completion() { - if (!count_results) self.show("no_results"); - else self.finish(result_type); - } - - var method_name = "open-ils.acq." + result_type + ".unified_search"; + this.method_name = "open-ils.acq." + this.result_type + + ".unified_search"; /* Except for building the API method name that we want to call, * we want to treat lineitem_and_bib the same way as lineitem from * here forward. */ - var params = [ + this.params = [ openils.User.authtoken, null, null, null, - this.result_types[result_type].search_options + this.result_types[this.result_type].search_options ]; - params[conjunction == "and" ? 1 : 2] = search_object; - - fieldmapper.standardRequest( - ["open-ils.acq", method_name], { - "params": params, - "async": true, - "onresponse": function(r) { - if (r = openils.Util.readResponse(r)) { - if (!count_results++) - self.show(result_type); - self.add(result_type, r); - } - }, - "oncomplete": function() { - if (bib_search_string) { - fieldmapper.standardRequest( - ["open-ils.acq", - "open-ils.acq.biblio.wrapped_search"], { - "params": [ - openils.User.authtoken, - bib_search_string, - self.result_types.lineitem.search_options - ], - "async": true, - "onresponse": function(r) { - if (r = openils.Util.readResponse(r)) { - if (!count_results++) - self.show("lineitem"); - self.add("lineitem", r); - } - }, - "oncomplete": function() { - result_completion(); - } - } - ); - } else { - result_completion(); + this.params[ + dojo.byId("acq-unified-conjunction").getValue() == "and" ? 1 : 2 + ] = search_object; + + var interface = this.result_types[this.result_type].interface; + interface.dataLoader = this._dataLoader; + + if (bib_search_string) { + /* Have the ML do the bib search first, which incidentally has the + * side effect of creating line items that will show up when + * we do the LI part of the search (so we don't actually want + * to display these results directly). */ + fieldmapper.standardRequest( + ["open-ils.acq", "open-ils.acq.biblio.wrapped_search.atomic"], { + "params": [ + openils.User.authtoken, bib_search_string, { + "clear_marc": true + } + ], + "onresponse": function(r) { + r = openils.Util.readResponse(r, false, true); } } - } - ); - } + ); + } + + interface.dataLoader(); + }; } function URIManager() { @@ -781,7 +795,7 @@ openils.Util.addOnLoad( function() { termManager = new TermManager(); resultManager = new ResultManager( - new AcqLiTable(), + new LiTablePager(null, new AcqLiTable()), dijit.byId("acq-unified-po-grid"), dijit.byId("acq-unified-pl-grid"), dijit.byId("acq-unified-inv-grid") diff --git a/Open-ILS/web/templates/default/acq/search/unified.tt2 b/Open-ILS/web/templates/default/acq/search/unified.tt2 index 69c99d44a4..5fc454e660 100644 --- a/Open-ILS/web/templates/default/acq/search/unified.tt2 +++ b/Open-ILS/web/templates/default/acq/search/unified.tt2 @@ -252,6 +252,7 @@ There are no results from your search. -- 2.43.2