added perl bits for hold cancel/suspend/activate all/selected w/ sample tempate compo...
authorBill Erickson <berick@esilibrary.com>
Thu, 27 Jan 2011 17:10:49 +0000 (12:10 -0500)
committerBill Erickson <berick@esilibrary.com>
Thu, 27 Jan 2011 17:10:49 +0000 (12:10 -0500)
Open-ILS/src/perlmods/OpenILS/WWW/EGCatLoader.pm
Open-ILS/web/templates/default/opac/myopac/holds.tt2

index 785cd11..d544721 100644 (file)
@@ -429,24 +429,36 @@ sub load_myopac {
     return Apache2::Const::OK;
 }
 
-sub load_myopac_holds {
+
+sub fetch_user_holds {
     my $self = shift;
-    my $e = $self->editor;
-    my $ctx = $self->ctx;
+    my $hold_ids = shift;
+    my $ids_only = shift;
+    my $flesh = shift;
+    my $limit = shift;
+    my $offset = shift;
 
-    my $limit = $self->cgi->param('limit') || 0;
-    my $offset = $self->cgi->param('offset') || 0;
+    my $e = $self->editor;
 
     my $circ = OpenSRF::AppSession->create('open-ils.circ');
-    my $hold_ids = $circ->request(
-        'open-ils.circ.holds.id_list.retrieve', 
-        $e->authtoken, 
-        $e->requestor->id
-    )->gather(1);
 
-    $hold_ids = [ grep { defined $_ } @$hold_ids[$offset..($offset + $limit - 1)] ] if $limit or $offset;
+    if(!$hold_ids) {
+
+        $hold_ids = $circ->request(
+            'open-ils.circ.holds.id_list.retrieve.authoritative', 
+            $e->authtoken, 
+            $e->requestor->id
+        )->gather(1);
+    
+        $hold_ids = [ grep { defined $_ } @$hold_ids[$offset..($offset + $limit - 1)] ] if $limit or $offset;
+    }
+
+
+    return $hold_ids if $ids_only or @$hold_ids == 0;
 
     my $req = $circ->request(
+        # TODO .authoritative version is chewing up cstores
+        # 'open-ils.circ.hold.details.batch.retrieve.authoritative', 
         'open-ils.circ.hold.details.batch.retrieve', 
         $e->authtoken, 
         $hold_ids,
@@ -459,18 +471,75 @@ sub load_myopac_holds {
         }
     );
 
-    # any requests we can fire off here?
-    
-    $ctx->{holds} = []; 
+    my @holds;
     while(my $resp = $req->recv) {
         my $hold = $resp->content;
-        push(@{$ctx->{holds}}, {
+        push(@holds, {
             hold => $hold,
-            marc_xml => XML::LibXML->new->parse_string($hold->{bre}->marc)
+            marc_xml => ($flesh) ? XML::LibXML->new->parse_string($hold->{bre}->marc) : undef
         });
     }
 
     $circ->kill_me;
+    return \@holds;
+}
+
+sub handle_hold_update {
+    my $self = shift;
+    my $action = shift;
+    my $e = $self->editor;
+
+
+    my @hold_ids = $self->cgi->param('hold_id'); # for non-_all actions
+    @hold_ids = @{$self->fetch_user_holds(undef, 1)} if $action =~ /_all/;
+
+    my $circ = OpenSRF::AppSession->create('open-ils.circ');
+
+    if($action =~ /cancel/) {
+
+        for my $hold_id (@hold_ids) {
+            my $resp = $circ->request(
+                'open-ils.circ.hold.cancel', $e->authtoken, $hold_id, 6 )->gather(1); # 6 == patron-cancelled-via-opac
+        }
+
+    } else {
+        
+        my $vlist = [];
+        for my $hold_id (@hold_ids) {
+            my $vals = {id => $hold_id};
+
+            if($action =~ /activate/) {
+                $vals->{frozen} = 'f';
+                $vals->{thaw_date} = undef;
+
+            } elsif($action =~ /suspend/) {
+                $vals->{frozen} = 't';
+                # $vals->{thaw_date} = TODO;
+            }
+            push(@$vlist, $vals);
+        }
+
+        $circ->request('open-ils.circ.hold.update.batch.atomic', $e->authtoken, undef, $vlist)->gather(1);
+    }
+
+    $circ->kill_me;
+    return undef;
+}
+
+sub load_myopac_holds {
+    my $self = shift;
+    my $e = $self->editor;
+    my $ctx = $self->ctx;
+    
+
+    my $limit = $self->cgi->param('limit') || 0;
+    my $offset = $self->cgi->param('offset') || 0;
+    my $action = $self->cgi->param('action') || '';
+
+    $self->handle_hold_update($action) if $action;
+
+    $ctx->{holds} = $self->fetch_user_holds(undef, 0, 1, $limit, $offset);
+
     return Apache2::Const::OK;
 }
 
@@ -662,7 +731,6 @@ sub load_myopac_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';
@@ -687,7 +755,7 @@ sub load_myopac_fines {
 
     my $cstore = OpenSRF::AppSession->create('open-ils.cstore');
 
-    # TODO: This should really use a ML call, but the existing calls 
+    # TODO: This should really be 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) : ();
@@ -738,5 +806,4 @@ sub load_myopac_fines {
      return Apache2::Const::OK;
 }       
 
-
 1;
index 86df64b..8ac0be6 100644 (file)
@@ -4,6 +4,8 @@
     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%; }
+    #action-buttons { float:right; }
 </style>
 [% END %]
 
 [% PROCESS "default/opac/common.tt2" %]
 [% WRAPPER "default/opac/base.tt2" %]
 [% INCLUDE "default/opac/myopac/_links.tt2" myopac_page = "holds" %]
-<table>
-    <thead>
-        <tr>
-            <th>Title</th>
-            <th>Author</th>
-            <th>Formats</th>
-            <th>Pickup Location</th>
-            <th>Status</th>
-            <th>Active</th>
-            <th>Activate on...</th>
-            <th>Expiration Date</th>
-            <th>Select</th>
-            <th>Edit</th>
-        </tr>
-    </thead>
-    <tbody>
-        [% FOR hold IN ctx.holds %]
-            [% attrs = {marc_xml => hold.marc_xml}; %]
-            [% PROCESS get_marc_attrs args=attrs; %]
-        <tr>
-            <td>[% attrs.title %]</td>
-            <td>[% attrs.author %]</td>
-            <td>[% hold.hold.hold.holdable_formats %]<!-- see _myOPACFleshHoldTitle(), search for "mods_formats" in skin/default/js/myopac.js; holdable_formats is wrong --></td>
-            <td>[% ctx.find_aou(hold.hold.hold.pickup_lib).name %]</td>
-            <td>[% hold.hold.hold.status %]<!-- see myOShowHoldStatus() in skin/default/js/myopac.js --></td>
-            <td></td>
-            <td></td>
-            <td>[% hold.hold.hold.expire_time %]</td>
-            <td><em>XXX TODO</em></td>
-            <td><em>XXX TODO</em></td>
-        </tr>
-        [% END %]
-    </tbody>
-</table>
+<form method='POST'>
 
+    <div id='action_div'>
+        <div id='action-buttons'>
+            <select name='action'>
+                <option value='cancel'>Cancel Selected</option>
+                <option value='cancel_all'>Cancel All</option>
+                <option value='suspend'>Suspend Selected</option>
+                <option value='suspend_all'>Suspend All</option>
+                <option value='activate'>Activate Selected</option>
+                <option value='activate_all'>Activate All</option>
+            </select>
+            <input type='Submit' value='Go'/>
+        </div>
+    </div>
+
+    <table>
+        <thead>
+            <tr>
+                <th>Title</th>
+                <th>Author</th>
+                <th>Formats</th>
+                <th>Pickup Location</th>
+                <th>Status</th>
+                <th>Active</th>
+                <th>Activate on...</th>
+                <th>Expiration Date</th>
+                <th>Select</th>
+                <th>Edit</th>
+            </tr>
+        </thead>
+        <tbody>
+            [% FOR hold IN ctx.holds %]
+                [% attrs = {marc_xml => hold.marc_xml}; %]
+                [% PROCESS get_marc_attrs args=attrs; %]
+            <tr>
+                <td>[% attrs.title %]</td>
+                <td>[% attrs.author %]</td>
+                <td>[% hold.hold.hold.holdable_formats %]<!-- see _myOPACFleshHoldTitle(), search for "mods_formats" in skin/default/js/myopac.js; holdable_formats is wrong --></td>
+                <td>[% ctx.find_aou(hold.hold.hold.pickup_lib).name %]</td>
+                <td>[% hold.hold.hold.status %]<!-- see myOShowHoldStatus() in skin/default/js/myopac.js --></td>
+                <td>[% IF hold.hold.hold.frozen == 't' %] No [% ELSE %] Yes [% END %]</td>
+                <td>[% 
+                    IF hold.hold.hold.frozen == 't' AND hold.hold.hold.thaw_date;
+                        date.format(ctx.parse_datetime(hold.hold.hold.thaw_date),'%Y-%m-%d'); 
+                    END 
+                %]</td>
+                <td>[% hold.hold.hold.expire_time %]</td>
+                <td><input type='checkbox' name='hold_id' value='[% hold.hold.hold.id %]'/></td>
+                <td><em>XXX TODO</em></td>
+            </tr>
+            [% END %]
+        </tbody>
+    </table>
+</form> 
 [% END %]