Allow choice of placing hold despite age protect
authorThomas Berezansky <tsbere@mvlc.org>
Tue, 20 Sep 2011 14:27:51 +0000 (10:27 -0400)
committerMike Rylander <mrylander@gmail.com>
Thu, 12 Jan 2012 14:04:31 +0000 (09:04 -0500)
This alters the backend to watch when so much as one copy failed only due
to age protection. If so, a flag is set and returned back up the calling
tree for examination.

In JSPac when the flag is set an alternate confirm message is shown.

In TTPac when the flag is set the failure message is changed and override
is always allowed for the hold in question.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/templates/opac/parts/place_hold_result.tt2
Open-ILS/web/opac/locale/en-US/opac.dtd
Open-ILS/web/opac/skin/default/js/holds.js
Open-ILS/web/opac/skin/default/xml/common/holds.xml

index d083747..fe1b930 100644 (file)
@@ -2256,9 +2256,9 @@ sub check_title_hold {
         };
     } elsif ($status[2]) {
         my $n = scalar @{$status[2]};
-        return {"success" => 0, "last_event" => $status[2]->[$n - 1]};
+        return {"success" => 0, "last_event" => $status[2]->[$n - 1], "age_protected_copy" => $status[3]};
     } else {
-        return {"success" => 0};
+        return {"success" => 0, "age_protected_copy" => $status[3]};
     }
 }
 
@@ -2473,6 +2473,7 @@ sub _check_title_hold_is_possible {
     my $title;
     my %seen;
     my @status;
+    my $age_protect_only = 0;
     OUTER: for my $key (@keys) {
       my @cps = @{$buckets{$key}};
 
@@ -2494,10 +2495,12 @@ sub _check_title_hold_is_possible {
          @status = verify_copy_for_hold(
             $patron, $requestor, $title, $copy, $pickup_lib, $request_lib);
 
+         $age_protect_only ||= $status[3];
          last OUTER if $status[0];
       }
     }
 
+    $status[3] = $age_protect_only;
     return @status;
 }
 
@@ -2599,6 +2602,7 @@ sub _check_issuance_hold_is_possible {
     my $title;
     my %seen;
     my @status;
+    my $age_protect_only = 0;
     OUTER: for my $key (@keys) {
       my @cps = @{$buckets{$key}};
 
@@ -2620,6 +2624,7 @@ sub _check_issuance_hold_is_possible {
          @status = verify_copy_for_hold(
             $patron, $requestor, $title, $copy, $pickup_lib, $request_lib);
 
+         $age_protect_only ||= $status[3];
          last OUTER if $status[0];
       }
     }
@@ -2632,6 +2637,7 @@ sub _check_issuance_hold_is_possible {
 
         return (1,0) if ($empty_ok);
     }
+    $status[3] = $age_protect_only;
     return @status;
 }
 
@@ -2733,6 +2739,7 @@ sub _check_monopart_hold_is_possible {
     my $title;
     my %seen;
     my @status;
+    my $age_protect_only = 0;
     OUTER: for my $key (@keys) {
       my @cps = @{$buckets{$key}};
 
@@ -2754,6 +2761,7 @@ sub _check_monopart_hold_is_possible {
          @status = verify_copy_for_hold(
             $patron, $requestor, $title, $copy, $pickup_lib, $request_lib);
 
+         $age_protect_only ||= $status[3];
          last OUTER if $status[0];
       }
     }
@@ -2766,6 +2774,7 @@ sub _check_monopart_hold_is_possible {
 
         return (1,0) if ($empty_ok);
     }
+    $status[3] = $age_protect_only;
     return @status;
 }
 
@@ -2794,11 +2803,14 @@ sub _check_volume_hold_is_possible {
     ) unless @$copies;
 
     my @status;
+    my $age_protect_only = 0;
        for my $copy ( @$copies ) {
         @status = verify_copy_for_hold(
                        $patron, $requestor, $title, $copy, $pickup_lib, $request_lib );
+        $age_protect_only ||= $status[3];
         last if $status[0];
        }
+    $status[3] = $age_protect_only;
        return @status;
 }
 
@@ -2819,6 +2831,10 @@ sub verify_copy_for_hold {
             show_event_list     => 1
                } 
        );
+    my $age_protect_only = 0;
+    if (@$permitted == 1 && @$permitted[0]->{textcode} eq 'ITEM_AGE_PROTECTED') {
+        $age_protect_only = 1;
+    }
 
     return (
         (not scalar @$permitted), # true if permitted is an empty arrayref
@@ -2827,7 +2843,8 @@ sub verify_copy_for_hold {
                ($copy->circ_lib == $pickup_lib) and 
             ($copy->status == OILS_COPY_STATUS_AVAILABLE)
         ),
-        $permitted
+        $permitted,
+        $age_protect_only
     );
 }
 
index 5c95809..7f00cb6 100644 (file)
@@ -892,7 +892,12 @@ sub attempt_hold_placement {
                         $hdata->{hold_failed_event} = pop @$result;
                     }
 
-                    $hdata->{could_override} = $self->test_could_override($hdata->{hold_failed_event});
+                    if($result->{age_protected_copy}) {
+                        $hdata->{could_override} = 1;
+                        $hdata->{age_protect} = 1;
+                    } else {
+                        $hdata->{could_override} = $self->test_could_override($hdata->{hold_failed_event});
+                    }
                 }
             }
         }
