Fix the wrongish way we were doing staff-assisted holds
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 18 Jul 2011 22:49:01 +0000 (18:49 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 18 Jul 2011 22:49:01 +0000 (18:49 -0400)
Now the patron that a staff user wants to place a hold for is passed
around as a cookie

It's a little unclear when is best from a workflow perspective to kill
said cookie... hrmmm....

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/web/js/ui/default/opac/staff.js
Open-ILS/web/templates/default/opac/parts/place_hold.tt2
Open-ILS/xul/staff_client/server/patron/holds.js

index 72fbf59..b1d6483 100644 (file)
@@ -168,6 +168,19 @@ sub redirect_auth {
 sub load_simple {
     my ($self, $page) = @_;
     $self->ctx->{page} = $page;
+
+    if (my $patron_barcode = $self->cgi->param("patron_barcode")) {
+        # Special CGI variable from staff client; propagate henceforth as cookie
+        $self->apache->headers_out->add(
+            "Set-Cookie" => $self->cgi->cookie(
+                -name => "patron_barcode",
+                -path => "/",
+                -secure => 1,
+                -value => $patron_barcode,
+                -expires => undef
+            )
+        );
+    }
     return Apache2::Const::OK;
 }
 
index 410d06a..a715ab3 100644 (file)
@@ -400,12 +400,19 @@ sub load_place_hold {
     $ctx->{hold_target} = $cgi->param('hold_target');
     $ctx->{hold_type} = $cgi->param('hold_type');
 
-    # Although in the context of staff placing holds for other users, this
-    # does not yield the appropriate pickup lib, that situation is addressed
-    # in the client with javascript when possible.
-    $ctx->{default_pickup_lib} = $e->requestor->home_ou;
+    $ctx->{default_pickup_lib} = $e->requestor->home_ou; # unless changed below
 
-    my $request_lib = $e->requestor->ws_ou || $e->requestor->home_ou;
+    if (my $bc = $self->cgi->cookie("patron_barcode")) {
+        # passed in from staff client
+        $ctx->{patron_recipient} = $U->simplereq(
+            "open-ils.actor", "open-ils.actor.user.fleshed.retrieve_by_barcode",
+            $self->editor->authtoken, $bc
+        ) or return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
+
+        $ctx->{default_pickup_lib} = $ctx->{patron_recipient}->home_ou;
+    }
+
+    my $request_lib = $e->requestor->ws_ou;
 
     # XXX check for failure of the retrieve_* methods called below, and
     # possibly replace all the if,elsif with a dispatch table (meh, elegance)
@@ -527,7 +534,21 @@ sub load_place_hold {
                 $self->apache->log->info(
                     "Redirecting back to " . $cgi->param('redirect_to')
                 );
-                return $self->generic_redirect;
+
+                # We also clear the patron_barcode (from the staff client)
+                # cookie at this point (otherwise it haunts the staff user
+                # later). XXX todo make sure this is best; also see that
+                # template when staff mode calls xulG.opac_hold_placed()
+                return $self->generic_redirect(
+                    undef,
+                    $self->cgi->cookie(
+                        -name => "patron_barcode",
+                        -path => "/",
+                        -secure => 1,
+                        -value => "",
+                        -expires => "-1h"
+                    )
+                );
 
             } else {
                 $ctx->{hold_failed} = 1;
index 16234b5..c170198 100644 (file)
@@ -18,31 +18,9 @@ function staff_hold_usr_input_disabler(input) {
     document.getElementById("hold_usr_input").disabled =
         Boolean(Number(input.value));
 }
-function staff_hold_usr_prepop() {
-    if (xulG && xulG.patron_barcode) {
-        var sel = document.getElementById("pickup_lib");
-        for (var i = 0; i < sel.options.length; i++) {
-            if (sel.options[i].value == xulG.patron_home_ou) {
-                sel.selectedIndex = i;
-                break;
-            }
-        }
-        document.getElementById("hold_usr_input").value = xulG.patron_barcode;
-        document.getElementById("hold_usr_input").disabled = false;
-        document.getElementById("hold_usr_is_requestor_not").checked = true;
-
-        var kill_this =
-            document.getElementById("hold_usr_is_requestor").parentNode;
-        kill_this.parentNode.removeChild(kill_this);
-    }
-}
 window.onload = function() {
     // record details page events
     var rec = location.href.match(/\/opac\/record\/(\d+)/);
     if(rec && rec[1]) { runEvt('rdetail', 'recordRetrieved', rec[1]); }
-
-    if (document.getElementById("hold_usr_input"))
-        staff_hold_usr_prepop();
-
     // fire other events the staff client is expecting...
 }
index 4dcd278..8ca6075 100644 (file)
             <p class="staff-hold">
                 <input type="radio" id="hold_usr_is_requestor_not"
                     onchange="staff_hold_usr_input_disabler(this);"
-                    name="hold_usr_is_requestor" value="0" />
+                    name="hold_usr_is_requestor" value="0"
+                    [% IF ctx.patron_recipient; ' checked="checked"'; END %]
+                    />
                 <label for="hold_usr_is_requestor_not">
                     [% l("Place hold for patron by barcode:") %]
                 </label>
-                <input type="text" name="hold_usr" id="hold_usr_input" /><br />
+                <input type="text" name="hold_usr" id="hold_usr_input" value="[% ctx.patron_recipient.card.barcode %]" /><br />[%# XXX multi-barcode users? %]
                 <span>
                     <input type="radio" id="hold_usr_is_requestor"
                         onchange="staff_hold_usr_input_disabler(this);"
index 5dd912a..dc86318 100644 (file)
@@ -1309,6 +1309,9 @@ patron.holds.prototype = {
                         ['command'],
                         function(ev) {
                             try {
+                                var use_url = urls.browser;
+                                use_url += use_url.match(/\?/) ? "&" : "?";
+                                use_url += "patron_barcode=" + obj.patron_barcode;
                                 var content_params = {
                                     'show_nav_buttons' : false,
                                     'show_print_button' : true,
@@ -1341,11 +1344,10 @@ patron.holds.prototype = {
                                                 obj.error.standard_unexpected_error_alert('holds.js, opac_hold_placed(): ',E);
                                             }
                                         },
-                                        'patron_barcode' : obj.patron_barcode,
-                                        'patron_home_ou': patron.util.retrieve_au_via_id(ses(),obj.patron_id).home_ou()
+                                        'patron_barcode' : obj.patron_barcode
                                     },
                                     'url_prefix' : xulG.url_prefix,
-                                    'url' : xulG.url_prefix( urls.browser )
+                                    'url' : xulG.url_prefix(use_url)
                                 };
                                 xulG.display_window.g.patron.right_deck.set_iframe( urls.XUL_REMOTE_BROWSER + '?patron_hold=1', {}, content_params);
                             } catch(E) {