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 : 'match_set', cls : 'vms'},
18 {key : 'bib_source', cls : 'cbs'},
19 {key : 'merge_profile', cls : 'vmp'},
20 {key : 'fall_through_merge_profile', cls : 'vmp'},
21 {key : 'existing_queue', cls : 'vbq'}
26 this.init = function() {
29 dojo.forEach(this.widgets,
31 if (widg.cls) { // selectors
33 new openils.widget.AutoFieldWidget({
36 orgLimitPerms : [self.limitPerm || 'CREATE_PURCHASE_ORDER'],
37 parentNode : dojo.byId('acq_vl:' + widg.key),
38 searchFilter : (widg.cls == 'vbq') ? {queue_type : 'acq'} : null,
39 useWriteStore : (widg.cls == 'vbq')
40 }).build(function(dijit) {
42 self.attachOnChange(widg);
46 widg.dijit = dijit.byId('acq_vl:' + widg.key);
47 self.attachOnChange(widg);
52 // loaded != all widgets are done rendering,
53 // only that init() has been called.
57 this.attachOnChange = function(widg) {
61 var qSelChange = function(val) {
62 // user selected a queue from the selector; clear the text input
63 // and set the item import profile already defined for the queue
65 var qInput = self.getDijit('queue_name');
66 var matchSetSelector = self.getDijit('match_set');
67 var qSelector = self.getDijit('existing_queue');
70 qSelector.store.fetch({
71 query : {id : val+''},
72 onComplete : function(items) {
73 matchSetSelector.attr('value', items[0].match_set[0] || '');
74 matchSetSelector.attr('disabled', true);
78 matchSetSelector.attr('value', '');
79 matchSetSelector.attr('disabled', false);
82 // detach and reattach to avoid onchange firing while when we clear
83 dojo.disconnect(qInput._onchange);
84 qInput.attr('value', '');
85 qInput._onchange = dojo.connect(qInput, 'onChange', qInputChange);
88 qInputChange = function(val) {
90 var qSelector = self.getDijit('existing_queue');
91 var matchSetSelector = self.getDijit('match_set');
92 var foundMatch = false;
96 // if the user entered the name of an existing queue, update the
97 // queue selector to match the value (and clear the text input
98 // via qselector onchange)
99 qSelector.store.fetch({
101 onComplete:function(items) {
102 if(items.length == 0) return;
104 qSelector.attr('value', item.id);
111 self.getDijit('match_set').attr('disabled', false);
112 dojo.disconnect(qSelector._onchange);
113 qSelector.attr('value', '');
114 qSelector._onchange = dojo.connect(qSelector, 'onChange', qSelChange);
118 if (widg.key == 'existing_queue') {
119 var qSelector = self.getDijit('existing_queue');
120 qSelector._onchange = dojo.connect(qSelector, 'onChange', qSelChange);
121 } else if(widg.key == 'queue_name') {
122 var qInput = self.getDijit('queue_name');
123 qInput._onchange = dojo.connect(qInput, 'onChange', qInputChange);
127 this.getDijit = function(key) {
128 return this.widgets.filter(function(w) {return (w.key == key)})[0].dijit;
131 this.values = function() {
133 dojo.forEach(this.widgets,
135 values[widg.key] = widg.dijit.attr('value');
141 this.handleResponse = function(resp, oncomplete) {
145 console.log('vandelay import returned : ' + js2JSON(resp));
147 // update the display counts
148 dojo.byId('acq_vl:li-processed').innerHTML = resp.li;
149 dojo.byId('acq_vl:vqbr-processed').innerHTML = resp.vqbr;
150 dojo.byId('acq_vl:bibs-processed').innerHTML = resp.bibs;
151 dojo.byId('acq_vl:lid-processed').innerHTML = resp.lid;
152 dojo.byId('acq_vl:debits-processed').innerHTML = resp.debits_accrued;
153 dojo.byId('acq_vl:copies-processed').innerHTML = resp.copies;
158 res.picklist_url = oilsBasePath + '/acq/picklist/view/' + resp.picklist.id();
161 if(resp.purchase_order) {
162 res.po_url = oilsBasePath + '/acq/po/view/' + resp.purchase_order.id();
166 var newQid = resp.queue.id();
167 res.queue_url = oilsBasePath + '/vandelay/vandelay?qtype=bib&qid=' + newQid;
169 var qInput = this.getDijit('queue_name');
171 if (newQName = qInput.attr('value')) {
172 // user created a new queue. Fetch the new queue object,
173 // replace the ReadStore with a WriteStore and insert.
174 qInput.attr('value', '');
175 var qSelector = this.getDijit('existing_queue');
176 var newQ = new openils.PermaCrud().retrieve('vbq', newQid);
177 qSelector.store.newItem(newQ.toStoreItem());
178 qSelector.attr('value', newQid);
183 oncomplete(resp, res);
188 return false; // not yet complete