index 87e2d40..6504906 100644 (file)
                                                 event_key = hdata.hold_failed_event.textcode;
 
                                                 # display:
-                                                FAIL_PART_MSG_MAP.$fail_part_key ||
-                                                EVENT_MSG_MAP.$event_key ||
-                                                l(hdata.hold_failed_event.desc) ||
-                                                hdata.hold_failed_event.payload.fail_part ||
-                                                hdata.hold_failed_event.textcode ||
-                                                (hdata.hold_local_alert ?
-                                                    l("There is already a copy available at your local library.") :
-                                                    l("Unknown problem")) | html
+                                                (hdata.age_protect ?
+                                                    l("All available copies are temporarily unavailable at your pickup library. Placing this hold could result in longer wait times.") :
+                                                    FAIL_PART_MSG_MAP.$fail_part_key ||
+                                                    EVENT_MSG_MAP.$event_key ||
+                                                    l(hdata.hold_failed_event.desc) ||
+                                                    hdata.hold_failed_event.payload.fail_part ||
+                                                    hdata.hold_failed_event.textcode ||
+                                                    (hdata.hold_local_alert ?
+                                                        l("There is already a copy available at your local library.") :
+                                                        l("Unknown problem"))) | html
                                             %]</em>
                                             [% IF event_key == 'PERM_FAILURE' %]
                                             <div>[% l('Permission: "[_1]"', hdata.hold_failed_event.ilsperm) | html %]</div>
index 545085a..7bcf044 100644 (file)
@@ -619,6 +619,7 @@ We recommend that you remove this title from any bookbags it may have been added
 <!ENTITY common.hold.checked_out.override "This item is already checked out.  Would you like to place the hold anyway?">
 <!ENTITY common.hold.exists "A hold already exists on the requested item.">
 <!ENTITY common.hold.exists.override "A hold already exists on the requested item. Would you like to create the hold anyway?">
+<!ENTITY common.hold.age_protect.override "This hold may take extra time to fill due to library policies. Would you like to create the hold anyway?">
 <!ENTITY common.hold.barred 'PATRON BARRED. Please see any notes in the
 "Staff Notes" section of your "My Account" page or contact your local library.'>
 <!ENTITY common.hold.item.invalid "This hold is no longer valid. It's likely that the
index 4c85368..df7bef4 100644 (file)
@@ -1022,28 +1022,40 @@ function holdHandleCreateResponse(r, recurse) {
 
        if(!recurse) {
                var res = r.getResultObject();
+        var age_protect_override = false;;
                if(checkILSEvent(res) || res.success != 1) {
-                       if(res.success != 1) {
-
-                if(!holdArgs.partsSuggestionMade && holdArgs.recordParts && 
-                        holdArgs.recordParts.length && holdArgs.type == 'T') {
-                    // T holds on records that have parts are OK, but if the record has no non-part
-                    // copies, the hold will ultimately fail.  Suggest selecting a part to the user.
-                    addCSSClass($('holds_parts_selector'), 'parts-warning');
-                    holdArgs.partsSuggestionMade = true;
-                    alert($('hold_has_parts').innerHTML);
+            if(res.success != 1 && res.age_protected_copy == 1) {
+                // There is at least one copy that *could* fill the hold, if it were not age-protected.
+                if( confirm($('hold_age_protected_override').innerHTML) ) {
+                    age_protect_override = true;
                 } else {
-                                   alert($('hold_not_allowed').innerHTML);
+                       swapCanvas($('holds_box'));
+                           return;
                 }
-                       } else {
-                               if( res.textcode == 'PATRON_BARRED' ) {
-                                       alertId('hold_failed_patron_barred');
-                       } else {
-                                       alert($('hold_not_allowed').innerHTML);
-                               }
-                       }
-                       swapCanvas($('holds_box'));
-                       return;
+            }
+            if(!age_protect_override) {
+                       if(res.success != 1) {
+
+                    if(!holdArgs.partsSuggestionMade && holdArgs.recordParts && 
+                            holdArgs.recordParts.length && holdArgs.type == 'T') {
+                        // T holds on records that have parts are OK, but if the record has no non-part
+                        // copies, the hold will ultimately fail.  Suggest selecting a part to the user.
+                        addCSSClass($('holds_parts_selector'), 'parts-warning');
+                        holdArgs.partsSuggestionMade = true;
+                        alert($('hold_has_parts').innerHTML);
+                    } else {
+                                   alert($('hold_not_allowed').innerHTML);
+                    }
+                       } else {
+                               if( res.textcode == 'PATRON_BARRED' ) {
+                                       alertId('hold_failed_patron_barred');
+                           } else {
+                                       alert($('hold_not_allowed').innerHTML);
+                               }
+                       }
+                       swapCanvas($('holds_box'));
+                           return;
+            }
                }
         r._hold.selection_depth(res.depth);
        }       
index 4930ab7..3b091b6 100644 (file)
 
        <span class='hide_me' id='hold_dup_exists_override'>&common.hold.exists.override;</span>
        <span class='hide_me' id='hold_checked_out_override'>&common.hold.checked_out.override;</span>
+       <span class='hide_me' id='hold_age_protected_override'>&common.hold.age_protect.override;</span>
 
        <span id='hold_failed_patron_barred' class='hide_me'>&common.hold.barred;</span>