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
appends a form for handling single entry deletions, populating
the hidden input upon confirmation.

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.
  - 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.
  - Check one or more checkboxes and then click a single "Remove from
    list" link. After confirming, you should find that only the one
    title was removed from the list.

Sponsored-by: Athens County Public Libraries
Signed-off-by: Eric Garcia <cubingguy714@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit ace488e50f)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Owen Leonard 2024-06-24 14:46:36 +00:00 committed by Lucas Gass
parent 2d038cfda5
commit b5daaf54fe
2 changed files with 20 additions and 11 deletions

View File

@ -52,7 +52,7 @@
[% IF ( shelf AND op == 'view' ) %]
<span class="actions"><a href="/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber=[% items.biblionumber | uri %]" class="addtoshelf btn btn-link btn-sm"><i class="fa fa-list" aria-hidden="true"></i> Save to another list</a></span>
[% IF can_remove_biblios %]
<span class="actions"><a class="btn btn-link btn-sm removeitems" data-biblionumber="[% items.biblionumber | html %]" href="/cgi-bin/koha/opac-shelves.pl?op=remove_biblios&amp;shelfnumber=[% shelf.shelfnumber | html %]&amp;biblionumber=[% items.biblionumber | html %]"><i class="fa fa-remove" aria-hidden="true"></i> Remove from this list</a></span>
<span class="actions"><a class="btn btn-link btn-sm removeitems" data-biblionumber="[% items.biblionumber | html %]" href="#"><i class="fa fa-remove" aria-hidden="true"></i> Remove from this list</a></span>
[% END %]
[% ELSE %]
<span class="actions"><a class="addtoshelf btn btn-link btn-sm" href="/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber=[% items.biblionumber | html %]"><i class="fa fa-list" aria-hidden="true"></i> Save to lists</a></span>

View File

@ -383,7 +383,7 @@
</span>
[% END %]
[% IF loggedinusername && can_remove_biblios %]
<span id="removeitems"></span>
<a href="#" class="btn btn-link disabled removeitems tag_hides"><i class="fa fa-fw fa-remove" aria-hidden="true"></i> Remove from list</a>
[% END %]
</div> <!-- / .links -->
</div> <!-- / .selections-toolbar -->
@ -547,6 +547,15 @@
<input type="submit" value="Remove selected items" id="remove-selected" class="btn btn-danger removeitems"/>
[% END %]
</form> <!-- /myform -->
[% IF can_manage_shelf %]
<form action="/cgi-bin/koha/opac-shelves.pl" method="post" id="shelf_delete_title">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="op" value="cud-remove_biblios" />
<input type="hidden" name="shelfnumber" value="[% shelf.shelfnumber | html %]" />
<input type="hidden" name="biblionumber" id="shelf_delete_biblionumber" value="" />
<input type="hidden" name="modifyshelfcontents" value="1" />
</form>
[% END %]
[% ELSE %]
<div id="toolbar" class="toolbar clearfix">
<div class="list-actions">
@ -985,16 +994,16 @@ $(function() {
[% IF loggedinusername && can_remove_biblios %]
$("body").on("click", ".removeitems", function(e){
e.preventDefault();
var href;
var title;
var yes_label;
var no_label;
var message = "";
var biblionumber;
/* Single "Remove from list" link has a biblionumber data-attribute */
if( $(this).data("biblionumber") ){
/* 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");
biblionumber = $(this).data("biblionumber");
} else {
var selected_titles = $(".cb:checked");
}
@ -1004,23 +1013,24 @@ $(function() {
if( selected_titles.size() > 1 ){
message = $("<ul></ul>");
title = _("Are you sure you want to remove these items from the list?");
yes_label = _("Yes, delete from list");
no_label = _("No, do not delete from list");
yes_label = _("Yes, remove from list");
no_label = _("No, do not remove from list");
selected_titles.each(function(){
message.append( "<li>" + $(this).data("title") + "</li>" );
});
} else {
title = _("Are you sure you want to remove this item from the list?");
yes_label = _("Yes, delete from list");
no_label = _("No, do not delete from list");
yes_label = _("Yes, remove from list");
no_label = _("No, do not remove from list");
selected_titles.each(function(){
message += $(this).data("title");
});
}
confirmModal( message, title, yes_label, no_label, function( result ){
if( result ){
if( href ){
location.href= href;
if( selected_titles.size() == 1 ){
$("#shelf_delete_biblionumber").val( biblionumber );
$("#shelf_delete_title").submit();
} else {
$("#myform").submit();
}
@ -1029,7 +1039,6 @@ $(function() {
}
});
$("#removeitems").html("<a href=\"#\" class=\"btn btn-link disabled removeitems tag_hides\"><i class=\"fa fa-fw fa-remove\" aria-hidden=\"true\"></i> "+_("Remove from list")+"</a>");
[% END %]
[% IF OpenLibraryCovers %]KOHA.OpenLibrary.GetCoverFromIsbn();[% END %]
[% IF OPACLocalCoverImages %]KOHA.LocalCover.GetCoverFromBibnumber(false);[% END %]