ACQ: allow recv actions on copies from non-PO interface
authorBill Erickson <berick@esilibrary.com>
Tue, 22 Nov 2011 21:53:30 +0000 (16:53 -0500)
committerMike Rylander <mrylander@gmail.com>
Sun, 1 Apr 2012 02:42:38 +0000 (22:42 -0400)
* Allow PO actions on copies, like recieve, unreceive, and cancel from
  non-PO interfaces like the picklist UI and lineitem search interfaces.
  Instead of relying on whether the user is viewing a PO, use the status
  of each copy to determine which actions are appropriate to display.

* General cleanup and better arrangment of the copy actions hide/display
  logic

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/web/js/ui/default/acq/common/li_table.js

index b44a53f..c9b70d4 100644 (file)
@@ -1722,13 +1722,13 @@ function AcqLiTable() {
     };
 
     this.updateLidState = function(copy, row) {
+        var self = this;
+
         if (typeof(row) == "undefined") {
-            row = dojo.query(
-                'tr[copy_id="' + copy.id() + '"]', this.copyTbody
-            )[0];
+            row = dojo.query('tr[copy_id="' + copy.id() + '"]', this.copyTbody)[0];
         }
 
-        var self = this;
+        // action links
         var recv_link = nodeByName("receive", row);
         var unrecv_link = nodeByName("unreceive", row);
         var del_link = nodeByName("delete", row);
@@ -1736,90 +1736,78 @@ function AcqLiTable() {
         var claim_link = nodeByName("claim", row);
         var cxl_reason_link = nodeByName("cancel_reason", row);
 
-        if (copy.cancel_reason()) {
-            openils.Util.hide(del_link.parentNode);
-            openils.Util.hide(recv_link);
-            openils.Util.hide(unrecv_link);
-            openils.Util.hide(cxl_link);
-            openils.Util.hide(claim_link);
-
-            /* XXX the following may leak memory in a long lived table: dijits may not get destroyed... not positive. revisit. */
-            var holds_reason = dojo.create(
-                "span", {
-                    "style": "border-bottom: 1px dashed #000;",
-                    "innerHTML": "Cancelled" /* XXX [sic] and i18n */
-                }, cxl_reason_link, "only"
-            );
-            new dijit.Tooltip(
-                {
-                    "label": "<em>" + copy.cancel_reason().label() +
-                        "</em><br />" + copy.cancel_reason().description(),
-                    "connectId": [holds_reason]
-                }, dojo.create("span", null, cxl_reason_link, "last")
-            );
-            openils.Util.show(cxl_reason_link, "inline");
-        } else if (this.isPO) {
-            /* Only using this in one place so far, but may want it for better
-             * decisions on when to display certain controls. */
-            var li_state = this.liCache[copy.lineitem()].state();
-
-            openils.Util.hide(del_link.parentNode);
-            openils.Util.hide(cxl_reason_link);
-
-            /* Avoid showing (un)receive links, cancel links, for virt copies */
-            if (copy.id() > 0) {
-                if (copy.recv_time()) {
-                    openils.Util.hide(cxl_link);
-                    openils.Util.hide(recv_link);
-                    openils.Util.hide(claim_link);
-
-                    openils.Util.show(unrecv_link, "inline");
-                    unrecv_link.onclick = function() {
-                        if (confirm(localeStrings.UNRECEIVE_LID))
-                            self.issueReceive(copy, /* rollback */ true);
-                    };
-                } else {
-                    openils.Util.hide(unrecv_link);
+        // by default, hide all the actions
+        openils.Util.hide(del_link.parentNode);
+        openils.Util.hide(recv_link);
+        openils.Util.hide(unrecv_link);
+        openils.Util.hide(cxl_link);
+        openils.Util.hide(claim_link);
+        openils.Util.hide(cxl_reason_link);
 
-                    if (this.claimEligibleLid[copy.id()]) {
-                        openils.Util.show(claim_link, "inline");
-                        claim_link.onclick = function() {
-                            self.claimDialog.show(
-                                self.liCache[copy.lineitem()], copy.id()
-                            );
-                        };
-                    } else {
-                        openils.Util.hide(claim_link);
-                    }
+        if (copy.id() > 0) { // real copies (LIDs)
+
+            if (copy.cancel_reason()) { 
+
+                /* --------- cancelled -------------------------- */
+
+                /* XXX the following may leak memory in a long lived table: 
+                 * dijits may not get destroyed... not positive. revisit. */
+                var holds_reason = dojo.create(
+                    "span", {
+                        "style": "border-bottom: 1px dashed #000;",
+                        "innerHTML": "Cancelled" /* XXX [sic] and i18n */
+                    }, cxl_reason_link, "only"
+                );
+                new dijit.Tooltip(
+                    {
+                        "label": "<em>" + copy.cancel_reason().label() +
+                            "</em><br />" + copy.cancel_reason().description(),
+                        "connectId": [holds_reason]
+                    }, dojo.create("span", null, cxl_reason_link, "last")
+                );
+                openils.Util.show(cxl_reason_link, "inline");
+
+            } else if (copy.recv_time()) { 
+
+                /* --------- received -------------------------- */
+
+                openils.Util.show(unrecv_link, "inline");
+                unrecv_link.onclick = function() {
+                    if (confirm(localeStrings.UNRECEIVE_LID))
+                        self.issueReceive(copy, /* rollback */ true);
+                };
+
+            } else if (this.liCache[copy.lineitem()].state() == 'on-order') {
+                
+                /* --------- on order -------------------------- */
+
+                openils.Util.show(recv_link, 'inline');
+                openils.Util.show(cxl_link, "inline");
+
+                recv_link.onclick = function() {
+                    if (self.checkLiAlerts(copy.lineitem()))
+                        self.issueReceive(copy);
+                };
+
+                cxl_link.onclick = function() { self.cancelLid(copy.id()) };
 
-                    openils.Util[li_state == "on-order" ? "show" : "hide"](
-                        recv_link, "inline"
-                    );
-                    openils.Util.show(cxl_link, "inline");
-                    recv_link.onclick = function() {
-                        if (self.checkLiAlerts(copy.lineitem()))
-                            self.issueReceive(copy);
-                    };
-                    cxl_link.onclick = function() {
-                        self.cancelLid(copy.id());
-                    };
-                }
             } else {
-                openils.Util.hide(cxl_link);
-                openils.Util.hide(unrecv_link);
-                openils.Util.hide(recv_link);
-                openils.Util.hide(claim_link);
+
+                /* --------- pre-order copies  -------------------------- */
+
+                del_link.onclick = function() { self.deleteCopy(row) };
+                openils.Util.show(del_link.parentNode);
+
             }
-        } else {
-            openils.Util.hide(unrecv_link);
-            openils.Util.hide(recv_link);
-            openils.Util.hide(cxl_reason_link);
-            openils.Util.hide(claim_link);
+
+        } else { 
+
+            /* --------- virtual copies  -------------------------- */
 
             del_link.onclick = function() { self.deleteCopy(row) };
             openils.Util.show(del_link.parentNode);
         }
-    }
+    };
 
     this.cancelLid = function(lid_id) {
         lidCancelDialog._lid_id = lid_id;