Booking: don't bail out completely on COPY_ALERT_MESSAGE when returning items
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 10 Mar 2011 17:08:39 +0000 (17:08 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 10 Mar 2011 17:08:39 +0000 (17:08 +0000)
Provide overridability.

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

Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
Open-ILS/web/js/dojo/openils/booking/nls/pickup_and_return.js
Open-ILS/web/js/ui/default/booking/populator.js

index 97e4771..0e46529 100644 (file)
@@ -180,6 +180,10 @@ __PACKAGE__->register_method(
 );
 __PACKAGE__->register_method(
     method   => "run_method",
+    api_name => "open-ils.circ.reservation.return.override"
+);
+__PACKAGE__->register_method(
+    method   => "run_method",
     api_name => "open-ils.circ.checkout.inspect",
     desc     => q/Returns the circ matrix test result and, on success, the rule set and matrix test object/
 );
index f6df5dd..cf227ba 100644 (file)
@@ -29,5 +29,6 @@
     "AUTO_ATTR_VALUE_reset": "Clear / New Patron",
     "AUTO_ATTR_VALUE_pickup": "Pick up",
     "AUTO_ATTR_VALUE_return": "Return",
-    "ADDRESS": "${0}\n${1}\n${2}, ${3} ${4}"
+    "ADDRESS": "${0}\n${1}\n${2}, ${3} ${4}",
+    "COPY_ALERT": "${0}:\n${1}\n\nDo you wish to process it anyway?"
 }
index 9822144..1eeb7cb 100644 (file)
@@ -4,6 +4,7 @@
 dojo.require("dojo.data.ItemFileReadStore");
 dojo.require("dojo.date.locale");
 dojo.require("openils.PermaCrud");
+dojo.require("dojo.string");
 
 function Populator(widgets, primary_input) {
     this.widgets = widgets;
@@ -133,7 +134,7 @@ Populator.prototype.populate_patron = function(data) {
     this.reveal_container(this.widgets.patron);
     /* Maybe add patron's home OU or something here later... */
 };
-Populator.prototype.return_by_resource = function(barcode) {
+Populator.prototype.return_by_resource = function(barcode, override) {
     /* XXX instead of talking to the server every time we do this, we could
      * also check the "out" cache, iff we have one.  */
     var r = fieldmapper.standardRequest(
@@ -157,14 +158,26 @@ Populator.prototype.return_by_resource = function(barcode) {
             alert(localeStrings.NOTICE_CHANGE_OF_PATRON);
         }
         this.patron_barcode = new_barcode;
-        var ret = this.return(r);
+        var ret = this.return(r, override);
         if (!ret) {
             alert(localeStrings.RETURN_NO_RESPONSE);
         } else if (is_ils_event(ret) && ret.textcode != "SUCCESS") {
-            if (ret.textcode == "ROUTE_ITEM")
+            if (ret.textcode == "ROUTE_ITEM") {
                 display_transit_slip(ret);
-            else
+            } else if (ret.textcode == "COPY_ALERT_MESSAGE") {
+                if (
+                    confirm(
+                        dojo.string.substitute(
+                            localeStrings.COPY_ALERT, [ret.desc, ret.payload]
+                       )
+                    )
+                ) {
+                    this.return_by_resource(barcode, true /*override*/);
+                    return;
+                }
+            } else {
                 alert(my_ils_error(localeStrings.RETURN_ERROR, ret));
+            }
         } else {
             /* XXX speedbump should go, but something has to happen else
              * there's no indication to staff that anything happened when
@@ -231,9 +244,11 @@ Populator.prototype.pickup = function(reservation) {
         }]
     );
 };
-Populator.prototype.return = function(reservation) {
+Populator.prototype.return = function(reservation, override) {
+    var method = "open-ils.circ.reservation.return";
+    if (override) method += ".override";
     return fieldmapper.standardRequest(
-        ["open-ils.circ", "open-ils.circ.reservation.return"],
+        ["open-ils.circ", method],
         [openils.User.authtoken, {
             "patron_barcode": this.patron_barcode,
             "reservation": reservation.id()
@@ -258,20 +273,33 @@ Populator.prototype.act_on_selected = function(how, which) {
     var reservations = selected_id_list.map(function(o) { return cache[o]; });
 
     /* Do we have to process these one at a time?  I think so... */
-    for (var i in reservations) {
-        var result = this[how](reservations[i]);
+    var self = this;
+    function looper(reservation, override) {
+        if (looper._done) return;
+        var result = self[how](reservation, override);
         if (!result) {
             alert(no_response_msg);
         } else if (is_ils_event(result) && result.textcode != "SUCCESS") {
-            if (result.textcode == "ROUTE_ITEM")
+            if (result.textcode == "ROUTE_ITEM") {
                 display_transit_slip(result);
-            else
+            } else if (result.textcode == "COPY_ALERT_MESSAGE") {
+                if (confirm(
+                    dojo.string.substitute(
+                        localeStrings.COPY_ALERT, [result.desc, result.payload]
+                   )
+                )) {
+                    looper(reservation, true);
+                }
+                return; // continues processing other resvs
+            } else {
                 alert(my_ils_error(error_msg, result));
+            }
         } else {
-            continue;
+            return;
         }
-        break;
+        looper._done = true;
     }
+    dojo.forEach(reservations, looper);
 
     this.populate();
 };