1 dojo.require('openils.widget.AutoFieldWidget');
3 function VLAgent(args) {
5 for (var key in args) {
10 {key : 'import_no_match'},
11 {key : 'auto_overlay_exact'},
12 {key : 'auto_overlay_1match'},
13 {key : 'auto_overlay_best_match'},
14 {key : 'match_quality_ratio'},
16 {key : 'match_set', cls : 'vms'},
17 {key : 'bib_source', cls : 'cbs'},
18 {key : 'merge_profile', cls : 'vmp'},
19 {key : 'fall_through_merge_profile', cls : 'vmp'},
20 {key : 'existing_queue', cls : 'vbq'}
25 this.init = function() {
28 dojo.forEach(this.widgets,
30 if (widg.cls) { // selectors
32 new openils.widget.AutoFieldWidget({
35 orgLimitPerms : [self.limitPerm || 'CREATE_PURCHASE_ORDER'],
36 parentNode : dojo.byId('acq_vl:' + widg.key),
37 searchFilter : (widg.cls == 'vbq') ? {queue_type : 'acq'} : null
38 }).build(function(dijit) {
40 self.attachOnChange(widg);
44 widg.dijit = dijit.byId('acq_vl:' + widg.key);
45 self.attachOnChange(widg);
50 // loaded != all widgets are done rendering,
51 // only that init() has been called.
55 this.attachOnChange = function(widg) {
59 var qSelChange = function(val) {
60 // user selected a queue from the selector; clear the text input
61 // and set the item import profile already defined for the queue
63 var qInput = self.getDijit('queue_name');
64 var matchSetSelector = self.getDijit('match_set');
65 var qSelector = self.getDijit('existing_queue');
68 qSelector.store.fetch({
69 query : {id : val+''},
70 onComplete : function(items) {
71 matchSetSelector.attr('value', items[0].match_set[0] || '');
72 matchSetSelector.attr('disabled', true);
76 matchSetSelector.attr('value', '');
77 matchSetSelector.attr('disabled', false);
80 // detach and reattach to avoid onchange firing while when we clear
81 dojo.disconnect(qInput._onchange);
82 qInput.attr('value', '');
83 qInput._onchange = dojo.connect(qInput, 'onChange', qInputChange);
86 qInputChange = function(val) {
87 // TODO: user may enter the name of an existing queue.
88 // Detect this and disable/update match_set accordingly
89 self.getDijit('match_set').attr('disabled', false);
90 var qSelector = self.getDijit('existing_queue');
91 dojo.disconnect(qSelector._onchange);
92 qSelector.attr('value', '');
93 qSelector._onchange = dojo.connect(qSelector, 'onChange', qSelChange);
96 if (widg.key == 'existing_queue') {
97 var qSelector = self.getDijit('existing_queue');
98 qSelector._onchange = dojo.connect(qSelector, 'onChange', qSelChange);
99 } else if(widg.key == 'queue_name') {
100 var qInput = self.getDijit('queue_name');
101 qInput._onchange = dojo.connect(qInput, 'onChange', qInputChange);
105 this.getDijit = function(key) {
106 return this.widgets.filter(
107 function(w) {return (w.key == key)}
111 this.values = function() {
113 dojo.forEach(this.widgets,
115 values[widg.key] = widg.dijit.attr('value');
121 this.handleResponse = function(resp, oncomplete) {
125 console.log('vandelay import returned : ' + js2JSON(resp));
127 // update the display counts
128 dojo.byId('acq_vl:li-processed').innerHTML = resp.li;
129 dojo.byId('acq_vl:vqbr-processed').innerHTML = resp.vqbr;
130 dojo.byId('acq_vl:bibs-processed').innerHTML = resp.bibs;
131 dojo.byId('acq_vl:lid-processed').innerHTML = resp.lid;
132 dojo.byId('acq_vl:debits-processed').innerHTML = resp.debits_accrued;
133 dojo.byId('acq_vl:copies-processed').innerHTML = resp.copies;
138 res.picklist_url = oilsBasePath + '/acq/picklist/view/' + resp.picklist.id();
141 if(resp.purchase_order) {
142 res.po_url = oilsBasePath + '/acq/po/view/' + resp.purchase_order.id();
146 res.queue_url = oilsBasePath + '/vandelay/vandelay?qtype=bib&qid=' + resp.queue.id();
150 oncomplete(resp, res);
155 return false; // not yet complete