Bug 31921: Add confirmation modal when deleting a vendor

This patch adds a new modal for confirming vendor deletion. It fixes
the previous functionality, showing a confirmation modal for each
vendor and appropriately handling the response.

To test:
1) Visit Acquisitions home. Under where it says 'Manage orders', click
   the search bar to bring up the list of vendors.
2) Add a few vendors by clicking 'New' and 'Vendor'. After this, go back
   to the vendor search so that all the vendors are showing.
3) For each vendor, click on 'Delete vendor' and ensure the modal shows
   properly.
4) Attempt to delete one of the vendors. Go back to the vendor search
   and ensure they are deleted correctly.
5) Click on a vendor's name to go their supplier page. Make sure modal
   works properly and attempt to delete a vendor from here.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Sam Lau 2024-07-09 15:20:57 +00:00 committed by Katrin Fischer
parent 538c943faa
commit 81af57344d
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
5 changed files with 34 additions and 10 deletions

View file

@ -23,12 +23,7 @@
</div>
[% UNLESS ( basketcount OR subscriptioncount ) %]
<div class="btn-group">
<form action="/cgi-bin/koha/acqui/supplier.pl" method="post">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="op" value="cud-delete" />
<input type="hidden" name="booksellerid" value="[% booksellerid | html %]" />
<button class="btn btn-default" id="deletesupplier" type="submit"><i class="fa fa-trash-can"></i> Delete vendor</button>
</form>
<button type="button" data-toggle="modal" data-target="#deleteVendorModal" data-booksellerid="[% booksellerid | html %]" class="btn btn-default"><i class="fa fa-trash-can"></i> Delete vendor</button>
</div>
[% END %]
[% END %]

View file

@ -0,0 +1,23 @@
<!-- Delete Vendor modal form -->
<div id="deleteVendorModal" class="modal" tabindex="-1" role="dialog" aria-labelledby="deleteVendorModalLabel">
<form method="post" action="/cgi-bin/koha/acqui/supplier.pl">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="op" value="cud-delete" />
<input type="hidden" name="booksellerid" id="booksellerid" value="" />
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="deleteVendorModalLabel">Delete vendor</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this vendor?</p>
</div>
<div class="modal-footer">
<button id="deleteVendorModaConfirmBtn" class="btn btn-primary"><i class="fa fa-check" aria-hidden="true"></i> Yes</button>
<button id="deleteVendorModaCancelBtn"data-dismiss="modal" class="btn btn-secondary"><i class="fa fa-times" aria-hidden="true"></i> No</button>
</div>
</div>
</div>
</form>
</div>

View file

@ -208,7 +208,7 @@
<a class="btn btn-default btn-xs" id="addtoBasketLabel[% basket.basketno | html %]" href="#addtoBasket[% basket.basketno | html %]" role="button" data-toggle="modal"><i class="fa fa-plus"></i> Add to basket</a>
[% END %]
<!-- Modal -->
<div id="addtoBasket[% basket.basketno | html %]" class="modal" tabindex="-1" role="dialog" aria-labelledby="addtoBasketLabel[% basket.basketno | html %]" aria-hidden="true" data-basketno="[% basket.basketname | html %]">
<div id="addtoBasket[% basket.basketno | html %]" class="modal add_to_basket" tabindex="-1" role="dialog" aria-labelledby="addtoBasketLabel[% basket.basketno | html %]" aria-hidden="true" data-basketno="[% basket.basketname | html %]">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
@ -257,6 +257,8 @@
</div>
</div> <!-- /.row -->
[% INCLUDE 'modals/delete_vendor.inc' %]
[% MACRO jsinclude BLOCK %]
[% Asset.js("js/acquisitions-menu.js") | $raw %]
[% INCLUDE 'datatables.inc' %]
@ -277,7 +279,7 @@
var id = $(this).find("option:selected").val();
window.location.href = "#vendor" + id;
});
$(".modal").on("shown.bs.modal", function(){
$(".add_to_basket").on("shown.bs.modal", function(){
var basket = $(this).data("basketno");
var legend = _("Add order to basket %s").format(basket);
$(this).find("h4").text( legend );

View file

@ -524,6 +524,8 @@
</aside>
</div> <!-- /.col-sm-2.col-sm-pull-10 -->
</div> <!-- /.row -->
[% INCLUDE 'modals/delete_vendor.inc' %]
[% MACRO jsinclude BLOCK %]
[% Asset.js("js/acquisitions-menu.js") | $raw %]
[% Asset.js("lib/hc-sticky/hc-sticky.js") | $raw %]

View file

@ -389,7 +389,9 @@ function hideAllColumns(){
}
$(document).ready(function(){
$("#deletesupplier").on("click", function(){
confirmDelete(__("Are you sure you want to delete this vendor?") );
$("#deleteVendorModal").on("shown.bs.modal", function(e){
var button = $(e.relatedTarget);
var item = button.data('booksellerid');
$('#booksellerid').val(item);
});
});