From 869a732c9944f9fdc336db9628b41b1c546723fd Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 27 Jan 2011 09:56:26 -0500 Subject: [PATCH] added support for reporting renewal responses in the template --- Open-ILS/src/perlmods/OpenILS/WWW/EGCatLoader.pm | 46 +++++++++++++++------- .../web/templates/default/opac/myopac/circs.tt2 | 37 ++++++++++++++--- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/OpenILS/WWW/EGCatLoader.pm index 33e7675326..785cd11204 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/EGCatLoader.pm @@ -7,6 +7,7 @@ use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERR use OpenSRF::AppSession; use OpenSRF::EX qw/:try/; use OpenSRF::Utils qw/:datetime/; +use OpenSRF::Utils::JSON; use OpenSRF::Utils::Logger qw/$logger/; use OpenILS::Application::AppUtils; use OpenILS::Utils::CStoreEditor qw/:funcs/; @@ -433,7 +434,7 @@ sub load_myopac_holds { my $e = $self->editor; my $ctx = $self->ctx; - my $limit = $self->cgi->param('limit') || 10; + my $limit = $self->cgi->param('limit') || 0; my $offset = $self->cgi->param('offset') || 0; my $circ = OpenSRF::AppSession->create('open-ils.circ'); @@ -443,7 +444,7 @@ sub load_myopac_holds { $e->requestor->id )->gather(1); - $hold_ids = [ grep { defined $_ } @$hold_ids[$offset..($offset + $limit - 1)] ]; + $hold_ids = [ grep { defined $_ } @$hold_ids[$offset..($offset + $limit - 1)] ] if $limit or $offset; my $req = $circ->request( 'open-ils.circ.hold.details.batch.retrieve', @@ -612,21 +613,20 @@ sub handle_circ_renew { my $ctx = $self->ctx; my @renew_ids = $self->cgi->param('circ'); - $self->apache->log->warn("renewal ids: @renew_ids"); - my $circs = $self->fetch_user_circs(1, ($action eq 'renew') ? [@renew_ids] : undef); + my $circs = $self->fetch_user_circs(0, ($action eq 'renew') ? [@renew_ids] : undef); # TODO: fire off renewal calls in batches to speed things up - $ctx->{renewal_responses} = []; + my @responses; for my $circ (@$circs) { - my $resp = $U->simplereq( + my $evt = $U->simplereq( 'open-ils.circ', 'open-ils.circ.renew', $self->editor->authtoken, { patron_id => $self->editor->requestor->id, - copy_id => $circ->{circ}->target_copy->id, + copy_id => $circ->{circ}->target_copy, opac_renewal => 1 } ); @@ -634,10 +634,10 @@ sub handle_circ_renew { # TODO return these, then insert them into the circ data # blob that is shoved into the template for each circ # so the template won't have to match them - push(@{$ctx->{renewal_responses}}, $resp); + push(@responses, {copy => $circ->{circ}->target_copy, evt => $evt}); } - return undef; + return @responses; } @@ -647,15 +647,32 @@ sub load_myopac_circs { my $ctx = $self->ctx; $ctx->{circs} = []; - my $limit = $self->cgi->param('limit') || 10; + my $limit = $self->cgi->param('limit') || 0; # 0 == unlimited my $offset = $self->cgi->param('offset') || 0; my $action = $self->cgi->param('action') || ''; # perform the renewal first if necessary - $self->handle_circ_renew($action) if $action =~ /renew/; + my @results = $self->handle_circ_renew($action) if $action =~ /renew/; $ctx->{circs} = $self->fetch_user_circs(1, undef, $limit, $offset); + my $success_renewals = 0; + my $failed_renewals = 0; + for my $data (@{$ctx->{circs}}) { + my ($resp) = grep { $_->{copy} == $data->{circ}->target_copy->id } @results; + + if($resp) { + #$self->apache->log->warn("renewal response: " . OpenSRF::Utils::JSON->perl2JSON($resp)); + my $evt = ref($resp->{evt}) eq 'ARRAY' ? $resp->{evt}->[0] : $resp->{evt}; + $data->{renewal_response} = $evt; + $success_renewals++ if $evt->{textcode} eq 'SUCCESS'; + $failed_renewals++ if $evt->{textcode} ne 'SUCCESS'; + } + } + + $ctx->{success_renewals} = $success_renewals; + $ctx->{failed_renewals} = $failed_renewals; + return Apache2::Const::OK; } @@ -665,7 +682,7 @@ sub load_myopac_fines { my $ctx = $self->ctx; $ctx->{transactions} = []; - my $limit = $self->cgi->param('limit') || 10; + my $limit = $self->cgi->param('limit') || 0; my $offset = $self->cgi->param('offset') || 0; my $cstore = OpenSRF::AppSession->create('open-ils.cstore'); @@ -673,6 +690,8 @@ sub load_myopac_fines { # TODO: This should really use a ML call, but the existing calls # return an excessive amount of data and don't offer streaming + my %paging = ($limit or $offset) ? (limit => $limit, offset => $offset) : (); + my $req = $cstore->request( 'open-ils.cstore.direct.money.open_billable_transaction_summary.search', { @@ -690,8 +709,7 @@ sub load_myopac_fines { acn => ['record'] }, order_by => { mobts => 'xact_start' }, - limit => $limit, - offset => $offset + %paging } ); diff --git a/Open-ILS/web/templates/default/opac/myopac/circs.tt2 b/Open-ILS/web/templates/default/opac/myopac/circs.tt2 index 33f3e3f46a..3c156cc130 100644 --- a/Open-ILS/web/templates/default/opac/myopac/circs.tt2 +++ b/Open-ILS/web/templates/default/opac/myopac/circs.tt2 @@ -3,8 +3,12 @@ table { width: 100%; text-align: center; padding: 20px; margin-top: 30px; } table { border-collapse: collapse; } table { padding: 3px; border-bottom: 1px solid #ddd; text-align: left;} - table tr:nth-child(odd) { background-color:#ded; } - #action_div { width: 95%; text-align: right } + #action_div { width: 95%; } + .renew-summary { float:left; padding-right: 10px;} + #action-buttons { float:right; } + .circ-table-odd { background-color:#ded; } + .failure-text { font-weight: bold; color: red; } + #circ-form { margin-top: 20px; } [% END %] @@ -13,10 +17,19 @@ [% INCLUDE "default/opac/myopac/_links.tt2" myopac_page = "circs" %] [% USE date %] -
+ +
- - + [% IF ctx.success_renewals > 0 %] +
Successfully renewed [% ctx.success_renewals %] items.
+ [% END %] + [% IF ctx.failed_renewals > 0 %] +
Failed to renew [% ctx.failed_renewals %] items.
+ [% END %] +
+ + +
@@ -32,13 +45,25 @@ [% FOR circ IN ctx.circs %] [% attrs = {marc_xml => circ.marc_xml}; %] [% PROCESS get_marc_attrs args=attrs; %] - + + [% IF circ.renewal_response and circ.renewal_response.textcode != 'SUCCESS' %] + + + + [% END %] [% END %]
[% attrs.title %] [% attrs.author %] [% date.format(ctx.parse_datetime(circ.circ.due_date),'%Y-%m-%d') %] [% circ.circ.renewal_remaining %]
+
+ [% circ.renewal_response.textcode %] + [% IF circ.renewal_response.payload.fail_part and circ.renewal_response.payload.fail_part != circ.renewal_response.textcode %] + [% circ.renewal_response.payload.fail_part %] + [% END %] +
+
-- 2.11.0