Bug 7910: Add the ability to renew several subscriptions at once
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 18 Apr 2018 17:01:18 +0000 (14:01 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 24 Apr 2018 15:04:46 +0000 (12:04 -0300)
This patch adds a "Renew all selected subscriptions" action link on top
of the table of the "Check expiration" page.

It will allow to auto-renew several subscriptions.

Test plan:
Make sure this new link renew the selected subscriptions as expected.

Sponsored-by: BULAC - http://www.bulac.fr/
Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
koha-tmpl/intranet-tmpl/prog/en/modules/serials/checkexpiration.tt
koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt
serials/subscription-renew.pl

index 24a977c..d2bf124 100644 (file)
     [% END %]
         will expire before <b>[% date | $KohaDates %]</b>
 </p>
+
+<div class="checkexpiration-table_table_controls">
+    <a href="#" class="SelectAll"><i class="fa fa-check"></i> Select all</a> |
+    <a href="#" class="ClearAll"><i class="fa fa-remove"></i> Clear all</a>
+    <span class="itemselection_actions">
+      | Actions:
+          <a class="itemselection_action_renew" title="Renew selected subscriptions"><i class="fa fa-refresh"></i> Renew selected subscriptions</a>
+    </span>
+</div>
+
+
 <table>
         <tr>
+            <th></th>
             <th>ISSN</th>
             <th>Title</th>
             [% IF can_change_library %]<th>Library</th>[% END %]
@@ -73,6 +85,9 @@
         </tr>
     [% FOREACH subscriptions_loo IN subscriptions_loop %]
         <tr>
+            <td style="text-align:center;vertical-align:middle">
+                <input type="checkbox" value="[% subscriptions_loo.subscriptionid %]" name="subscriptionid" />
+            </td>
             <td>
                 [% subscriptions_loo.issn %]
             </td>
                 var subscriptionid = $(this).data("subscriptionid");
                 popup( subscriptionid );
             });
