ACQ+Vandelay detect existing queue with same name
authorBill Erickson <berick@esilibrary.com>
Wed, 1 Feb 2012 14:12:23 +0000 (09:12 -0500)
committerBen Shum <bshum@biblio.org>
Tue, 13 Mar 2012 19:28:01 +0000 (15:28 -0400)
Within the acq/vandelay agent, detect when a user has entered the name
of one of their existing queues.  When detected, update the queue
selector to match the found queue (which updates the linked match set
and clears the queue selector input).  Otherwise, users may not realize
they are adding items to an existing queue (with a pre-linked match
set).

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/web/js/ui/default/acq/common/vlagent.js

index 8444b9c..7e307c6 100644 (file)
@@ -84,13 +84,33 @@ function VLAgent(args) {
         }
 
         qInputChange = function(val) {
-            // TODO: user may enter the name of an existing queue.  
-            // Detect this and disable/update match_set accordingly
-            self.getDijit('match_set').attr('disabled', false);
+
             var qSelector = self.getDijit('existing_queue');
-            dojo.disconnect(qSelector._onchange);
-            qSelector.attr('value', '');
-            qSelector._onchange = dojo.connect(qSelector, 'onChange', qSelChange);
+            var matchSetSelector = self.getDijit('match_set');
+            var foundMatch = false;
+
+            if (val) {
+
+                // if the user entered the name of an existing queue, update the 
+                // queue selector to match the value (and clear the text input 
+                // via qselector onchange)
+                qSelector.store.fetch({
+                    query:{name:val},
+                    onComplete:function(items) {
+                        if(items.length == 0) return;
+                        var item = items[0];
+                        qSelector.attr('value', item.id);
+                        foundMatch = true;
+                    }
+                });
+            }
+
+            if (!foundMatch) {
+                self.getDijit('match_set').attr('disabled', false);
+                dojo.disconnect(qSelector._onchange);
+                qSelector.attr('value', '');
+                qSelector._onchange = dojo.connect(qSelector, 'onChange', qSelChange);
+            }
         }
 
         if (widg.key == 'existing_queue') {
@@ -103,9 +123,7 @@ function VLAgent(args) {
     }
 
     this.getDijit = function(key) {
-        return this.widgets.filter( 
-            function(w) {return (w.key == key)}
-        )[0].dijit;
+        return this.widgets.filter(function(w) {return (w.key == key)})[0].dijit;
     }
 
     this.values = function() {