[open-ils-commits] r16446 - in trunk/Open-ILS/web: js/ui/default/acq/common js/ui/default/acq/picklist js/ui/default/acq/search templates/default/acq/search (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon May 17 17:33:52 EDT 2010


Author: senator
Date: 2010-05-17 17:33:46 -0400 (Mon, 17 May 2010)
New Revision: 16446

Modified:
   trunk/Open-ILS/web/js/ui/default/acq/common/li_table_pager.js
   trunk/Open-ILS/web/js/ui/default/acq/picklist/from_bib.js
   trunk/Open-ILS/web/js/ui/default/acq/search/unified.js
   trunk/Open-ILS/web/templates/default/acq/search/unified.tt2
Log:
Acq: back/next result paging through unified search interfaces


Modified: trunk/Open-ILS/web/js/ui/default/acq/common/li_table_pager.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/common/li_table_pager.js	2010-05-17 20:50:52 UTC (rev 16445)
+++ trunk/Open-ILS/web/js/ui/default/acq/common/li_table_pager.js	2010-05-17 21:33:46 UTC (rev 16446)
@@ -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 @@
     };
 
     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 @@
             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");

Modified: trunk/Open-ILS/web/js/ui/default/acq/picklist/from_bib.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/picklist/from_bib.js	2010-05-17 20:50:52 UTC (rev 16445)
+++ trunk/Open-ILS/web/js/ui/default/acq/picklist/from_bib.js	2010-05-17 21:33:46 UTC (rev 16446)
@@ -6,18 +6,20 @@
 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 @@
             ],
             "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 @@
             }
         }
     );
+    pager.batch_length = result_count;
     progressDialog.hide();
-    return [results, total];
 }
 
 function beginSearch() {

Modified: trunk/Open-ILS/web/js/ui/default/acq/search/unified.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/search/unified.js	2010-05-17 20:50:52 UTC (rev 16445)
+++ trunk/Open-ILS/web/js/ui/default/acq/search/unified.js	2010-05-17 21:33:46 UTC (rev 16446)
@@ -568,11 +568,11 @@
  * 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 @@
                 "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 @@
             },
             "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 @@
             },
             "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._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._add_purchase_order = function(po) {
-        this.poCache[po.id()] = po;
-        this.poGrid.store.newItem(acqpo.toStoreItem(po));
+        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_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._finish_invoice = function() {
-        this.invGrid.hideLoadProgressIndicator();
-    };
-
     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 @@
         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 @@
     };
 
     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;
+        this.params[
+            dojo.byId("acq-unified-conjunction").getValue() == "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);
+        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);
                     }
-                },
-                "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();
-                    }
                 }
-            }
-        );
-    }
+            );
+        }
+
+        interface.dataLoader();
+    };
 }
 
 function URIManager() {
@@ -781,7 +795,7 @@
     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")

Modified: trunk/Open-ILS/web/templates/default/acq/search/unified.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/acq/search/unified.tt2	2010-05-17 20:50:52 UTC (rev 16445)
+++ trunk/Open-ILS/web/templates/default/acq/search/unified.tt2	2010-05-17 21:33:46 UTC (rev 16446)
@@ -252,6 +252,7 @@
         There are no results from your search.
     </div>
     <div id="acq-unified-results-lineitem" class="hidden">
+        [% INCLUDE "default/acq/common/li_table_pager.tt2" %]
         [% INCLUDE "default/acq/common/li_table.tt2" %]
     </div>
 </div>



More information about the open-ils-commits mailing list