JBAS-1007 ACQ focus lib selector on delete
authorBill Erickson <berickxx@gmail.com>
Wed, 2 Dec 2015 20:49:37 +0000 (15:49 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Focus the first library selector after adding new copies and after
removing copies.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/web/js/ui/default/acq/common/li_table.js

index ea97da8..f6c651c 100644 (file)
@@ -2493,9 +2493,29 @@ function AcqLiTable() {
         }
     };
 
+    /*
+     * Focus the first owning library selector in the list of copies.
+     * Timeout is needed to prevent focus shifting before the onKeyUp 
+     * handler fires.  Otherwise, onKeyUp is called on the lib selector 
+     * instead of acqLitAddCopyCount, causing focus to jump to the second 
+     * selector.
+     */
+    this.focusCopyLibSelector = function() {
+        setTimeout(function() {
+            var row = dojo.query('tr', self.copyTbody)[0];
+            if (!row) return;
+
+            // The first filteringtreeselect is our owning lib selector
+            // They are sequential, but don't necessarily start with _1, 
+            // since rows can be arbitrarily removed.
+            var selector = dojo.query(
+                '[widgetid^="openils_widget_FilteringTreeSelect_"]', row)[0];
+            if (selector) selector.focus();
+        }, 100);
+    }
+
     this._drawCopies = function(li) {
         var self = this;
-        self.firstItemLibSelector = null;
 
         // this button sets the total number of copies for a given lineitem
         acqLitAddCopyCount.onClick = function() { 
@@ -2516,16 +2536,9 @@ function AcqLiTable() {
                 }
             }
 
-            // KCLS -- after adding new copies, focus the library
-            // selector of the first copy in the list.  Add the timeout
-            // so prevent focus shifting before the onKeyUp handler fires.
-            // Otherwise, onKeyUp is called on the lib selector instead
-            // of acqLitAddCopyCount, causing focus to jump to the 
-            // second selector.
-            setTimeout(function() {
-                if (self.firstItemLibSelector)
-                    self.firstItemLibSelector.focus();
-            }, 100);
+            // KCLS -- after adding or removing copies, focus the library
+            // selector of the first copy in the list.
+            self.focusCopyLibSelector();
         }
 
 
@@ -2659,17 +2672,14 @@ function AcqLiTable() {
 
                         // KCLS ---
                         if (field == 'owning_lib') {
-                            var nodeId = w.id.replace(/.*(\d+)$/,'$1');
-
-                            // track the first library selector so we can
-                            // focus it after generating new copies
-                            if (nodeId == 1) self.firstItemLibSelector = w;
 
                             // User pressing Enter on the ownling library 
                             // selector causes focus to jump to the next 
                             // owning library selector in the list of copies.
                             dojo.connect(w, 'onKeyUp', function(key) {
                                 if (key.keyCode != 13) return // 13 = Enter
+                                var nodeId = w.id.replace(/.*(\d+)$/,'$1');
+
                                 // ID's for like dijits increment by 1.
                                 var nextId = w.id.replace(
                                     /(.*)\d+$/, '$1' + (Number(nodeId) + 1));
@@ -2936,6 +2946,7 @@ function AcqLiTable() {
         if(copy.isnew())
             delete this.copyCache[copy.id()];
         this.copyTbody.removeChild(row);
+        this.focusCopyLibSelector();
     }
 
     this._virtDfaCountsAsList = function() {