]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/common/vlagent.js
ACQ+Vandelay import/merge user interface components
[Evergreen.git] / Open-ILS / web / js / ui / default / acq / common / vlagent.js
1 dojo.require('openils.widget.AutoFieldWidget');
2
3 function VLAgent(args) {
4     args = args || {};
5     for (var key in args) { 
6         this[key] = args[key]; 
7     }
8
9     this.widgets = [  
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'},
15         {key : 'queue_name'},
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'}
21     ];
22     
23     this.loaded = false;
24
25     this.init = function() {
26         var self = this;
27
28         dojo.forEach(this.widgets,
29             function(widg) {
30                 if (widg.cls) { // selectors
31
32                     new openils.widget.AutoFieldWidget({
33                         fmClass : widg.cls,
34                         selfReference : true,
35                         orgLimitPerms : [self.limitPerm || 'CREATE_PURCHASE_ORDER'],
36                         parentNode : dojo.byId('acq_vl:' + widg.key)
37                     }).build(function(dijit) { 
38                         widg.dijit = dijit; 
39                     }); 
40
41                 } else { // bools
42                     widg.dijit = dijit.byId('acq_vl:' + widg.key);
43                 }
44             }
45         );
46         
47         // loaded != all widgets are done rendering,
48         // only that init() has been called.
49         this.loaded = true;
50     }
51
52     this.values = function() {
53         var values = {};
54         dojo.forEach(this.widgets,
55             function(widg) {
56                 values[widg.key] = widg.dijit.attr('value');
57             }
58         );
59         return values;
60     }
61
62     this.handleResponse = function(resp, oncomplete) {
63         if(!resp) return;
64         var res = {}
65
66         console.log('vandelay import returned : ' + js2JSON(resp));
67
68         // update the display counts
69         dojo.byId('acq_vl:li-processed').innerHTML = resp.li;
70         dojo.byId('acq_vl:vqbr-processed').innerHTML = resp.vqbr;
71         dojo.byId('acq_vl:bibs-processed').innerHTML = resp.bibs;
72         dojo.byId('acq_vl:lid-processed').innerHTML = resp.lid;
73         dojo.byId('acq_vl:debits-processed').innerHTML = resp.debits_accrued;
74         dojo.byId('acq_vl:copies-processed').innerHTML = resp.copies;
75
76         if (resp.complete) {
77
78             if(resp.picklist) {
79                 res.picklist_url = oilsBasePath + '/acq/picklist/view/' + resp.picklist.id();
80             } 
81
82             if(resp.purchase_order) {
83                 res.po_url = oilsBasePath + '/acq/po/view/' + resp.purchase_order.id();
84             }
85
86             if (resp.queue) {
87                 res.queue_url = oilsBasePath + '/vandelay/vandelay?qtype=bib&qid=' + resp.queue.id();
88             }
89
90             if (oncomplete) 
91                 oncomplete(resp, res);
92
93             return res;
94         }
95
96         return false; // not yet complete
97     }
98 }