From 777679e17299dcdcc135d493a2a9987c9357d9ff Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Mon, 18 Jul 2011 13:40:17 -0400 Subject: [PATCH] Alert or block holds on available copy at same pickup lib This improves upon the earlier commit that attempted to deal with what to do when either of these org_unit settings are true: circ.holds.hold_has_copy_at.alert circ.holds.hold_has_copy_at.block The correct use of these settings are that when /any/ type of hold is attempted at a given pickup lib, if either of those settings are true in the context of said pickup lib, and there are copies in an available status at the pickup lib already, inform the user before placing the hold. In the alert case, the user can place the hold anyway with another click. In the block case, there's an end on't. Signed-off-by: Lebbeous Fogle-Weekley --- .../lib/OpenILS/Application/Circ/Holds.pm | 6 +-- .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 54 +++++++++++++------ .../default/opac/parts/place_hold.tt2 | 18 ++++--- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm index 48abee9439..26b57f030c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm @@ -3353,15 +3353,15 @@ __PACKAGE__->register_method( 'available at the library where the user is placing the hold (or, alternatively, '. 'at the pickup library) to encourage bypassing the hold placement and just ' . 'checking out the item.' , - params => { + params => [ { desc => 'Authentication Token', type => 'string' }, { desc => 'Method Arguments. Options include: hold_type, hold_target, org_unit. ' . 'hold_type is the hold type code (T, V, C, M, ...). ' . 'hold_target is the identifier of the hold target object. ' . 'org_unit is org unit ID.', type => 'object' - }, - }, + } + ], return => { desc => q/Result hash like { "copy" : copy_id, "location" : location_name }, empty hash on misses, event on error./, type => 'object' diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm index a1f7178478..410d06a912 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -7,6 +7,8 @@ use OpenILS::Utils::Fieldmapper; use OpenILS::Application::AppUtils; use OpenILS::Event; use OpenSRF::Utils::JSON; +use Data::Dumper; +$Data::Dumper::Indent = 0; use DateTime; my $U = 'OpenILS::Application::AppUtils'; @@ -44,19 +46,37 @@ sub test_could_override { # Find out whether we care that local copies are available sub local_avail_concern { - my ($self, $allowed, $request_lib) = @_; - - my ($block, $alert); - if ($allowed->{"success"} and $allowed->{"local_avail"}) { - $block = $self->ctx->{get_org_setting}-> - ($request_lib, "circ.holds.hold_has_copy_at.block"); - $alert = ( - $self->ctx->{get_org_setting}-> - ($request_lib, "circ.holds.hold_has_copy_at.alert") - and not $self->cgi->param("override") + my ($self, $allowed, $hold_target, $hold_type, $pickup_lib) = @_; + + my $would_block = $self->ctx->{get_org_setting}-> + ($pickup_lib, "circ.holds.hold_has_copy_at.block"); + my $would_alert = ( + $self->ctx->{get_org_setting}-> + ($pickup_lib, "circ.holds.hold_has_copy_at.alert") and + not $self->cgi->param("override") + ) unless $would_block; + + if ($allowed->{"success"} and ($would_block or $would_alert)) { + my $args = { + "hold_target" => $hold_target, + "hold_type" => $hold_type, + "org_unit" => $pickup_lib + }; + my $local_avail = $U->simplereq( + "open-ils.circ", + "open-ils.circ.hold.has_copy_at", $self->editor->authtoken, $args + ); + $logger->info( + "copy availability information for " . Dumper($args) . + " is " . Dumper($local_avail) ); + if (%$local_avail) { # if hash not empty + $self->ctx->{hold_copy_available} = $local_avail; + return ($would_block, $would_alert); + } } - return ($block, $alert); + + return (0, 0); } # context additions: @@ -468,8 +488,13 @@ sub load_place_hold { $logger->info('hold permit result ' . OpenSRF::Utils::JSON->perl2JSON($allowed)); - my ($local_block, $local_alert) = - $self->local_avail_concern($allowed, $request_lib); + my ($local_block, $local_alert) = $self->local_avail_concern( + $allowed, $args->{$target_field}, $args->{hold_type}, $pickup_lib + ); + + # Give the original CGI params back to the user in case they + # want to try to override something. + $ctx->{orig_params} = $cgi->Vars; if ($local_block) { $ctx->{hold_failed} = 1; @@ -507,9 +532,6 @@ sub load_place_hold { } else { $ctx->{hold_failed} = 1; - # Give the original CGI params back to the user in case they - # want to try to override something. - $ctx->{orig_params} = $cgi->Vars; delete $ctx->{orig_params}{submit}; if (ref $stat eq 'ARRAY') { diff --git a/Open-ILS/web/templates/default/opac/parts/place_hold.tt2 b/Open-ILS/web/templates/default/opac/parts/place_hold.tt2 index e4304bde3c..4dcd278898 100644 --- a/Open-ILS/web/templates/default/opac/parts/place_hold.tt2 +++ b/Open-ILS/web/templates/default/opac/parts/place_hold.tt2 @@ -8,7 +8,9 @@
[% l("Hold was successfully placed"); %]
[% ELSIF ctx.hold_failed %]
[% l("Hold was not successfully placed"); %]
- [% IF ctx.hold_failed_event || ctx.hold_local_alert %] + [% IF ctx.hold_local_block %] +
[% l("There is already a copy available at your local library.") %]
+ [% ELSIF ctx.hold_failed_event || ctx.hold_local_alert %]
[% l('Problem:') %] @@ -16,10 +18,16 @@ ctx.hold_failed_event.payload.fail_part || ctx.hold_failed_event.textcode || (ctx.hold_local_alert ? - l("There is already a copy available at your local library") : - l("Unknown problem")) %] + l("There is already a copy available at your local library.") : + l("Unknown problem")) %] - [% IF ctx.could_override %] + + [% IF ctx.hold_copy_available %]

+ [% l('Find a copy in the shelving location, "[_1]."', + ctx.hold_copy_available.location) %] +

[% END %] + + [% IF ctx.could_override || ctx.hold_local_alert %]

[% l("You have permission to place this hold anyway.") %]
@@ -276,8 +284,6 @@ -

[% l("Hold was successfully placed") %]
-
[% l("Hold was not successfully placed") %]
[% l("The phone number does not have the correct format. The expected format is XXX-YYY-ZZZZ") %] -- 2.43.2