From 5fa75b0eab4bd516e87b0ee541806b262127e5bf Mon Sep 17 00:00:00 2001
From: Emmi Takkinen <emmi.takkinen@koha-suomi.fi>
Date: Wed, 5 Mar 2025 10:09:02 +0200
Subject: [PATCH 15/15] Bug 36135: Batch clear hold notes and use select2 in
 multiple filters

This patch adds ability to clear hold note from all selected
holds. It also adds select2 to libraries and holds status
filters.
---
 .../prog/en/modules/tools/batch_modify_holds.tt    | 14 ++++++++++++++
 tools/batch_modify_holds.pl                        |  5 +++++
 2 files changed, 19 insertions(+)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_modify_holds.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_modify_holds.tt
index ce5900c01f..d1493f81a1 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_modify_holds.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_modify_holds.tt
@@ -136,6 +136,7 @@
                                         <th>Suspend holds</th>
                                         <th>Suspend until</th>
                                         <th>New hold note</th>
+                                        <th>Clear hold notes</th>
                                     </tr>
                                 </thead>
                                 <tbody>
@@ -162,6 +163,9 @@
                                         <td>
                                            <input type="text" id="new_hold_note" name="new_hold_note"/>
                                         </td>
+                                        <td>
+                                           <input class="selection" type="checkbox" id="clear_hold_notes" name="clear_hold_notes" value="1"/>
+                                        </td>
                                     </tr>
                                 </tbody>
                             </table> <!-- /#modify_holds_options -->
@@ -185,6 +189,7 @@
     [% Asset.js("js/tools-menu.js") | $raw %]
     [% INCLUDE 'calendar.inc' %]
     [% INCLUDE 'datatables.inc' %]
+    [% INCLUDE 'select2.inc' %]
     [% INCLUDE 'js-patron-format.inc' %]
     [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
     <script>
@@ -192,6 +197,14 @@
         let hold_ids = [% IF updated_holds %] [% updated_holds | $raw %] [% ELSE %] [] [% END %];
 
         $(document).ready(function() {
+
+            // Apply select2 to all select fields having a "multiple" attribute
+            let selectFields = document.querySelectorAll('select[multiple]');
+            selectFields.forEach((selectField) => {
+                selectField.style.minWidth = '200px';
+                $(selectField).select2();
+            });
+
             //Empty local storage from previous selections
             localStorage.removeItem("holds_modify_selections");
 
@@ -493,6 +506,7 @@
                 var new_suspend_status  = $("#new_suspend_status").val();
                 var new_suspend_date    = $("#new_suspend_date").val();
                 var new_hold_note       = $("#new_hold_note").val();
+                var clear_hold_notes    = $("#clear_hold_notes").val();
 
                 if ( holds_checked.length == 0 ) {
                     e.preventDefault();
diff --git a/tools/batch_modify_holds.pl b/tools/batch_modify_holds.pl
index 5d76d8e6f0..9f0da01cae 100755
--- a/tools/batch_modify_holds.pl
+++ b/tools/batch_modify_holds.pl
@@ -51,6 +51,7 @@ if ( $op eq 'form' ) {
     my $new_suspend_status  = $input->param('new_suspend_status');
     my $new_suspend_date    = $input->param('new_suspend_date');
     my $new_hold_note       = $input->param('new_hold_note');
+    my $clear_hold_notes    = $input->param('clear_hold_notes');
 
     @hold_ids = $input->multi_param('hold_id');
 
@@ -84,6 +85,10 @@ if ( $op eq 'form' ) {
         if ($new_hold_note) {
             $hold->reservenotes($new_hold_note)->store;
         }
+
+        if ($clear_hold_notes) {
+            $hold->reservenotes(undef)->store;
+        }
     }
 
     $template->param(
-- 
2.34.1