Bug 23197: Add more batch operation options to SQL report results
authorOwen Leonard <oleonard@myacpl.org>
Mon, 24 Jun 2019 18:48:29 +0000 (18:48 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 15 Jul 2019 10:28:06 +0000 (11:28 +0100)
This patch extends the feature which allows the user to send item
numbers from a page of report results to batch item modification. For
biblionumbers: Batch record modification, batch record deletion, and
add to list are now available. For item numbers: batch item deletion is
added.

A new menu button is added for these options at the top of report
results, removing the button from the item number column header.
Corresponding CSS has been removed.

To test, apply the patch and create a report which includes both
biblionumber and itemnumber columns in the results.

 - Run the report and confirm that a new "Batch operations" button
   appears at the top of the results. Test each option:
   - Batch record modification
   - Batch record deletion
   - Add to list
   - Batch item modification
   - Batch item deletion

In each case the correct set of parameters should be passed to the batch
operations. Test with reports which return only biblionumbers, only
itemnumbers, and neither.

Signed-off-by: Maryse Simard <maryse.simard@inlibro.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

koha-tmpl/intranet-tmpl/prog/css/reports.css
koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt

index fa8e13e..ef60a95 100644 (file)
@@ -36,17 +36,6 @@ del {
     font-family: monospace;
 }
 
-.send_to_item_mod {
-    background-color: #EBF3FF;
-    border: 1px solid #88b0e8;
-    border-radius: 5px;
-    display: inline-block;
-    font-size: 75%;
-    margin: 3px 5px;
-    padding: 3px 5px;
-    white-space: nowrap;
-}
-
 .filter {
     background-color: #EBF3FF;
     border-radius: 5px;
index 58ff9e3..ba2dc6d 100644 (file)
@@ -731,6 +731,104 @@ canned reports and writing custom SQL reports.</p>
 </div>
 <div id="chart" class="clearfix"></div>
 
+[% IF ( execute ) %]
+    [% UNLESS ( errors ) %]
+        <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/tools/batch_record_modification.pl" id="batch_record_modification">
+            <input type="hidden" name="recordtype" value="biblio" />
+            <input type="hidden" name="op" value="list" />
+            [% # Preserve the whitespace of the following textarea in order to format the values correctly %]
+            <textarea style="display:none" name="recordnumber_list" id="recordnumber_list">[% FOREACH result IN results %][% FOREACH cells IN result.cells %][% place = loop.index %][% IF header_row.$place.cell == 'biblionumber' %][% SET batch_biblionumbers = 1 %]
+[% cells.cell | html %][% END %][% END %][% END %]</textarea>
+        </form>
+
+        <form method="POST" action="/cgi-bin/koha/tools/batch_delete_records.pl" id="batch_record_deletion">
+            <input type="hidden" name="recordtype" value="biblio" />
+            <input type="hidden" name="op" value="list" />
+            [% # Preserve the whitespace of the following textarea in order to format the values correctly %]
+            <textarea style="display:none" name="recordnumber_list" id="recordnumber_list">[% FOREACH result IN results %][% FOREACH cells IN result.cells %][% place = loop.index %][% IF header_row.$place.cell == 'biblionumber' %][% SET batch_biblionumbers = 1 %]
+[% cells.cell | html %][% END %][% END %][% END %]</textarea>
+        </form>
+
+        <form method="POST" action="/cgi-bin/koha/tools/batchMod.pl" id="batch_item_modification">
+            <input type="hidden" name="op" value="show" />
+            [% FOREACH result IN results %]
+                [% FOREACH cells IN result.cells %]
+                    [% place = loop.index %]
+                    [% IF header_row.$place.cell == 'itemnumber' %]
+                        [% SET batch_itemnumbers = 1 %]
+                        <input type="hidden" name="[% header_row.$place.cell | html %]" value="[% cells.cell | html %]" />
+                    [% END %]
+                [% END %]
+            [% END %]
+        </form>
+
+        <form method="POST" action="/cgi-bin/koha/tools/batchMod.pl" id="batch_item_deletion">
+            <input type="hidden" name="op" value="show" />
+            <input type="hidden" name="del" value="1" />
+            [% FOREACH result IN results %]
+                [% FOREACH cells IN result.cells %]
+                    [% place = loop.index %]
+                    [% IF header_row.$place.cell == 'itemnumber' %]
+                        [% SET batch_itemnumbers = 1 %]
+                        <input type="hidden" name="[% header_row.$place.cell | html %]" value="[% cells.cell | html %]" />
+                    [% END %]
+                [% END %]
+            [% END %]
+        </form>
+
+        <form method="get" action="/cgi-bin/koha/virtualshelves/addbybiblionumber.pl" id="batch_add_to_list">
+            [% FOREACH result IN results %]
+                [% FOREACH cells IN result.cells %]
+                    [% place = loop.index %]
+                    [% IF header_row.$place.cell == 'biblionumber' %]
+                        [% SET batch_biblionumbers = 1 %]
+                        <input type="hidden" class="bib_to_list" name="biblionumber" value="[% cells.cell | html %]" />
+                    [% END %]
+                [% END %]
+            [% END %]
+        </form>
+
+        [% IF ( batch_biblionumbers || batch_itemnumbers ) %]
+            <p>
+                <div class="dropdown">
+                    <button class="btn btn-default dropdown-toggle" type="button" id="batch_mod_menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
+                        Batch operations with [% IF unlimited_total > limit %][% limit | html %][% ELSE %][% unlimited_total | html %][% END %] visible records
+                        <span class="caret"></span>
+                    </button>
+                    <ul class="dropdown-menu" aria-labelledby="batch_mod_menu">
+                        [% FOREACH header_ro IN header_row %]
+                            [% IF header_ro.cell == 'biblionumber' %]
+                                <li class="dropdown-header">Bibliographic records</li>
+                                <li>
+                                    <a href="#" data-submit="batch_record_modification" data-toggle="tooltip" data-placement="right" title="Send visible records to batch record modification" class="batch_op send_to_record_mod">Batch record modification</a>
+                                </li>
+                                <li>
+                                    <a href="#" data-submit="batch_record_deletion" data-toggle="tooltip" data-placement="right" title="Send visible records to batch record deletion" class="batch_op send_to_record_del">Batch record deletion</a>
+                                </li>
+                                <li>
+                                    <a href="#" data-submit="batch_add_to_list" data-toggle="tooltip" data-placement="right" title="Send visible records to a list" class="batch_op send_to_list">Add to list</a>
+                                </li>
+                            [% END %]
+                            [% IF header_ro.cell == 'itemnumber' %]
+                                [% IF ( batch_biblionumbers ) %]
+                                    <li role="separator" class="divider"></li>
+                                [% END %]
+                                <li class="dropdown-header">Item records</li>
+                                <li>
+                                    <a href="#" data-submit="batch_item_modification" data-toggle="tooltip" data-placement="right" title="Send visible items to batch item modification" class="batch_op send_to_item_mod">Batch item modification</a>
+                                </li>
+                                <li>
+                                    <a href="#" data-submit="batch_item_deletion" data-toggle="tooltip" data-placement="right" title="Send visible items to batch item deletion" class="batch_op send_to_item_del">Batch item deletion</a>
+                                </li>
+                            [% END %]
+                        [% END %]
+                    </ul> <!-- /.dropdown-menu -->
+                </div> <!-- /.dropdown -->
+            </p>
+        [% END %]
+    [% END # UNLESS ( errors ) %]
+[% END # IF ( execute ) %]
+
 <form action="/cgi-bin/koha/reports/guided_reports.pl" method="get" id="limitselect">
     <input type="hidden" name="phase" value="Run this report"/>
     <input type="hidden" name="reports" value="[% report_id | html %]"/>
@@ -757,34 +855,20 @@ canned reports and writing custom SQL reports.</p>
 
 <div class="pages">[% pagination_bar | $raw %]</div>
 [% UNLESS ( errors ) %]
-    <form method="POST" action="/cgi-bin/koha/tools/batchMod.pl" id="report_results">
-        <input type="hidden" name="op" value="show" />
-        <table>
+    <table>
+        <tr>
+            [% FOREACH header_ro IN header_row %]
+                <th>[% header_ro.cell | html %]</th>
+            [% END %]
+        </tr>
+        [% FOREACH result IN results %]
             <tr>
-                [% FOREACH header_ro IN header_row %]
-                    [% IF header_ro.cell == 'itemnumber' %]
-                        <th>
-                            [% header_ro.cell | html %] <button type="submit" data-toggle="tooltip" title="Send visible items to batch modification" id="batchModify" class="btn btn-xs btn-default send_to_item_mod"><i class="fa fa-pencil"></i> Batch modify</button>
-                        </th>
-                    [% ELSE %]
-                        <th>[% header_ro.cell | html %]</th>
-                    [% END %]
+                [% FOREACH cells IN result.cells %]
+                    <td>[% cells.cell | $raw %]</td>
                 [% END %]
             </tr>
-            [% FOREACH result IN results %]
-                <tr>
-                    [% FOREACH cells IN result.cells %]
-                        [% place = loop.index %]
-                        [% IF header_row.$place.cell == 'itemnumber' %]
-                            <input type="hidden" name="[% header_row.$place.cell | html %]" value="[% cells.cell | html %]" />
-                        [% END %]
-                        <td>[% cells.cell | $raw %]</td>
-                    [% END %]
-                </tr>
-            [% END %]
-        </table>
-    </form>
-
+        [% END %]
+    </table>
 [% END %]
 
 [% INCLUDE 'chart.inc' %]
@@ -1426,6 +1510,17 @@ canned reports and writing custom SQL reports.</p>
                 $("#mana_result_content").html("");
                 $("#mana_search_field").val("");
             });
+
+            $(".batch_op").on("click", function(e){
+                e.preventDefault();
+                var target_form = $(this).data("submit");
+                $("#" + target_form ).submit();
+            });
+
+            $("#batch_add_to_list").on("submit", function(e){
+                e.preventDefault();
+                addToList();
+            });
         });
 
         function addColumn() {
@@ -1502,6 +1597,20 @@ canned reports and writing custom SQL reports.</p>
                     }
                 });
         }
+
+        function addToList() {
+            var biblionumbers = [];
+            $(".bib_to_list").each(function() {
+                var biblionumber = Number( $(this).val() );
+                if( biblionumbers.indexOf( biblionumber ) < 0 ){
+                    biblionumbers.push( biblionumber );
+                }
+            });
+            bibs = biblionumbers.join("/");
+            var url = "/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumbers=" + bibs;
+            window.open(url, 'Add_to_virtualshelf', 'width=500, height=400, toolbar=false, scrollbars=yes');
+            return false;
+        }
     </script>
 [% END %]