From 23d5d744472f7f5ce654b93ffe930a80bcb97d71 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 26 Jan 2011 17:14:40 -0500 Subject: [PATCH] initial support for renew all and renew selected, w/ stub template implementation; still some to-do's --- Open-ILS/src/perlmods/OpenILS/WWW/EGCatLoader.pm | 129 ++++++++++++++++----- .../web/templates/default/opac/myopac/circs.tt2 | 52 +++++---- 2 files changed, 128 insertions(+), 53 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/OpenILS/WWW/EGCatLoader.pm index 8468bdcb91..33e7675326 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/EGCatLoader.pm @@ -535,60 +535,127 @@ sub load_place_hold { } -sub load_myopac_circs { +sub fetch_user_circs { my $self = shift; + my $flesh = shift; # flesh bib data, etc. + my $circ_ids = shift; + my $limit = shift; + my $offset = shift; + my $e = $self->editor; - my $ctx = $self->ctx; - $ctx->{circs} = []; - my $limit = $self->cgi->param('limit') || 10; - my $offset = $self->cgi->param('offset') || 0; + my @circ_ids; - my $circ_data = $U->simplereq( - 'open-ils.actor', - 'open-ils.actor.user.checked_out', - $e->authtoken, - $e->requestor->id - ); + if($circ_ids) { + @circ_ids = @$circ_ids; - my @circ_ids = ( @{$circ_data->{overdue}}, @{$circ_data->{out}} ); - @circ_ids = grep { defined $_ } @circ_ids[0..($offset + $limit - 1)]; + } else { + + my $circ_data = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.checked_out', + $e->authtoken, + $e->requestor->id + ); + + @circ_ids = ( @{$circ_data->{overdue}}, @{$circ_data->{out}} ); + + if($limit or $offset) { + @circ_ids = grep { defined $_ } @circ_ids[0..($offset + $limit - 1)]; + } + } - return Apache2::Const::OK unless @circ_ids; + return [] unless @circ_ids; my $cstore = OpenSRF::AppSession->create('open-ils.cstore'); - my $req = $cstore->request( - 'open-ils.cstore.direct.action.circulation.search', - {id => \@circ_ids}, - { - flesh => 3, - flesh_fields => { - circ => ['target_copy'], - acp => ['call_number'], - acn => ['record'] - } + + my $qflesh = { + flesh => 3, + flesh_fields => { + circ => ['target_copy'], + acp => ['call_number'], + acn => ['record'] } - ); + }; + + $e->xact_begin; + my $circs = $e->search_action_circulation( + [{id => \@circ_ids}, ($flesh) ? $qflesh : {}], {substream => 1}); my @circs; - while(my $resp = $req->recv) { - my $circ = $resp->content; + for my $circ (@$circs) { push(@circs, { circ => $circ, - marc_xml => ($circ->target_copy->call_number->id == -1) ? - undef : # pre-cat copy, use the dummy title/author instead - XML::LibXML->new->parse_string($circ->target_copy->call_number->record->marc), + marc_xml => ($flesh and $circ->target_copy->call_number->id != -1) ? + XML::LibXML->new->parse_string($circ->target_copy->call_number->record->marc) : + undef # pre-cat copy, use the dummy title/author instead }); } + $e->xact_rollback; # make sure the final list is in the correct order + my @sorted_circs; for my $id (@circ_ids) { push( - @{$ctx->{circs}}, + @sorted_circs, (grep { $_->{circ}->id == $id } @circs) ); } + return \@sorted_circs; +} + + +sub handle_circ_renew { + my $self = shift; + my $action = shift; + 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); + + # TODO: fire off renewal calls in batches to speed things up + $ctx->{renewal_responses} = []; + for my $circ (@$circs) { + + my $resp = $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, + opac_renewal => 1 + } + ); + + # 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); + } + + return undef; +} + + +sub load_myopac_circs { + my $self = shift; + my $e = $self->editor; + my $ctx = $self->ctx; + + $ctx->{circs} = []; + my $limit = $self->cgi->param('limit') || 10; + 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/; + + $ctx->{circs} = $self->fetch_user_circs(1, undef, $limit, $offset); + return Apache2::Const::OK; } diff --git a/Open-ILS/web/templates/default/opac/myopac/circs.tt2 b/Open-ILS/web/templates/default/opac/myopac/circs.tt2 index 1ca1a4d137..33f3e3f46a 100644 --- a/Open-ILS/web/templates/default/opac/myopac/circs.tt2 +++ b/Open-ILS/web/templates/default/opac/myopac/circs.tt2 @@ -4,6 +4,7 @@ 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 } [% END %] @@ -11,29 +12,36 @@ [% WRAPPER "default/opac/base.tt2" %] [% INCLUDE "default/opac/myopac/_links.tt2" myopac_page = "circs" %] [% USE date %] - - - - - - - - - - - - [% FOR circ IN ctx.circs %] - [% attrs = {marc_xml => circ.marc_xml}; %] - [% PROCESS get_marc_attrs args=attrs; %] + + +
+ + +
+
TitleAuthorDue DateRenewals RemainingSelect
+ - - - - - + + + + + - [% END %] - -
[% attrs.title %][% attrs.author %][% date.format(ctx.parse_datetime(circ.circ.due_date),'%Y-%m-%d') %][% circ.circ.renewal_remaining %]XXX TODOTitleAuthorDue DateRenewals RemainingSelect
+ + + [% FOR circ IN ctx.circs %] + [% attrs = {marc_xml => circ.marc_xml}; %] + [% PROCESS get_marc_attrs args=attrs; %] + + [% attrs.title %] + [% attrs.author %] + [% date.format(ctx.parse_datetime(circ.circ.due_date),'%Y-%m-%d') %] + [% circ.circ.renewal_remaining %] + + + [% END %] + + + [% END %] -- 2.11.0