Bug 34085: Remove the use of event attributes from basket groups template

This patch removes the use of event attributes (onclick, onsubmit) from
the basket groups template. These events are defined now along with the
other in-page JS.

This change allows us to move the scripts to the bottom of the page.

Unrelated changes: There was no confirmation tied to the process of
deleting a basket group. I've added one. And there were several "MSG_"
variables defined which were unused and have been removed.

To test you should have at least one vendor with at least one basket
group.

- Apply the patch and go to Acquisitions.
- Locate a vendor with an associated basket group.
- Edit a basketgroup
  - Confirm that editing works correctly (leaving "Close basket group"
    unchecked")
  - Confirm that editing works correctly with "Close basket group"
    checked.
- In the list of closed basket groups, confirm that all the controls
  work correctly.
- Create an empty basket group and confirm that clicking the associated
  "Delete" button in the list of basket groups triggers a confirmation,
  "Are you sure you want to delete this basket group?" Test that both
  confirming and cancelling work correctly.

Signed-off-by: David Cook <dcook@prosentient.com.au>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Owen Leonard 2023-06-21 17:24:20 +00:00 committed by Tomas Cohen Arazi
parent c23f36b812
commit 059e598f38
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -4,100 +4,15 @@
[% USE Price %]
[% USE Koha %]
[% PROCESS 'i18n.inc' %]
[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
<title>[% FILTER collapse %]
[% tx("Basket grouping for '{vendor}'", { vendor = booksellername }) %] &rsaquo;
[% t("Koha") | html %]
[% END %]</title>
[% INCLUDE 'doc-head-close.inc' %]
[% INCLUDE 'datatables.inc' %]
<script>
var MSG_CONFIRM_CLOSE_BASKETGROUP = _("Are you sure you want to close this basketgroup?");
var MSG_CLOSE_EMPTY_BASKET = _("Why close an empty basket?");
var MSG_SAVE_BEFORE_PRINTING = _("You need to save the page before printing");
var MSG_REOPEN_BASKETGROUP = _("reopen basketgroup");
var MSG_FILE_DOWNLOAD_ERROR = _("Error downloading the file");
function submitForm(form) {
if (form.close.checked == true) {
var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", "closed");
input.setAttribute("value", "1");
form.appendChild(input);
}
}
function closeandprint(bg){
if(document.location = '/cgi-bin/koha/acqui/basketgroup.pl?op=closeandprint&amp;basketgroupid=' + bg ){
setTimeout("window.location.reload();", 3000);
} else {
alert(MSG_FILE_DOWNLOAD_ERROR);
}
}
$(document).ready(function() {
[% IF ( listclosed) %]
$("#basket_groups a[href='#closed']").tab("show");
[% ELSE %]
$("#basket_groups a[href='#opened']").tab("show");
[% END %]
[% UNLESS ( grouping ) %]
$("table").dataTable($.extend(true, {}, dataTablesDefaults, {
"aoColumnDefs": [
{ "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
],
"bAutoWidth": false,
"sPaginationType": "full"
} ));
[% ELSE %]
grouped = $("#grouped").DataTable($.extend(true, {}, dataTablesDefaults, {
"dom": 't',
"columnDefs": [
{ 'sortable': false, 'targets': [ 'NoSort' ] }
],
'autoWidth': false,
"language": {
"emptyTable": _("There are no baskets in this group")
}
} ));
ungrouped = $("#ungrouped").DataTable($.extend(true, {}, dataTablesDefaults, {
"dom": 't',
"columnDefs": [
{ 'sortable': false, 'targets': [ 'NoSort' ] }
],
'autoWidth': false,
"language": {
"emptyTable": _("There are no ungrouped baskets")
}
} ));
[% END %]
$("#basketgroupcolumns").on("click", ".addtogroup", function(){
const row = $("#" + $(this).data("basketid") );
if( row ){
$(this).removeClass("addtogroup").addClass("removefromgroup").html("<i class=\"fa fa-trash-can\" aria-hidden=\"true\"></i> " + _("Remove") );
row.removeClass("ungrouped").addClass("grouped");
ungrouped.row( row ).remove().draw();
grouped.row.add( row ).draw();
}
});
$("#basketgroupcolumns").on("click", ".removefromgroup", function(){
const row = $("#" + $(this).data("basketid") );
if( row ){
$(this).removeClass("removefromgroup").addClass("addtogroup").html("<i class=\"fa fa-plus\" aria-hidden=\"true\"></i> " + _("Add to group") );
$(this).removeClass("").addClass("");
row.removeClass("grouped").addClass("ungrouped");
grouped.row( row ).remove().draw();
ungrouped.row.add( row ).draw();
}
});
});
</script>
</head>
<body id="acq_basketgroup" class="acq">
[% WRAPPER 'header.inc' %]
[% INCLUDE 'acquisitions-search.inc' %]
@ -205,7 +120,7 @@
[% ELSE %]
<div class="col-xs-6 col-xs-pull-6">
[% END %]
<form action="/cgi-bin/koha/acqui/basketgroup.pl" method="post" id="groupingform" onsubmit="return submitForm(this)">
<form action="/cgi-bin/koha/acqui/basketgroup.pl" method="post" id="groupingform">
<fieldset id="various" class="brief">
<ol>
[% UNLESS (closedbg) %]
@ -363,10 +278,10 @@
<td>[% IF (basketgroup.freedeliveryplace) %]Free delivery place[% ELSE %][% Branches.GetName( basketgroup.deliveryplace ) | html %][% END %]</td>
<td>[% basketgroup.basketsqty | html %]</td>
<td>
<input type="button" onclick="closeandprint('[% basketgroup.id | html %]');" value="Close and export as PDF" />
<input type="button" id="close_and_print" data-basketgroupid="[% basketgroup.id | html %]" value="Close and export as PDF" />
<form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="add" /><input type="hidden" name="booksellerid" value="[% basketgroup.booksellerid | html %]" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id | html %]" /><input type="submit" class="btn btn-primary" value="Edit" /></form>
[% UNLESS basketgroup.basketsqty %]
<form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="delete" /><input type="hidden" name="booksellerid" value="[% basketgroup.booksellerid | html %]" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id | html %]" /><input type="submit" class="btn btn-primary" value="Delete" /></form>
<form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="delete" /><input type="hidden" name="booksellerid" value="[% basketgroup.booksellerid | html %]" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id | html %]" /><input type="submit" id="delete_basketgroup" class="btn btn-primary" value="Delete" /></form>
[% END %]
</td>
</tr>
@ -410,7 +325,7 @@
<form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="export" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id | html %]" /><input type="submit" class="btn btn-primary" value="Export as CSV" /></form>
[% IF Koha.Preference('EDIFACT') %]
[% IF (ediaccount) %]
<form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="ediprint" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id | html %]" /><input type="submit" class="btn btn-primary" value="Generate EDIFACT order" /></form>
<form action="/cgi-bin/koha/acqui/basketgroup.pl" method="get"><input type="hidden" name="op" value="ediprint" /><input type="hidden" name="basketgroupid" value="[% basketgroup.id | html %]" /><input type="hidden" name="booksellerid" value="[% basketgroup.booksellerid | html %]" /><input type="submit" class="btn btn-primary" value="Generate EDIFACT order" /></form>
[% ELSE %]
<div>No EDIFACT configuration for [% booksellername | html %]</div>
[% END %]
@ -437,4 +352,102 @@
</aside>
</div>
</div> <!-- /.row -->
[% INCLUDE 'intranet-bottom.inc' %]
[% MACRO jsinclude BLOCK %]
[% INCLUDE 'datatables.inc' %]
<script>
\ function submitForm(form) {
if (form.closedbg.checked == true) {
var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", "closed");
input.setAttribute("value", "1");
form.appendChild(input);
}
form.submit();
}
function closeandprint(bg){
if(document.location = '/cgi-bin/koha/acqui/basketgroup.pl?op=closeandprint&amp;basketgroupid=' + bg ){
setTimeout("window.location.reload();", 3000);
} else {
alert( _("Error downloading the file") );
}
}
$(document).ready(function() {
[% IF ( listclosed) %]
$("#basket_groups a[href='#closed']").tab("show");
[% ELSE %]
$("#basket_groups a[href='#opened']").tab("show");
[% END %]
[% UNLESS ( grouping ) %]
$("table").dataTable($.extend(true, {}, dataTablesDefaults, {
"aoColumnDefs": [
{ "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
],
"bAutoWidth": false,
"sPaginationType": "full"
} ));
[% ELSE %]
grouped = $("#grouped").DataTable($.extend(true, {}, dataTablesDefaults, {
"dom": 't',
"columnDefs": [
{ 'sortable': false, 'targets': [ 'NoSort' ] }
],
'autoWidth': false,
"language": {
"emptyTable": _("There are no baskets in this group")
}
} ));
ungrouped = $("#ungrouped").DataTable($.extend(true, {}, dataTablesDefaults, {
"dom": 't',
"columnDefs": [
{ 'sortable': false, 'targets': [ 'NoSort' ] }
],
'autoWidth': false,
"language": {
"emptyTable": _("There are no ungrouped baskets")
}
} ));
[% END %]
$("#basketgroupcolumns").on("click", ".addtogroup", function(){
const row = $("#" + $(this).data("basketid") );
if( row ){
$(this).removeClass("addtogroup").addClass("removefromgroup").html("<i class=\"fa fa-trash-can\" aria-hidden=\"true\"></i> " + _("Remove") );
row.removeClass("ungrouped").addClass("grouped");
ungrouped.row( row ).remove().draw();
grouped.row.add( row ).draw();
}
});
$("#basketgroupcolumns").on("click", ".removefromgroup", function(){
const row = $("#" + $(this).data("basketid") );
if( row ){
$(this).removeClass("removefromgroup").addClass("addtogroup").html("<i class=\"fa fa-plus\" aria-hidden=\"true\"></i> " + _("Add to group") );
$(this).removeClass("").addClass("");
row.removeClass("grouped").addClass("ungrouped");
grouped.row( row ).remove().draw();
ungrouped.row.add( row ).draw();
}
});
$("#close_and_print").on("click", function(e){
e.preventDefault();
const basketgroupid = $(this).data("basketgroupid");
closeandprint( basketgroupid );
});
$("#groupingform").on("submit", function(e){
e.preventDefault();
submitForm(this);
});
$("#delete_basketgroup").on("click", function(e){
return confirm(_("Are you sure you want to delete this basket group?"));
});
});
</script>
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]