From ba79ed803c3e7c7cf33a99d8b0a3760e45450d51 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Tue, 15 Jul 2025 12:41:32 +0000 Subject: [PATCH] Bug 40395: Preparation: Move holds table JS from request.tt to holds.js This is so that tables from patron-detail-tabs.inc can also make use of this JS --- .../prog/en/modules/reserve/request.tt | 73 ------ koha-tmpl/intranet-tmpl/prog/js/holds.js | 221 ++++++++++++++++++ 2 files changed, 221 insertions(+), 73 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index f4a01f47bc9..abf5ccefb28 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -1429,8 +1429,6 @@ pickupNotInHoldGroup: _("Only pickup locations within the same hold group are allowed") } - var MSG_CANCEL_SELECTED = _("Cancel selected (%s)"); - var MSG_CANCEL_ALERT = _("This action will cancel %s hold(s)."); $.fn.select2.defaults.set("width", "100%" ); $.fn.select2.defaults.set("dropdownAutoWidth", true ); @@ -1749,21 +1747,6 @@ $("#" + fieldID).val(""); }); - // Confirm cancellation of hold - let cancel_link; - $(".cancel-hold").on("click",function(e) { - e.preventDefault; - cancel_link = $(this); - $("#cancel_modal_form #inputs").empty(); - let reserve_id = cancel_link.data('id'); - let biblionumber = cancel_link.data('biblionumber'); - $("#cancel_modal_form #inputs").append(''); - $("#cancel_modal_form #inputs").append(''); - $("#cancel_modal_form #inputs").append(''); - $('#cancelModal').modal('show'); - return false; - }); - [% UNLESS ( patron || patron.borrowernumber || borrowers || noitems || nobiblio ) %] [% IF ( PatronAutoComplete ) %] patron_autocomplete($(".search_patron_filter"), { 'link-to': 'reserve', 'url-params': '[% url_biblio_params | url %]' }); @@ -1780,62 +1763,6 @@ }); [% END %] - if(!localStorage.selectedHolds || document.referrer.replace(/\?.*/, '') !== document.location.origin+document.location.pathname) { - localStorage.selectedHolds = []; - } - - $('.holds_table .select_hold').each(function() { - if(localStorage.selectedHolds.includes($(this).data('id'))) { - $(this).prop('checked', true); - } - }); - - $('.holds_table .select_hold_all').each(function() { - var table = $(this).parents('.holds_table'); - var count = $('.select_hold:not(:checked)', table).length; - $('.select_hold_all', table).prop('checked', !count); - }); - - $('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length)); - - $('.holds_table .select_hold_all').click(function() { - var table = $(this).parents('.holds_table'); - var count = $('.select_hold:checked', table).length; - $('.select_hold', table).prop('checked', !count); - $(this).prop('checked', !count); - $('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length)); - $('#cancel_hold_alert').html( MSG_CANCEL_ALERT.format($('.holds_table .select_hold:checked').length)); - $('#cancel_hold_alert').show(); - localStorage.selectedHolds = $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id')); - }); - - $('.holds_table .select_hold').click(function() { - var table = $(this).parents('.holds_table'); - var count = $('.select_hold:not(:checked)', table).length; - $('.select_hold_all', table).prop('checked', !count); - $('.cancel_selected_holds').html(MSG_CANCEL_SELECTED.format($('.holds_table .select_hold:checked').length)); - $('#cancel_hold_alert').html( MSG_CANCEL_ALERT.format($('.holds_table .select_hold:checked').length)); - $('#cancel_hold_alert').show(); - localStorage.selectedHolds = $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id')); - }); - - $('.cancel_selected_holds').click(function(e) { - e.preventDefault(); - if($('.holds_table .select_hold:checked').length) { - cancel_link = $(this); - $("#cancel_modal_form #inputs").empty(); - biblionumbers.forEach( function(biblionumber){ - $("#cancel_modal_form #inputs").append(''); - }); - $("#cancel_modal_form #inputs").append(''); - let hold_ids= $('.holds_table .select_hold:checked').toArray().map(el => $(el).data('id')).join(','); - $("#cancel_modal_form #inputs").append(''); - delete localStorage.selectedHolds; - $('#cancelModal').modal('show'); - } - return false; - }); - $(".hold-arrow").click(function(e) { e.preventDefault(); let arrowForm = $("#hold-actions-form").attr({ diff --git a/koha-tmpl/intranet-tmpl/prog/js/holds.js b/koha-tmpl/intranet-tmpl/prog/js/holds.js index 752e0f5b6ab..8e3acf7b1ac 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/holds.js +++ b/koha-tmpl/intranet-tmpl/prog/js/holds.js @@ -686,6 +686,25 @@ $(document).ready(function () { ]; return toggle_suspend(this, inputs); }); + + var MSG_SUSPEND_SELECTED = _("Suspend selected (%s)"); + var MSG_SUSPEND_SELECTED_HOLDS = _("Suspend selected holds"); + $(".suspend_selected_holds").html( + MSG_SUSPEND_SELECTED.format( + $(".holds_table .select_hold:checked").length + ) + ); + + $(".suspend_selected_holds").click(function (e) { + e.preventDefault(); + if (!$(".holds_table .select_hold:checked").length) { + return false; + } + $(".modal-title").html(MSG_SUSPEND_SELECTED_HOLDS); + $("#suspend-modal").modal("show"); + return false; + }); + $(".unsuspend-hold").on("click", function (e) { e.preventDefault(); let inputs = [ @@ -697,4 +716,206 @@ $(document).ready(function () { ]; return toggle_suspend(this, inputs); }); + + var MSG_CANCEL_SELECTED = _("Cancel selected (%s)"); + var MSG_CANCEL_ALERT = _( + "This action will cancel %s hold(s)." + ); + + // Confirm cancellation of hold + let cancel_link; + $(document).on("click", ".cancel-hold", function (e) { + e.preventDefault; + cancel_link = $(this); + $("#cancel_modal_form #inputs").empty(); + let reserve_id = cancel_link.data("id"); + let biblionumber = cancel_link.data("biblionumber"); + if (!patron_page) { + $("#cancel_modal_form #inputs").append( + '' + ); + $("#cancel_modal_form #inputs").append( + '' + ); + $("#cancel_modal_form #inputs").append( + '' + ); + } else { + _append_patron_page_cancel_hold_modal_data({ + hold: reserve_id, + biblionumber: biblionumber, + borrowernumber: cancel_link.data("borrowernumber"), + }); + } + $("#cancelModal").modal("show"); + return false; + }); + + if ( + !localStorage.selectedHolds || + document.referrer.replace(/\?.*/, "") !== + document.location.origin + document.location.pathname + ) { + localStorage.selectedHolds = []; + } + + $(".holds_table .select_hold").each(function () { + if (localStorage.selectedHolds.includes($(this).data("id"))) { + $(this).prop("checked", true); + } + }); + + if (!patron_page) { + $(".holds_table .select_hold_all").each(function () { + var table = $(this).parents(".holds_table"); + var count = $(".select_hold:not(:checked)", table).length; + $(".select_hold_all", table).prop("checked", !count); + }); + } + + function updateSelectedHoldsButtonCounters() { + $(".cancel_selected_holds").html( + MSG_CANCEL_SELECTED.format( + $(".holds_table .select_hold:checked").length + ) + ); + $(".suspend_selected_holds").html( + MSG_SUSPEND_SELECTED.format( + $(".holds_table .select_hold:checked").length + ) + ); + } + + updateSelectedHoldsButtonCounters(); + + $(".holds_table .select_hold_all").click(function () { + var table; + if (!patron_page) { + table = $(this).parents(".holds_table"); + } else { + table = $(".holds_table:not(.fixedHeader-floating)"); + } + var count = $(".select_hold:checked", table).length; + $(".select_hold", table).prop("checked", !count); + $(this).prop("checked", !count); + updateSelectedHoldsButtonCounters(); + $("#cancel_hold_alert").html( + MSG_CANCEL_ALERT.format( + $(".holds_table .select_hold:checked").length + ) + ); + $("#cancel_hold_alert").show(); + localStorage.selectedHolds = + "[" + + $(".holds_table .select_hold:checked") + .toArray() + .map(el => + JSON.stringify({ + hold: $(el).data("id"), + borrowernumber: $(el).data("borrowernumber"), + biblionumber: $(el).data("biblionumber"), + }) + ) + .join(",") + + "]"; + }); + + $(".holds_table").on("click", ".select_hold", function () { + var table = $(this).parents(".holds_table"); + var count = $(".select_hold:not(:checked)", table).length; + $(".select_hold_all", table).prop("checked", !count); + updateSelectedHoldsButtonCounters(); + $("#cancel_hold_alert").html( + MSG_CANCEL_ALERT.format( + $(".holds_table .select_hold:checked").length + ) + ); + $("#cancel_hold_alert").show(); + localStorage.selectedHolds = + "[" + + $(".holds_table .select_hold:checked") + .toArray() + .map(el => + JSON.stringify({ + hold: $(el).data("id"), + borrowernumber: $(el).data("borrowernumber"), + biblionumber: $(el).data("biblionumber"), + }) + ) + .join(",") + + "]"; + }); + + $(".cancel_selected_holds").click(function (e) { + e.preventDefault(); + if ($(".holds_table .select_hold:checked").length) { + $("#cancel_modal_form #inputs").empty(); + if (!patron_page) { + biblionumbers.forEach(function (biblionumber) { + $("#cancel_modal_form #inputs").append( + '' + ); + }); + $("#cancel_modal_form #inputs").append( + '' + ); + let hold_ids = $(".holds_table .select_hold:checked") + .toArray() + .map(el => $(el).data("id")) + .join(","); + $("#cancel_modal_form #inputs").append( + '' + ); + } else { + $("#cancel_modal_form #inputs").append( + '' + ); + let hold_data = + "[" + + $(".holds_table .select_hold:checked") + .toArray() + .map(el => + JSON.stringify({ + hold: $(el).data("id"), + borrowernumber: $(el).data("borrowernumber"), + biblionumber: $(el).data("biblionumber"), + }) + ) + .join(",") + + "]"; + JSON.parse(hold_data).forEach(function (hold) { + _append_patron_page_cancel_hold_modal_data(hold); + }); + } + + delete localStorage.selectedHolds; + $("#cancelModal").modal("show"); + } + return false; + }); + + function _append_patron_page_cancel_hold_modal_data(hold) { + $("#cancel_modal_form #inputs").append( + '' + ); + $("#cancel_modal_form #inputs").append( + '' + ); + $("#cancel_modal_form #inputs").append( + '' + ); + $("#cancel_modal_form #inputs").append( + '' + ); + } }); -- 2.39.5