From b1e6627652a3cb39c29b4f7234f4cf73c3075282 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 13 Jul 2015 17:34:53 +0100 Subject: [PATCH] Bug 13943: Prevent the deletion of items if the user cancels On the edit items page, there is some weird JS code: if the user clicks on the delete link and then cancel, the item is deleted anyway. Test plan: - Do a search with multiple results - Go to the detail page (make sure results browser shows up!) - Use the "Edit items" link from the toolbar - Delete item (try both way) - Choose "cancel" Note: Before this patch, the 2 first columns didn't contain the edit/delete item links, now it's only the 1st one. --- .../prog/en/modules/cataloguing/additem.tt | 43 +++++++++++----------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index ab9621b..dbcc7aa 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -21,17 +21,24 @@ $(document).ready(function(){ [% END %] [% END %] $("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit"); - /* Inline edit/delete links */ - var biblionumber = $("input[name='biblionumber']").attr("value"); - $("tr.editable td").click(function(event){ - var $tgt = $(event.target); - if($tgt.is("a")||$tgt.is(":first-child")||$tgt.is(":nth-child(2)")){ return true; } else { - var rowid = $(this).parent().attr("id"); - num_rowid = rowid.replace("row",""); - $(".linktools").remove(); - $(this).append("" + _("Edit item") + " " + _("Delete item") + ""); - } - }); + /* Inline edit/delete links */ + var biblionumber = $("input[name='biblionumber']").attr("value"); + $("tr.editable").each(function(){ + $(this).find("td:not(:first)").on('click', function(){ + var rowid = $(this).parent().attr("id"); + num_rowid = rowid.replace("row",""); + $(".linktools").remove(); + var edit_link = $('' + _("Edit item") + ''); + var delete_link = $('' + _("Delete item") + ''); + $(delete_link).on('click', function(e) { + return confirm_deletion(); + }); + var tools_node = $(''); + $(tools_node).append(edit_link); + $(tools_node).append(delete_link); + $(this).append(tools_node); + }); + }); var itemst = $("#itemst").dataTable($.extend(true, {}, dataTablesDefaults, { "aoColumnDefs": [ @@ -79,16 +86,10 @@ function Dopop(link,i) { newin=window.open(link+"&result="+defaultvalue,"valuebuilder",'width=500,height=400,toolbar=false,scrollbars=yes'); } -function confirm_deletion(biblionumber,itemnumber) { - var original = $("#row"+itemnumber).attr("class"); - $("#row"+itemnumber).attr("class","confirm"); - var is_confirmed = confirm(_("Are you sure you want to delete this item?")); - if (is_confirmed) { - window.location = "additem.pl?op=delitem&biblionumber="+biblionumber+"&itemnumber="+itemnumber; - } else { - $("#row"+itemnumber).attr("class",""); - } +function confirm_deletion() { + return confirm(_("Are you sure you want to delete this item?")); } + //]]> @@ -161,7 +162,7 @@ function confirm_deletion(biblionumber,itemnumber) { [% IF ( item_loo.countanalytics ) %] View analytics [% ELSE %] - Delete + Delete [% END %] [% END %] -- 2.1.0