From 5ba60088817b071e1fb392b260d6123acd9d3e8b Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Fri, 14 Feb 2025 13:15:37 +0200 Subject: [PATCH 14/14] Bug 36135: Save state of selected checkboxes and fix modifying suspend --- .../en/modules/tools/batch_modify_holds.tt | 317 +++++++++++------- 1 file changed, 190 insertions(+), 127 deletions(-) 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 c92914f9cb..ce5900c01f 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 @@ -118,7 +118,11 @@
Select all visible rows | Clear selections -
+ +

Holds found for:

@@ -188,21 +192,53 @@ let hold_ids = [% IF updated_holds %] [% updated_holds | $raw %] [% ELSE %] [] [% END %]; $(document).ready(function() { + //Empty local storage from previous selections + localStorage.removeItem("holds_modify_selections"); + + $("#holds_to_modify").on("change", "input[type='checkbox']", function(){ + var holds_modify_selections = JSON.parse(localStorage.getItem("holds_modify_selections")) || []; + var hold_id = $(this).val(); + if ($(this).prop("checked")) { + holds_modify_selections.push($(this).val()); + localStorage.setItem("holds_modify_selections", JSON.stringify(holds_modify_selections)); + showHoldSelections(holds_modify_selections.length); + } else { + var filtered = holds_modify_selections.filter(function( value ){ + return value !== hold_id; + }); + if( filtered.length > 0 ){ + localStorage.setItem("holds_modify_selections", JSON.stringify( filtered )); + holds_modify_selections = filtered; + showHoldSelections( filtered.length ); + } else { + holds_modify_selections = []; + localStorage.removeItem("holds_modify_selections"); + showHoldSelections( 0 ); + } + } + }); - $("#select_all").click(function(e){ + $("#select_all").on("click", function(e){ e.preventDefault(); $("#holds_to_modify input[type='checkbox']").each(function(){ - $(this).prop("checked", true); + $(this).prop("checked", true).change(); }); }); - $("#clear_all").click(function(e){ + $("#clear_all").on("click", function(e){ e.preventDefault(); $("#holds_to_modify input[type='checkbox']").each(function(){ - $(this).prop("checked", false); + $(this).prop("checked", false).change(); }); }); + $("#clear-row-selection").on("click", function (e) { + e.preventDefault(); + $("input[type='checkbox']").prop("checked", false).change(); + localStorage.removeItem("holds_modify_selections"); + $("#table_search_selections").hide(); + }); + $('#modify_holds_form').submit(function() { var modify_holds_form = $(this); search_holds(modify_holds_form); @@ -217,6 +253,30 @@ $('#edit_search').hide(); }); + function prepSelections(){ + let holds_modify_selections = JSON.parse( localStorage.getItem("holds_modify_selections") ) || []; + if( holds_modify_selections.length > 0 ){ + showHoldSelections( holds_modify_selections.length ); + $("#holds_to_modify input[type='checkbox']").each(function(){ + var hold_id = $(this).val(); + if( holds_modify_selections.indexOf( hold_id ) >= 0 ){ + $(this).prop("checked", true ); + } + }); + } + } + + function showHoldSelections( number ){ + if (number === 0) { + $("#table_search_selections").hide(); + } else { + $("#table_search_selections") + .show() + .find("span") + .text(__("Holds selected: %s").format(number)); + } + } + function search_holds(modify_holds_form){ var table_settings = [% TablesSettings.GetTableSettings( 'circ', 'holds', 'holds_to_modify', 'json' ) | $raw %]; var searchpattern = ""; @@ -308,7 +368,7 @@ "name": "checkbox", "orderable": false, "render": function(data, type, row, meta) { - return '' + return '' } }, { @@ -372,7 +432,7 @@ } else if( data == "W" ) { status = _("Waiting"); } - return status; + return "" + status + ""; } }, { @@ -411,7 +471,10 @@ return escape_str( data ); } } - ] + ], + "drawCallback": function( settings ) { + prepSelections(); + }, }, table_settings, 0, filters); $(".searchpattern").text(searchpattern); @@ -439,7 +502,7 @@ if( new_pickup_loc || new_suspend_status ){ var found = false; holds_checked.each(function(){ - if($(this).parents("tr").children(".found_status").html() !== "No status"){ + if($(this).parents("tr").children(".found_status").children("span").data("found-status")){ e.preventDefault(); found = true; } @@ -468,131 +531,131 @@ //Modified holds table var table_settings = [% TablesSettings.GetTableSettings( 'circ', 'holds', 'modified_holds', 'json' ) | $raw %]; - var filters = { - "me.hold_id": function(){ - return {"-in": hold_ids}; - } + var filters = { + "me.hold_id": function(){ + return {"-in": hold_ids}; } + } - var holds_modified_table = $("#modified_holds").kohaTable({ - "ajax": { - "url": "/api/v1/holds" + var holds_modified_table = $("#modified_holds").kohaTable({ + "ajax": { + "url": "/api/v1/holds" + }, + "embed": [ + "biblio", + "item", + "pickup_library", + "patron" + ], + "destroy": true, + "autoWidth": false, + "processing": true, + "columns": [ + { + "data": "expiration_date", + "name": "expiration_date", + "type": "date", + "title": _("Expiration date"), + "orderable": true, + "render": function( data, type, row, meta ) { + return $date(data); + } }, - "embed": [ - "biblio", - "item", - "pickup_library", - "patron" - ], - "destroy": true, - "autoWidth": false, - "processing": true, - "columns": [ - { - "data": "expiration_date", - "name": "expiration_date", - "type": "date", - "title": _("Expiration date"), - "orderable": true, - "render": function( data, type, row, meta ) { - return $date(data); - } - }, - { - "data": "biblio.title", - "name": "title", - "title": _("Title"), - "orderable": true, - "render": function( data, type, row, meta ) { - return '' + escape_str( data ) + ''; - } - }, - { - "data": "item.external_id", - "name": "barcode", - "title": _("Barcode"), - "defaultContent": _(""), - "orderable": true, - "render": function( data, type, row, meta ) { - if( row.item ){ - let item_id = encodeURIComponent( row.item_id ); - let biblio_id = encodeURIComponent( row.biblio_id ); - return '' + escape_str( data ) + '' - } - } - }, - { - "data": "patron_id", - "name": "patron", - "title": _("Patron"), - "orderable": true, - "render": function( data, type, row, meta ) { - let patron_to_html = $patron_to_html(row.patron, { url: true, display_cardnumber: true, hide_patron_name }); - return patron_to_html; - } - }, - { - "data": "status", - "name": "status", - "className": "found_status", - "title": _("Status"), - "orderable": true, - "render": function( data, type, row, meta ) { - let status = _("No status"); - if ( data == "T" ) { - status = _("In transit"); - } else if( data == "P" ) { - status = _("In processing"); - } else if( data == "W" ) { - status = _("Waiting"); - } - return status; - } - }, - { - "data": "pickup_library_id", - "name": "pickup_library", - "title": _("Hold pickup library"), - "orderable": true, - "render": function( data, type, row, meta ) { - return escape_str( row.pickup_library.name ); - } - }, - { - "data": "suspended", - "name": "suspended", - "title": _("Suspended"), - "orderable": true, - "render": function( data, type, row, meta ) { - return data == 0 ? _("No") : _("Yes"); - } - }, - { - "data": "suspended_until", - "name": "suspended_until", - "title": _("Suspended until"), - "orderable": true, - "render": function( data, type, row, meta ) { - return $date( data ); + { + "data": "biblio.title", + "name": "title", + "title": _("Title"), + "orderable": true, + "render": function( data, type, row, meta ) { + return '' + escape_str( data ) + ''; + } + }, + { + "data": "item.external_id", + "name": "barcode", + "title": _("Barcode"), + "defaultContent": _(""), + "orderable": true, + "render": function( data, type, row, meta ) { + if( row.item ){ + let item_id = encodeURIComponent( row.item_id ); + let biblio_id = encodeURIComponent( row.biblio_id ); + return '' + escape_str( data ) + '' } - }, - { - "data": "notes", - "name": "notes", - "title": _("Notes"), - "orderable": true, - "render": function( data, type, row, meta ) { - return escape_str( data ); + } + }, + { + "data": "patron_id", + "name": "patron", + "title": _("Patron"), + "orderable": true, + "render": function( data, type, row, meta ) { + let patron_to_html = $patron_to_html(row.patron, { url: true, display_cardnumber: true, hide_patron_name }); + return patron_to_html; + } + }, + { + "data": "status", + "name": "status", + "className": "found_status", + "title": _("Status"), + "orderable": true, + "render": function( data, type, row, meta ) { + let status = _("No status"); + if ( data == "T" ) { + status = _("In transit"); + } else if( data == "P" ) { + status = _("In processing"); + } else if( data == "W" ) { + status = _("Waiting"); } + return status; } - ] - }, table_settings, 0, filters); + }, + { + "data": "pickup_library_id", + "name": "pickup_library", + "title": _("Hold pickup library"), + "orderable": true, + "render": function( data, type, row, meta ) { + return escape_str( row.pickup_library.name ); + } + }, + { + "data": "suspended", + "name": "suspended", + "title": _("Suspended"), + "orderable": true, + "render": function( data, type, row, meta ) { + return data == 0 ? _("No") : _("Yes"); + } + }, + { + "data": "suspended_until", + "name": "suspended_until", + "title": _("Suspended until"), + "orderable": true, + "render": function( data, type, row, meta ) { + return $date( data ); + } + }, + { + "data": "notes", + "name": "notes", + "title": _("Notes"), + "orderable": true, + "render": function( data, type, row, meta ) { + return escape_str( data ); + } + } + ] + }, table_settings, 0, filters); - var modified_message = '
'+hold_ids.length+' hold(s) have been modified!
'; - $("#modified_holds_results-wrapper").prepend(modified_message); + var modified_message = '
'+hold_ids.length+' hold(s) have been modified!
'; + $("#modified_holds_results-wrapper").prepend(modified_message); }); -- 2.34.1