From edf1440ccf53af3cf8cdacd949bfe71f80facd96 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 21 Jun 2024 12:32:41 +0000 Subject: [PATCH] Bug 37150: Can't delete single title from a list using the "Remove from list" link In the OPAC display of titles on a list, the "Remove from list" control needs to trigger a POST operation instead of GET. This patch achieves this by using the existing form, automatically checking the checkbox corresponding to the "Remove" link which has been clicked. To test, apply the patch and create a list if necessary, adding multiple titles to it. - View the contents of your list. - Each title on your list should have a "Remove from this list" link. - Click one of these. You should see a modal confirmation, "Are you sure you want to remove this item from the list?" - Confirming should delete the title form the list. - Cancelling should close the modal and uncheck the title's checkbox * I include automatic un-checking of the checkbox because the user didn't "deliberately" check the box, and I want to avoid having that title included with "deliberately" checked items. - Check multiple checkboxes in the list of titles and click "Remove from list" at the top of the list. - You should see a modal confirmation, "Are you sure you want to remove these items from the list?" - Confirming should result in all checked titles being removed from the list. - Cancelling should hide the modal, and your checked checkboxes should remain the same. Sponsored-by: Athens County Public Libraries --- .../bootstrap/en/modules/opac-shelves.tt | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt index 0686b5d506..6deb5a5af4 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -983,20 +983,23 @@ $(function() { [% END %] [% IF loggedinusername && can_remove_biblios %] + let single_bib; + let selected_titles; $("body").on("click", ".removeitems", function(e){ e.preventDefault(); - var href; + single_bib = $(this).data("biblionumber"); var title; var yes_label; var no_label; var message = ""; /* Single "Remove from list" link has a biblionumber data-attribute */ - if( $(this).data("biblionumber") ){ + if( single_bib ){ /* Use the checkbox with that value to preview the title in the confirmation */ - var selected_titles = $(".cb[value='" + $(this).data("biblionumber") + "'"); - var href = $(this).attr("href"); + selected_titles = $(".cb[value='" + single_bib + "'"); + /* Check the box automatically so we can submit the form from the modal */ + selected_titles.prop("checked", true ); } else { - var selected_titles = $(".cb:checked"); + selected_titles = $(".cb:checked"); } if ( selected_titles.size() < 1 ) { alert( _("No item was selected") ); @@ -1019,15 +1022,17 @@ $(function() { } confirmModal( message, title, yes_label, no_label, function( result ){ if( result ){ - if( href ){ - location.href= href; - } else { - $("#myform").submit(); - } + $("#myform").submit(); } }); } }); + $("body").on("hidden.bs.modal", "#bootstrap-confirm-box-modal", function(){ + /* If the user clicked a single "Remove from list" link, uncheck the checkbox */ + if( single_bib ){ + selected_titles.prop("checked", false ); + } + }); $("#removeitems").html(" "+_("Remove from list")+""); [% END %] -- 2.39.2