Bug 34478: Fixes for MARC modification template management

This patch converts several delete links to POSTed forms and corrects
the op variable names in the script. The patch also simplifies the
deletion click handlers.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Owen Leonard 2024-02-23 15:30:22 +00:00 committed by Jonathan Druart
parent 7798f0346c
commit 4e5944f7f9
No known key found for this signature in database
GPG Key ID: A085E712BEF0E0F0
3 changed files with 29 additions and 17 deletions

View File

@ -70,7 +70,12 @@
<a href="#" data-toggle="modal" data-template_id="" data-target="#createTemplate" id="new_template" class="btn btn-default duplicate_template"><i class="fa fa-plus"></i> New template</a>
[% IF ( template_id != '' ) %]
<a href="#" class="btn btn-default new_action"><i class="fa fa-plus"></i> New action</a>
<a class="btn btn-default delete_template" href="/cgi-bin/koha/tools/marc_modification_templates.pl?template_id=[% template_id | html %]&amp;op=delete_template"><i class="fa fa-fw fa-trash-can"></i> Delete template</a>
<form action="/cgi-bin/koha/tools/marc_modification_templates.pl" method="post">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="template_id" value="[% template_id | html %]" />
<input type="hidden" name="op" value="cud-delete_template" />
<button type="submit" class="btn btn-default confirm-delete-template"><i class="fa fa-fw fa-trash-can"></i> Delete template</button>
</form>
[% END %]
</div>
@ -103,7 +108,13 @@
<td class="actions">
<a class="btn btn-default btn-xs" href="/cgi-bin/koha/tools/marc_modification_templates.pl?template_id=[% TemplatesLoo.template_id | html %]&amp;op=select_template" ><i class="fa-fw fa-solid fa-pencil" aria-hidden="true"></i> Edit actions</a>
<a class="btn btn-default btn-xs duplicate_template" href="#" data-toggle="modal" data-template_id="[% TemplatesLoo.template_id | html %]" data-target="#createTemplate"><i class="fa fa-fw fa-copy"></i> Duplicate</a>
<a class="btn btn-default btn-xs delete_template" href="/cgi-bin/koha/tools/marc_modification_templates.pl?template_id=[% TemplatesLoo.template_id | html %]&amp;op=delete_template"><i class="fa fa-fw fa-trash-can"></i> Delete</a>
<form action="/cgi-bin/koha/tools/marc_modification_templates.pl" method="post">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="op" value="cud-delete_template">
<input type="hidden" name="template_id" value="[% TemplatesLoo.template_id | html %]" />
<button type="submit" class="btn btn-default btn-xs confirm-delete-template"><i class="fa fa-fw fa-trash-can"></i> Delete</button>
</form>
</td>
</tr>
[% END %]
@ -199,7 +210,13 @@
<a class="btn btn-default btn-xs edit_action" href="#modaction" data-mmta_id="[% ActionsLoo.mmta_id | html %]"><i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit</a>
</td>
<td>
<a class="btn btn-default btn-xs" href="marc_modification_templates.pl?template_id=[% ActionsLoo.template_id | html %]&op=delete_action&mmta_id=[% ActionsLoo.mmta_id | html %]" onclick="return confirmDeleteAction();"><i class="fa fa-trash-can"></i> Delete</a>
<form action="marc_modification_templates.pl" method="post">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="template_id" value="[% ActionsLoo.template_id | html %]" />
<input type="hidden" name="op" value="cud-delete_action" />
<input type="hidden" name="mmta_id" value="[% ActionsLoo.mmta_id | html %]" />
<button type="submit" class="btn btn-default btn-xs confirm-delete-action"><i class="fa fa-trash-can"></i> Delete</button>
</form>
</td>
</tr>
[% END # /FOREACH ActionsLoo %]

View File

@ -97,10 +97,6 @@ $(document).ready(function() {
}
});
$(".delete_template").on("click",function(){
return confirmDelete();
});
$(".edit_action").on("click", function(){
var mmta_id = $(this).data("mmta_id");
var mmta = $.grep(mmtas, function(elt, id) {
@ -113,6 +109,13 @@ $(document).ready(function() {
KohaTable("templatest", {
}, table_settings);
$(".confirm-delete-action").on("click", function(){
return confirm( __("Are you sure you wish to delete this template action?") );
});
$(".confirm-delete-template").on("click", function(){
return confirm( __("Are you sure you wish to delete this template?") );
});
});
function updateAllEvery(){
@ -261,14 +264,6 @@ function clearFormElements(divId) {
}
function confirmDeleteAction() {
return confirm( __("Are you sure you wish to delete this template action?") );
}
function confirmDelete() {
return confirm( __("Are you sure you wish to delete this template?") );
}
var modaction_legend_innerhtml;
var action_submit_value;

View File

@ -50,7 +50,7 @@ if ( $op eq "cud-create_template" ) {
$template_id = '' unless $cgi->param('duplicate_current_template');
$template_id = AddModificationTemplate( scalar $cgi->param('template_name'), $template_id );
} elsif ( $op eq "delete_template" ) {
} elsif ( $op eq "cud-delete_template" ) {
DelModificationTemplate( $template_id );
$template_id = '';
@ -108,7 +108,7 @@ if ( $op eq "cud-create_template" ) {
$template->param( error => 'no_from_field' );
}
} elsif ( $op eq "delete_action" ) {
} elsif ( $op eq "cud-delete_action" ) {
DelModificationTemplateAction( scalar $cgi->param('mmta_id') );
} elsif ( $op eq "move_action" ) {