]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/common/inv_dialog.js
7a5789e1dc88158661b3d0dc8a3c8edf48cd9127
[working/Evergreen.git] / Open-ILS / web / js / ui / default / acq / common / inv_dialog.js
1 function InvoiceLinkDialogManager(which, target) {
2     var self = this;
3     this.inv = null;
4
5     this.linkFoundInvoice = function(r) {
6         self.inv = openils.Util.readResponse(r);
7         var path = oilsBasePath + "/acq/invoice/view/" + self.inv.id();
8         if (!dojo.isArray(self.target)) self.target = [self.target];
9         dojo.forEach(self.target, function(target, idx) { 
10             id = (typeof target != 'object') ? target : target.id();
11             var join = (idx == 0) ? '?' : '&';
12             path += join + "attach_" + self.which + "=" + id;
13         });
14         location.href = path;
15     };
16
17     this.which = which;
18     if (target)
19         this.target = target;
20
21     new openils.widget.AutoFieldWidget({
22         "fmField": "provider",
23         "fmClass": "acqinv",
24         "parentNode": dojo.byId("acq-" + this.which + "-link-invoice-provider"),
25         "orgLimitPerms": ["VIEW_INVOICE"],
26         "forceSync": true
27     }).build();
28
29     dijit.byId("acq-" + this.which + "-link-invoice-link").onClick =
30         function() {
31             self.inv = null;
32             pcrud.search(
33                 "acqinv", {
34                     "provider": dijit.byId(
35                             "acq-" + self.which + "-link-invoice-provider"
36                         ).attr("value"),
37                     "inv_ident":
38                         dijit.byId(
39                             "acq-" + self.which + "-link-invoice-inv_ident"
40                         ).attr("value")
41                 }, {
42                     "async": true,
43                     "streaming": true,
44                     "onresponse": self.linkFoundInvoice,
45                     "oncomplete": function() {
46                         if (!self.inv)
47                             alert(localeStrings.NO_FIND_INVOICE);
48                     }
49                 }
50             );
51         };
52 }