1 dojo.require('openils.widget.AutoFieldWidget');
2 dojo.require('openils.PermaCrud');
4 function VLAgent(args) {
6 for (var key in args) {
11 {key : 'import_no_match'},
12 {key : 'auto_overlay_exact'},
13 {key : 'auto_overlay_1match'},
14 {key : 'auto_overlay_best_match'},
15 {key : 'match_quality_ratio'},
17 {key : 'create_assets'},
18 {key : 'match_set', cls : 'vms'},
19 {key : 'bib_source', cls : 'cbs'},
20 {key : 'merge_profile', cls : 'vmp'},
21 {key : 'fall_through_merge_profile', cls : 'vmp'},
22 {key : 'existing_queue', cls : 'vbq'}
27 this.init = function() {
30 dojo.forEach(this.widgets,
32 if (widg.cls) { // selectors
34 new openils.widget.AutoFieldWidget({
37 orgLimitPerms : [self.limitPerm || 'CREATE_PURCHASE_ORDER'],
38 parentNode : dojo.byId('acq_vl:' + widg.key),
39 searchFilter : (widg.cls == 'vbq') ? {queue_type : 'acq'} : null,
40 useWriteStore : (widg.cls == 'vbq')
41 }).build(function(dijit) {
43 self.attachOnChange(widg);
47 widg.dijit = dijit.byId('acq_vl:' + widg.key);
48 if (!widg.dijit) return; // some fields optional
49 self.attachOnChange(widg);
54 // loaded != all widgets are done rendering,
55 // only that init() has been called.
59 this.attachOnChange = function(widg) {
63 var qSelChange = function(val) {
64 // user selected a queue from the selector; clear the text input
65 // and set the item import profile already defined for the queue
67 var qInput = self.getDijit('queue_name');
68 var matchSetSelector = self.getDijit('match_set');
69 var qSelector = self.getDijit('existing_queue');
72 qSelector.store.fetch({
73 query : {id : val+''},
74 onComplete : function(items) {
75 matchSetSelector.attr('value', items[0].match_set[0] || '');
76 matchSetSelector.attr('disabled', true);
80 matchSetSelector.attr('value', '');
81 matchSetSelector.attr('disabled', false);
84 // detach and reattach to avoid onchange firing while when we clear
85 dojo.disconnect(qInput._onchange);
86 qInput.attr('value', '');
87 qInput._onchange = dojo.connect(qInput, 'onChange', qInputChange);
90 qInputChange = function(val) {
92 var qSelector = self.getDijit('existing_queue');
93 var matchSetSelector = self.getDijit('match_set');
94 var foundMatch = false;
98 // if the user entered the name of an existing queue, update the
99 // queue selector to match the value (and clear the text input
100 // via qselector onchange)
101 qSelector.store.fetch({
103 onComplete:function(items) {
104 if(items.length == 0) return;
106 qSelector.attr('value', item.id);
113 self.getDijit('match_set').attr('disabled', false);
114 dojo.disconnect(qSelector._onchange);
115 qSelector.attr('value', '');
116 qSelector._onchange = dojo.connect(qSelector, 'onChange', qSelChange);
120 if (widg.key == 'existing_queue') {
121 var qSelector = self.getDijit('existing_queue');
122 qSelector._onchange = dojo.connect(qSelector, 'onChange', qSelChange);
123 } else if(widg.key == 'queue_name') {
124 var qInput = self.getDijit('queue_name');
125 qInput._onchange = dojo.connect(qInput, 'onChange', qInputChange);
129 this.getDijit = function(key) {
130 return this.widgets.filter(function(w) {return (w.key == key)})[0].dijit;
133 this.values = function() {
135 dojo.forEach(this.widgets,
138 values[widg.key] = widg.dijit.attr('value');
144 this.handleResponse = function(resp, oncomplete) {
148 console.log('vandelay import returned : ' + js2JSON(resp));
150 // update the display counts
151 dojo.byId('acq_vl:li-processed').innerHTML = resp.li;
152 dojo.byId('acq_vl:vqbr-processed').innerHTML = resp.vqbr;
153 dojo.byId('acq_vl:bibs-processed').innerHTML = resp.bibs;
154 dojo.byId('acq_vl:lid-processed').innerHTML = resp.lid;
155 dojo.byId('acq_vl:debits-processed').innerHTML = resp.debits_accrued;
156 dojo.byId('acq_vl:copies-processed').innerHTML = resp.copies;
161 res.picklist_url = oilsBasePath + '/acq/picklist/view/' + resp.picklist.id();
164 if(resp.purchase_order) {
165 res.po_url = oilsBasePath + '/acq/po/view/' + resp.purchase_order.id();
169 var newQid = resp.queue.id();
170 res.queue_url = oilsBasePath + '/vandelay/vandelay?qtype=bib&qid=' + newQid;
172 var qInput = this.getDijit('queue_name');
174 if (newQName = qInput.attr('value')) {
175 // user created a new queue. Fetch the new queue object,
176 // replace the ReadStore with a WriteStore and insert.
177 qInput.attr('value', '');
178 var qSelector = this.getDijit('existing_queue');
179 var newQ = new openils.PermaCrud().retrieve('vbq', newQid);
180 qSelector.store.newItem(newQ.toStoreItem());
181 qSelector.attr('value', newQid);
186 oncomplete(resp, res);
191 return false; // not yet complete