Acq+Vandelay form re-use new queue
authorBill Erickson <berick@esilibrary.com>
Fri, 10 Feb 2012 15:42:24 +0000 (10:42 -0500)
committerBen Shum <bshum@biblio.org>
Tue, 13 Mar 2012 19:28:24 +0000 (15:28 -0400)
In the Vandelay agent form, if a user creates a new destination queue
for the uploaded records, allow the user to re-use the new queue without
having to refresh the interface.  This is primarily useful in the ACQ
upload UI, where re-using the pre-filled form is possible.

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 7e307c6..dbfc70f 100644 (file)
@@ -1,4 +1,5 @@
 dojo.require('openils.widget.AutoFieldWidget');
+dojo.require('openils.PermaCrud');
 
 function VLAgent(args) {
     args = args || {};
@@ -34,7 +35,8 @@ function VLAgent(args) {
                         selfReference : true,
                         orgLimitPerms : [self.limitPerm || 'CREATE_PURCHASE_ORDER'],
                         parentNode : dojo.byId('acq_vl:' + widg.key),
-                        searchFilter : (widg.cls == 'vbq') ? {queue_type : 'acq'} : null
+                        searchFilter : (widg.cls == 'vbq') ? {queue_type : 'acq'} : null,
+                        useWriteStore :  (widg.cls == 'vbq')
                     }).build(function(dijit) { 
                         widg.dijit = dijit; 
                         self.attachOnChange(widg);
@@ -161,7 +163,20 @@ function VLAgent(args) {
             }
 
             if (resp.queue) {
-                res.queue_url = oilsBasePath + '/vandelay/vandelay?qtype=bib&qid=' + resp.queue.id();
+                var newQid = resp.queue.id();
+                res.queue_url = oilsBasePath + '/vandelay/vandelay?qtype=bib&qid=' + newQid;
+
+                var qInput = this.getDijit('queue_name');
+
+                if (newQName = qInput.attr('value')) {
+                    // user created a new queue.  Fetch the new queue object,
+                    // replace the ReadStore with a WriteStore and insert.
+                    qInput.attr('value', '');
+                    var qSelector = this.getDijit('existing_queue');
+                    var newQ = new openils.PermaCrud().retrieve('vbq', newQid);
+                    qSelector.store.newItem(newQ.toStoreItem());
+                    qSelector.attr('value', newQid);
+                }
             }
 
             if (oncomplete)