kpac : hold placement; more auth refresh repairs
authorBill Erickson <berick@esilibrary.com>
Thu, 5 Apr 2012 21:30:54 +0000 (17:30 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 30 Jul 2012 19:03:22 +0000 (15:03 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm
Open-ILS/src/templates/kpac/getit_results.tt2
Open-ILS/src/templates/kpac/parts/base.tt2

index 10dd567..c11efe1 100644 (file)
@@ -853,6 +853,8 @@ sub load_place_hold {
             }
         }
 
+        $self->apache->log->warn("$#parts : @t_holds");
+
         $self->attempt_hold_placement($usr, $pickup_lib, 'P', @p_holds) if @p_holds;
         $self->attempt_hold_placement($usr, $pickup_lib, 'T', @t_holds) if @t_holds;
 
index 1aab231..5c80f92 100644 (file)
@@ -88,25 +88,52 @@ sub login_and_place_hold {
     my $password = $self->cgi->param('password');
     my $pickup_lib = $self->cgi->param('pickup_lib');
 
+    return Apache2::Const::HTTP_BAD_REQUEST 
+        unless $pickup_lib =~ /^\d+$/;
+
+    my $new_uri = $self->apache->unparsed_uri;
+    my $sep = ($new_uri =~ /\?/) ? '&' : '?';
+
     if (!$ctx->{user}) {
         # First, log the user in and return to 
+        $self->apache->log->info("kpac: logging in $username");
+
         # TODO: let user know username/password is required..
         return Apache2::Const::OK unless $username and $password;
-        my $new_uri = $self->apache->unparsed_uri;
-        my $sep = ($new_uri =~ /\?/) ? '&' : '?';
+
         $new_uri .= "${sep}pickup_lib=$pickup_lib&action=hold";
         $self->cgi->param('redirect_to', $new_uri);
         return $self->load_login;
-    }
 
-    # TODO: place hold
+    } else {
 
-    my $hold_id = '';
-#    (my $new_uri = $self->apache->unparsed_uri) =~ s/getit/getit_results/g;
-#    $new_uri .= ($new_uri =~ /\?/) ? "&hold=$hold_id" : "?hold=$hold_id";
-#    return $self->generic_redirect($new_uri);
+        $self->apache->log->info("kpac: placing hold for $bre_id");
 
-    return Apache2::Const::OK;
+        $new_uri =~ s/getit/getit_results/g;
+        $self->cgi->param('hold_target', $bre_id);
+        $self->cgi->param('hold_type', 'T');
+        $self->cgi->param('part', ''); # needed even if unused
+
+        my $stat = $self->load_place_hold;
+
+        $self->apache->log->info("kpac: place hold returned $stat");
+
+        return $stat unless $stat == Apache2::Const::OK;
+
+        my $hdata = $ctx->{hold_data}->[0]; # only 1 hold placed
+        if (my $hold_id = $hdata ? $hdata->{hold_success} : undef) {
+
+            $self->apache->log->info("kpac: place hold succeeded");
+            $new_uri .= "${sep}hold=$hold_id";
+
+        } else {
+            $self->apache->log->info("kpac: place hold failed : " . $ctx->{hold_failed_event});
+            $new_uri .= "${sep}hold_failed=1";
+        }
+    }
+
+    $self->apache->log->info("kpac: place hold redirecting to: $new_uri");
+    return $self->generic_redirect($new_uri);
 }
 
 sub save_item_to_bookbag {
@@ -153,16 +180,13 @@ sub load_getit_results {
 
     if ($list) {
         if ($list eq 'anon') {
-            $ctx->{anon_list} = 1;
+            $ctx->{added_to_anon} = 1;
         } else {
-            $ctx->{list} = $e->retrieve_container_biblio_record_entry_bucket($list);
+            $ctx->{added_to_list} = $e->retrieve_container_biblio_record_entry_bucket($list);
         }
-
-    } elsif ($hold_id) {
-
-        # new hold means potential for replication lag
-        $e->xact_start; 
-        # fetch the hold...
+    } else { 
+        $e->xact_begin;
+        $ctx->{hold} = $e->retrieve_action_hold_request(8);
         $e->xact_rollback;
     }
 
index ebd8de0..d1fba7f 100644 (file)
@@ -5,36 +5,44 @@
     attrs = {marc_xml => ctx.marc_xml};
     PROCESS get_marc_attrs args=attrs;
     ctx.page_title = l('Get it');
-    kill_params = ['list', 'hold'];
+    kill_params = ['list', 'hold', 'hold_failed', 'pickup_lib'];
     title_html = attrs.title | html;
 %]
           
-<h2 class="sub_header2">You Got It!</h2>
 
 <div class="checkout_res_body">
-    [% IF ctx.anon_list %]
+    [% IF ctx.added_to_anon %]
+        <h2 class="sub_header2">[% l('You Saved It!') %]</h2>
         <p>
         [% |l(title_html) %]
         You successfully saved [_1].  <br/>
         To manage your lists, go to <a href="[% mkurl(ctx.opac_root _ '/myopac/lists', {}, 1) %]">My Lists</a>
         [% END %]
         <p>
-    [% ELSIF ctx.list %]
+    [% ELSIF ctx.added_to_list %]
         [% list_html = ctx.list.name | html %]
+        <h2 class="sub_header2">[% l('You Saved It!') %]</h2>
         <p>
         [% |l(title_html, list_html) %]
         You successfully saved [_1] to [_2]. <br/>  
         To manage your lists, go to <a href="[% mkurl(ctx.opac_root _ '/myopac/lists', {}, 1) %]">My Lists</a>
         [% END %]
         <p>
-    [% ELSE %]
+    [% ELSIF CGI.param('hold') %]
         [% lib_html = ctx.get_aou(ctx.hold.pickup_lib).name | html %]
+        <h2 class="sub_header2">[% l('You Got It!') %]</h2>
         <p>
         [% |l(title_html, lib_html) %]
         Your request for <a href="[% mkurl(ctx.kpac_root _ '/record/' _ ctx.bre_id, {}, kill_params) %]">[_1]</a> was successful.<br/>
         You will be able to pick up this material at [_2].
         [% END %]
         <p>
+    [% ELSE %]
+        <p>
+        [% |l(title_html) %]
+        Unable to request <a href="[% mkurl(ctx.kpac_root _ '/record/' _ ctx.bre_id, {}, kill_params) %]">[_1]</a>.<br/>
+        Please see a librarian.
+        [% END %]
     [% END %]
 </div>
 
index ebfe0e5..e80a4c1 100644 (file)
@@ -4,7 +4,8 @@
         <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
         <link rel="stylesheet" type="text/css" href="[% ctx.media_prefix %]/css/skin/default/kpac/style.css" />
         [% IF ctx.authtime %]
-        <meta http-equiv="refresh" content="[% ctx.authtime %];[% ctx.logout_page %]">
+        <meta http-equiv="refresh" content="[% ctx.authtime %];[% 
+            ctx.logout_page _ '?redirect_to=' _ ctx.home_page %]">
         [% END %]
         <title>[% l("Kid's Catalog - [_1]", ctx.page_title) %]</title>
     </head>