Initial dev repository
[kcls-web.git] / js / ui / default / acq / common / inv_dialog.js
diff --git a/js/ui/default/acq/common/inv_dialog.js b/js/ui/default/acq/common/inv_dialog.js
new file mode 100644 (file)
index 0000000..b76aa97
--- /dev/null
@@ -0,0 +1,46 @@
+function InvoiceLinkDialogManager(which, target) {
+    var self = this;
+    this.inv = null;
+
+    this.linkFoundInvoice = function(r) {
+        self.inv = openils.Util.readResponse(r);
+        location.href = oilsBasePath + "/acq/invoice/view/" + self.inv.id() +
+            "?attach_" + self.which + "=" + self.target.id();
+    };
+
+    this.which = which;
+    if (target)
+        this.target = target;
+
+    new openils.widget.AutoFieldWidget({
+        "fmField": "provider",
+        "fmClass": "acqinv",
+        "parentNode": dojo.byId("acq-" + this.which + "-link-invoice-provider"),
+        "orgLimitPerms": ["VIEW_INVOICE"],
+        "forceSync": true
+    }).build();
+
+    dijit.byId("acq-" + this.which + "-link-invoice-link").onClick =
+        function() {
+            self.inv = null;
+            pcrud.search(
+                "acqinv", {
+                    "provider": dijit.byId(
+                            "acq-" + self.which + "-link-invoice-provider"
+                        ).attr("value"),
+                    "inv_ident":
+                        dijit.byId(
+                            "acq-" + self.which + "-link-invoice-inv_ident"
+                        ).attr("value")
+                }, {
+                    "async": true,
+                    "streaming": true,
+                    "onresponse": self.linkFoundInvoice,
+                    "oncomplete": function() {
+                        if (!self.inv)
+                            alert(localeStrings.NO_FIND_INVOICE);
+                    }
+                }
+            );
+        };
+}