From 89eb96b8eaae3f0074c1bf69c1408a2dc9fa9073 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 23 Sep 2017 14:45:41 -0400 Subject: [PATCH] LP 1694058: OPAC changes for multiple title and metarecord holds. We add the num_copies select box to the place_holds.tt2 whe appropriate. The new select list generator has its own tt2 file: Open-ILS/src/templates/opac/parts/multi_hold_select.tt2 Modify WWW/EGCatLoader/Account.pm to properly process multiple hold requests for the same title or metarecord. Signed-off-by: Jason Stephenson Signed-off-by: Kathy Lussier --- .../lib/OpenILS/WWW/EGCatLoader/Account.pm | 44 +++++++++++++++++----- .../src/templates/opac/parts/multi_hold_select.tt2 | 15 ++++++++ Open-ILS/src/templates/opac/parts/place_hold.tt2 | 1 + 3 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 Open-ILS/src/templates/opac/parts/multi_hold_select.tt2 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 8295e12b51..6095f85ed8 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm @@ -1000,6 +1000,23 @@ sub load_place_hold { return $self->generic_redirect unless @targets; + # Check for multiple hold placement via the num_copies widget. + my $num_copies = int($cgi->param('num_copies')); # if undefined, we get 0. + if ($num_copies > 1) { + # Only if we have 1 hold target and no parts. + if (scalar(@targets) == 1 && !$parts[0]) { + # Also, only for M and T holds. + if ($ctx->{hold_type} eq 'M' || $ctx->{hold_type} eq 'T') { + # Add the extra holds to @targets. NOTE: We start with + # 1 and go to < $num_copies to account for the + # existing target. + for (my $i = 1; $i < $num_copies; $i++) { + push(@targets, $targets[0]); + } + } + } + } + $logger->info("Looking at hold_type: " . $ctx->{hold_type} . " and targets: @targets"); $ctx->{staff_recipient} = $self->editor->retrieve_actor_user([ @@ -1241,15 +1258,23 @@ sub load_place_hold { # like a real P-type hold. my (@p_holds, @t_holds); - for my $idx (0..$#parts) { - my $hdata = $hold_data[$idx]; - if (my $part = $parts[$idx]) { - $hdata->{target_id} = $part; - $hdata->{selected_part} = $part; - push(@p_holds, $hdata); - } else { - push(@t_holds, $hdata); + # Now that we have the num_copies field for mutliple title and + # metarecord hold placement, the number of holds and parts + # arrays can get out of sync. We only want to parse out parts + # if the numbers are equal. + if ($#hold_data == $#parts) { + for my $idx (0..$#parts) { + my $hdata = $hold_data[$idx]; + if (my $part = $parts[$idx]) { + $hdata->{target_id} = $part; + $hdata->{selected_part} = $part; + push(@p_holds, $hdata); + } else { + push(@t_holds, $hdata); + } } + } else { + @t_holds = @hold_data; } $self->apache->log->warn("$#parts : @t_holds"); @@ -1342,7 +1367,8 @@ sub attempt_hold_placement { last; } - my ($hdata) = grep {$_->{target_id} eq $resp->{target}} @hold_data; + # Skip those that had the hold_success or hold_failed fields set for duplicate holds placement. + my ($hdata) = grep {$_->{target_id} eq $resp->{target} && !($_->{hold_failed} || $_->{hold_success})} @hold_data; my $result = $resp->{result}; if ($U->event_code($result)) { diff --git a/Open-ILS/src/templates/opac/parts/multi_hold_select.tt2 b/Open-ILS/src/templates/opac/parts/multi_hold_select.tt2 new file mode 100644 index 0000000000..020245b9b3 --- /dev/null +++ b/Open-ILS/src/templates/opac/parts/multi_hold_select.tt2 @@ -0,0 +1,15 @@ +[% # Check if we need to do anything. + hold_type = CGI.param('hold_type'); + max_holds = ctx.get_org_setting(ctx.default_pickup_lib, 'circ.holds.max_duplicate_holds'); + can_dup = ctx.has_perm('CREATE_DUPLICATE_HOLDS', ctx.default_pickup_lib); + IF ctx.hold_data.size == 1 && (hold_type == 'M' || hold_type == 'T') && max_holds && max_holds > 1 && can_dup; +%] +

+ + +

+[% END %] diff --git a/Open-ILS/src/templates/opac/parts/place_hold.tt2 b/Open-ILS/src/templates/opac/parts/place_hold.tt2 index 76d8d9e11d..b40c34c5d0 100644 --- a/Open-ILS/src/templates/opac/parts/place_hold.tt2 +++ b/Open-ILS/src/templates/opac/parts/place_hold.tt2 @@ -157,6 +157,7 @@ function toggleActivationDate() { [% END %] [% END %] + [% INCLUDE "opac/parts/multi_hold_select.tt2" IF NOT (this_hold_disallowed AND hdata.part_required); %] [% IF NOT metarecords.disabled %] [% IF CGI.param('hold_type') == 'T' AND hdata.record.metarecord AND !hdata.part_required %] -- 2.11.0