Acq: when receiving items, require user to acknowledge any related alerts
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 19 Feb 2010 23:58:31 +0000 (23:58 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 19 Feb 2010 23:58:31 +0000 (23:58 +0000)
Alerts are, in this context, lineitem notes (acqlin) that have a non-null
alert_text value pointing to a lineitem alert text (acqliat).

Users will be prompted to acknowledge all related alerts whether attempting
the receive operation against the whole purchase order, lineitems, or
individual copies.  Users will not be prompted to acknowledge the same alert
more than once per "use" of the purchase order viewing interface.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@15603 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/acq/nls/acq.js
Open-ILS/web/js/ui/default/acq/common/li_table.js

index 586f007..ff1a457 100644 (file)
@@ -21,4 +21,5 @@
     'UNRECEIVE_LI': "Are you sure you want to mark this lineitem as UN-received?",
 
     'UNRECEIVE_LID': "Are you sure you want to mark this copy as UN-received?",
+    'CONFIRM_LI_ALERT': "An alert has been placed on the lineitem titled,\n\"${0}\":\n\n${1}\n\n${2}\n\nChoose OK if you wish to acknowledge this alert."
 }
index 873cdff..22c3a8b 100644 (file)
@@ -40,6 +40,7 @@ function AcqLiTable() {
     this.toggleState = false;
     this.tbody = dojo.byId('acq-lit-tbody');
     this.selectors = [];
+    this.noteAcks = {};
     this.authtoken = openils.User.authtoken;
     this.rowTemplate = this.tbody.removeChild(dojo.byId('acq-lit-row'));
     this.copyTbody = dojo.byId('acq-lit-li-details-tbody');
@@ -89,6 +90,7 @@ function AcqLiTable() {
         while(self.tbody.childNodes[0])
             self.tbody.removeChild(self.tbody.childNodes[0]);
         self.selectors = [];
+        self.noteAcks = {};
     };
     
     this.setNext = function(handler) {
@@ -281,7 +283,10 @@ function AcqLiTable() {
                     openils.Util.hide(real_copies_link);
                     openils.Util.hide(unrecv_link);
                     openils.Util.show(recv_link, "inline");
-                    recv_link.onclick = function() { self.issueReceive(li); };
+                    recv_link.onclick = function() {
+                        if (self.checkLiAlerts(li.id()))
+                            self.issueReceive(li);
+                    };
                     return;
                 case "received":
                     openils.Util.hide(recv_link);
@@ -929,7 +934,10 @@ function AcqLiTable() {
                 } else {
                     openils.Util.hide(unrecv_link);
                     openils.Util.show(recv_link);
-                    recv_link.onclick = function() { self.issueReceive(copy); };
+                    recv_link.onclick = function() {
+                        if (self.checkLiAlerts(copy.lineitem()))
+                            self.issueReceive(copy);
+                    };
                 }
             } else {
                 openils.Util.hide(unrecv_link);
@@ -944,6 +952,39 @@ function AcqLiTable() {
         }
     }
 
+    this._confirmAlert = function(li, lin) {
+        return confirm(
+            dojo.string.substitute(
+                localeStrings.CONFIRM_LI_ALERT, [
+                    (new openils.acq.Lineitem({"lineitem": li})).findAttr(
+                        "title", "lineitem_marc_attr_definition"
+                    ),
+                    lin.alert_text().description(), lin.value()
+                ]
+            )
+        );
+    };
+
+    this.checkLiAlerts = function(li_id) {
+        var li = this.liCache[li_id];
+
+        var alert_notes = li.lineitem_notes().filter(
+            function(o) { return Boolean(o.alert_text()); }
+        );
+
+        /* this is _intentionally_ not done in a call to forEach() ... */
+        for (var i = 0; i < alert_notes.length; i++) {
+            if (this.noteAcks[alert_notes[i].id()])
+                continue;
+            else if (!this._confirmAlert(li, alert_notes[i]))
+                return false;
+            else
+                this.noteAcks[alert_notes[i].id()] = true;
+        }
+
+        return true;
+    };
+
     this.deleteCopy = function(row) {
         var copy = this.copyCache[row.getAttribute('copy_id')];
         copy.isdeleted(true);
@@ -1184,7 +1225,15 @@ function AcqLiTable() {
 
 
     this.receivePO = function() {
-        if(!this.isPO) return;
+        if (!this.isPO) return;
+
+        for (var id in this.liCache) {
+            /* assumption: liCache reflects exactly the
+             * set of LIs that belong to our PO */
+            if (this.liCache[id].state() != "received" &&
+                !this.checkLiAlerts(id)) return;
+        }
+
         this.show('acq-lit-progress-numbers');
         var self = this;
         fieldmapper.standardRequest(