+            function itemSelectionBuildRenewLink() {
+                var subscription_ids= new Array();
+                $("input[name='subscriptionid'][type='checkbox']:checked").each(function() {
+                    subscription_ids.push($(this).val());
+                });
+                if (subscription_ids.length > 0) {
+                    var url = '/cgi-bin/koha/serials/subscription-renew.pl?op=multi_renew';
+                    url += '&subscriptionid=' + subscription_ids.join('&subscriptionid=');
+                    $('a.itemselection_action_renew').attr('href', url);
+                } else {
+                    return false;
+                }
+                return true;
+            }
+
+            function itemSelectionBuildActionLinks() {
+                var export_link_ok = itemSelectionBuildRenewLink();
+                if (export_link_ok) {
+                    $('.itemselection_actions').show();
+                } else {
+                    $('.itemselection_actions').hide();
+                }
+            }
+
+            itemSelectionBuildActionLinks();
+
+            $("input[name='subscriptionid'][type='checkbox']").change(function() {
+                itemSelectionBuildActionLinks();
+            });
+
+            $(".SelectAll, .ClearAll").on("click",function(e){
+                e.preventDefault();
+                var checkboxes = $(this).parent().siblings('table').first().find('input[type="checkbox"]');
+                checkboxes.prop('checked', $(this).hasClass('SelectAll'));
+                itemSelectionBuildActionLinks();
+            });
+
         });
         function popup(subscriptionid) {
            newin=window.open("subscription-renew.pl?mode=popup&subscriptionid="+subscriptionid,'popup','width=590,height=440,toolbar=false,scrollbars=yes,resize=yes');
index 6f854e7..3639e57 100644 (file)
@@ -1,18 +1,23 @@
 [% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
-<title>Koha &rsaquo; Serials subscription renew #[% subscriptionid %]</title>
+[% IF subscription %]
+<title>Koha &rsaquo; Serials subscription renew #[% subscription.subscriptionid %]</title>
+[% ELSE %]
+<title>Koha &rsaquo; Serials subscription renew</title>
+[% END %]
 [% INCLUDE 'doc-head-close.inc' %]
 </head>
 
 <body id="ser_subscription-renew" class="ser">
     <div class="container-fluid">
 
-[% IF ( renew ) %]
+[% IF op == 'renew' %]
   Subscription renewed.
   
 <script type="text/javascript">
 //<![CDATA[
-  opener.document.location.reload();
+  //opener.document.location.reload();
+  window.opener.location.reload(false);
   self.close();
   //]]>
 </script>
@@ -20,8 +25,8 @@
       <div id="bd">
 <form name="f" action="/cgi-bin/koha/serials/subscription-renew.pl" method="post">
                <input type="hidden" name="op" value="renew" />
-               <input type="hidden" name="subscriptionid" value="[% subscriptionid %]" />
-               <fieldset class="rows"><legend>Subscription renewal for [% bibliotitle %]</legend>
+               <input type="hidden" name="subscriptionid" value="[% subscription.subscriptionid %]" />
+               <fieldset class="rows"><legend>Subscription renewal for [% subscription.bibliotitle %]</legend>
         <ol>
             <li>
                 <label for="startdate">Start date: </label>
@@ -30,9 +35,9 @@
             </li>
                <li><fieldset>
                <legend>Subscription length:</legend>
-               <ol><li><label for="numberlength">Number of num:</label><input type="text" id="numberlength" name="numberlength" value="[% numberlength %]" /></li>
-               <li><label for="weeklength">Number of weeks: </label><input type="text" id="weeklength" name="weeklength" value="[% weeklength %]" /></li>
-               <li><label for="monthlength">Number of months: </label><input type="text" id="monthlength" name="monthlength" value="[% monthlength %]" /></li></ol></fieldset></li>
+               <ol><li><label for="numberlength">Number of num:</label><input type="text" id="numberlength" name="numberlength" value="[% subscription.numberlength %]" /></li>
+               <li><label for="weeklength">Number of weeks: </label><input type="text" id="weeklength" name="weeklength" value="[% subscription.weeklength %]" /></li>
+               <li><label for="monthlength">Number of months: </label><input type="text" id="monthlength" name="monthlength" value="[% subscription.monthlength %]" /></li></ol></fieldset></li>
                <li><label for="note">Note for the librarian that will manage your renewal request: </label>
                <textarea name="note" id="note" rows="5" cols="50"></textarea></li></ol></fieldset>
                <fieldset class="action"><input type="submit" value="Submit" class="button" /></fieldset>
index 06b03e2..836e612 100755 (executable)
@@ -60,7 +60,7 @@ my $dbh   = C4::Context->dbh;
 
 my $mode           = $query->param('mode') || q{};
 my $op             = $query->param('op') || 'display';
-my $subscriptionid = $query->param('subscriptionid');
+my @subscriptionids = $query->multi_param('subscriptionid');
 my $done = 0;    # for after form has been submitted
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
@@ -73,34 +73,44 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     }
 );
 if ( $op eq "renew" ) {
+    # Do not use this script with op=renew and @subscriptionids > 1!
+    my $subscriptionid = $subscriptionids[0];
     my $startdate = output_pref( { str => scalar $query->param('startdate'), dateonly => 1, dateformat => 'iso' } );
     ReNewSubscription(
         $subscriptionid, $loggedinuser,
-        $startdate, $query->param('numberlength'),
-        $query->param('weeklength'), $query->param('monthlength'),
-        $query->param('note')
+        $startdate, scalar $query->param('numberlength'),
+        scalar $query->param('weeklength'), scalar $query->param('monthlength'),
+        scalar $query->param('note')
     );
-}
+} elsif ( $op eq 'multi_renew' ) {
+    for my $subscriptionid ( @subscriptionids ) {
+        my $subscription = GetSubscription( $subscriptionid );
+        next unless $subscription;
+        ReNewSubscription(
+            $subscriptionid, $loggedinuser,
+            $subscription->{enddate}, $subscription->{numberlength},
+            $subscription->{weeklength}, $subscription->{monthlength},
+        );
+    }
+} else {
+    my $subscriptionid = $subscriptionids[0];
+    my $subscription = GetSubscription($subscriptionid);
+    if ($subscription->{'cannotedit'}){
+      carp "Attempt to renew subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
+      print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
+    }
 
-my $subscription = GetSubscription($subscriptionid);
-if ($subscription->{'cannotedit'}){
-  carp "Attempt to renew subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
-  print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
-}
+    my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } )
+        or output_pref( { dt => dt_from_string, dateonly => 1 } );
 
-my $newstartdate = output_pref( { str => $subscription->{enddate}, dateonly => 1 } )
-    or output_pref( { dt => dt_from_string, dateonly => 1 } );
+    $template->param(
+        startdate      => $newstartdate,
+        subscription   => $subscription,
+    );
+}
 
 $template->param(
-    startdate      => $newstartdate,
-    numberlength   => $subscription->{numberlength},
-    weeklength     => $subscription->{weeklength},
-    monthlength    => $subscription->{monthlength},
-    subscriptionid => $subscriptionid,
-    bibliotitle    => $subscription->{bibliotitle},
-    $op            => 1,
-    popup          => ($mode eq 'popup'),
+    op => $op,
 );
 
-# Print the page
 output_html_with_http_headers $query, $cookie, $template->output;