added support for reporting renewal responses in the template
authorBill Erickson <berick@esilibrary.com>
Thu, 27 Jan 2011 14:56:26 +0000 (09:56 -0500)
committerBill Erickson <berick@esilibrary.com>
Thu, 27 Jan 2011 14:56:26 +0000 (09:56 -0500)
Open-ILS/src/perlmods/OpenILS/WWW/EGCatLoader.pm
Open-ILS/web/templates/default/opac/myopac/circs.tt2

index 33e7675..785cd11 100644 (file)
@@ -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
         }
     );
 
index 33f3e3f..3c156cc 100644 (file)
@@ -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; }
 </style>
 [% END %]
 
 [% INCLUDE "default/opac/myopac/_links.tt2" myopac_page = "circs" %]
 [% USE date %]
 
-<form method='POST'>
+
+<form method='POST' id='circ-form'>
     <div id='action_div'>
-        <button type='submit' value='renew' name='action'>Renew Selected</button>
-        <button type='submit' value='renew_all' name='action'>Renew All</button>
+        [% IF ctx.success_renewals > 0 %]
+            <div class='renew-summary'><b>Successfully renewed [% ctx.success_renewals %] items.</b></div>
+        [% END %]
+        [% IF ctx.failed_renewals > 0 %]
+            <div class='renew-summary'><b>Failed to renew [% ctx.failed_renewals %] items.</b></div>
+        [% END %]
+        <div id='action-buttons'>
+            <button type='submit' value='renew' name='action'>Renew Selected</button>
+            <button type='submit' value='renew_all' name='action'>Renew All</button>
+        </div>
     </div>
     <table>
         <thead>
             [% FOR circ IN ctx.circs %]
                 [% attrs = {marc_xml => circ.marc_xml}; %]
                 [% PROCESS get_marc_attrs args=attrs; %]
-                <tr>
+                <tr [% IF loop.count % 2 == 1 %] class='circ-table-odd' [% END %]>
                     <td>[% attrs.title %]</td>
                     <td>[% attrs.author %]</td>
                     <td>[% date.format(ctx.parse_datetime(circ.circ.due_date),'%Y-%m-%d') %]</td>
                     <td><em>[% circ.circ.renewal_remaining %]</em></td>
                     <td><input name='circ' value='[% circ.circ.id %]' type='checkbox'/></td>
                 </tr>
+                [% IF circ.renewal_response and circ.renewal_response.textcode != 'SUCCESS' %]
+                <tr [% IF loop.count % 2 == 1 %] class='circ-table-odd' [% END %]>
+                    <td colspan='0'>
+                        <div class='failure-text'>
+                            [% 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 %]
+                        </div>
+                    </td>
+                </tr>
+                [% END %]
             [% END %]
         </tbody>
     </table>