ACQ : Support lineitem fucus in ACQ unified search
authorBill Erickson <berick@esilibrary.com>
Fri, 13 Jul 2012 20:31:41 +0000 (16:31 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 24 Jul 2012 16:46:01 +0000 (12:46 -0400)
Adds support for a "focus_li" URL parameter to ACQ unified search
results pages.  When present, the page of results containing the
requested lineitem are loaded (instead of the default page 1) and the
lineitem is made visible in the viewable screen using the lineitem table
focusLi mechanism.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/web/js/ui/default/acq/common/li_table_pager.js
Open-ILS/web/js/ui/default/acq/search/unified.js

index 20d8a17..de24dcb 100644 (file)
@@ -60,6 +60,40 @@ function LiTablePager() {
         }
     };
 
+    this.focusLi = function() {
+        var liId = this.liTable.focusLineitem;
+        if (liId && this.liTable.liCache[liId] && dojo.byId('li-title-ref-' + liId))
+            this.liTable.focusLi();
+    };
+
+    /* given a lineitem to focus, this will determine what page in 
+     * the results set the lineitem sits, then fetch that page 
+     * of results.  Returns false if no focus requested.
+     */
+    this.loadFocusLi = function() {
+        var liId = this.liTable.focusLineitem;
+        if (!liId) return false;
+
+        var _this = this;
+        this.getAllLineitemIDs(
+            function(r) {
+                var allIds = openils.Util.readResponse(r);
+                var idx = dojo.indexOf(allIds, liId);
+                // if li not found, result is loading page 1
+
+                var page = 1;
+                while ( idx >= (page * _this.displayLimit) ) { 
+                    page++;
+                }
+
+                _this.displayOffset = (_this.displayLimit * (page - 1));
+                _this.dataLoader();
+            }
+        );
+
+        return true;
+    };
+
     this.getAllLineitemIDs = function(callback) {
         this.dataLoader({
             "id_list": true,
index 68fb3bb..b7f0137 100644 (file)
@@ -775,6 +775,13 @@ function ResultManager(liPager, poGrid, plGrid, invGrid) {
     };
 
     this.resultsComplete = function() {
+
+        // now that the records are loaded, we need to do the actual focusing
+        if (this.result_type == 'lineitem') {
+            if (this.liPager) 
+                this.liPager.focusLi();
+        }
+
         if (!this.count_results)
             this.show("no_results");
         else this.finish(this.result_type);
@@ -838,6 +845,15 @@ function ResultManager(liPager, poGrid, plGrid, invGrid) {
             );
         }
 
+        // if the caller has requested we focus on a specific
+        // lineitem, allow the pager to find the lineitem
+        // and load the results directly.
+        if (this.result_type == 'lineitem') {
+            if (this.liPager && this.liPager.loadFocusLi()) { 
+                return;
+            }
+        }
+
         interface.dataLoader();
     };
 }