ACQ+Vandelay disallow match_set change on selected queue
authorBill Erickson <berick@esilibrary.com>
Tue, 31 Jan 2012 17:17:20 +0000 (12:17 -0500)
committerBen Shum <bshum@biblio.org>
Tue, 13 Mar 2012 19:27:44 +0000 (15:27 -0400)
Consistent with Vandelay, if a queue is selected, show the linked
match_set and disable the match_set selector.  Existing queues are
already linked to a match set, so allowing the user to select one has no
effect, which is confusing.

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 1af1f77..e7c5b05 100644 (file)
@@ -36,10 +36,12 @@ function VLAgent(args) {
                         parentNode : dojo.byId('acq_vl:' + widg.key)
                     }).build(function(dijit) { 
                         widg.dijit = dijit; 
+                        self.attachOnChange(widg);
                     }); 
 
                 } else { // bools
                     widg.dijit = dijit.byId('acq_vl:' + widg.key);
+                    self.attachOnChange(widg);
                 }
             }
         );
@@ -49,6 +51,62 @@ function VLAgent(args) {
         this.loaded = true;
     }
 
+    this.attachOnChange = function(widg) {
+        var self = this;
+        var qInputChange;
+
+        var qSelChange = function(val) {
+            // user selected a queue from the selector;  clear the text input 
+            // and set the item import profile already defined for the queue
+
+            var qInput = self.getDijit('queue_name');
+            var matchSetSelector = self.getDijit('match_set');
+            var qSelector = self.getDijit('existing_queue');
+
+            if(val) {
+                qSelector.store.fetch({
+                    query : {id : val+''},
+                    onComplete : function(items) {
+                        matchSetSelector.attr('value', items[0].match_set[0] || '');
+                        matchSetSelector.attr('disabled', true);
+                    }
+                });
+            } else {
+                matchSetSelector.attr('value', '');
+                matchSetSelector.attr('disabled', false);
+            }
+
+            // detach and reattach to avoid onchange firing while when we clear
+            dojo.disconnect(qInput._onchange);
+            qInput.attr('value', '');
+            qInput._onchange = dojo.connect(qInput, 'onChange', qInputChange);
+        }
+
+        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);
+        }
+
+        if (widg.key == 'existing_queue') {
+            var qSelector = self.getDijit('existing_queue');
+            qSelector._onchange = dojo.connect(qSelector, 'onChange', qSelChange);
+        } else if(widg.key == 'queue_name') {
+            var qInput = self.getDijit('queue_name');
+            qInput._onchange = dojo.connect(qInput, 'onChange', qInputChange);
+        }
+    }
+
+    this.getDijit = function(key) {
+        return this.widgets.filter( 
+            function(w) {return (w.key == key)}
+        )[0].dijit;
+    }
+
     this.values = function() {
         var values = {};
         dojo.forEach(this.widgets,