]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/common/inv_dialog.js
6ef5126611d5ebbcaa9b39dacf8fb4a2ed5e76a8
[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         if (openils.XUL.isXUL()) {
15             openils.XUL.newTabEasy(
16                 path,
17                 /* tab title */ dojo.string.substitute(
18                     localeStrings.INVOICE_NUMBER, [self.inv.inv_ident()]
19                 ),
20                 null,
21                 true /* <browser> wrapper */
22             );
23         } else {
24             location.href = path;
25         }
26     };
27
28     this.which = which;
29     if (target)
30         this.target = target;
31
32     new openils.widget.AutoFieldWidget({
33         "fmField": "provider",
34         "fmClass": "acqinv",
35         "parentNode": dojo.byId("acq-" + this.which + "-link-invoice-provider"),
36         "orgLimitPerms": ["VIEW_INVOICE"],
37         "forceSync": true
38     }).build();
39
40     dijit.byId("acq-" + this.which + "-link-invoice-link").onClick =
41         function() {
42             self.inv = null;
43             pcrud.search(
44                 "acqinv", {
45                     "provider": dijit.byId(
46                             "acq-" + self.which + "-link-invoice-provider"
47                         ).attr("value"),
48                     "inv_ident":
49                         dijit.byId(
50                             "acq-" + self.which + "-link-invoice-inv_ident"
51                         ).attr("value")
52                 }, {
53                     "async": true,
54                     "streaming": true,
55                     "onresponse": self.linkFoundInvoice,
56                     "oncomplete": function() {
57                         if (!self.inv)
58                             alert(localeStrings.NO_FIND_INVOICE);
59                     }
60                 }
61             );
62         };
63 }