From 808ec53c1436a67f4a835ef7abbdf8af18267b15 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Fri, 11 Sep 2015 13:55:07 +0000 Subject: [PATCH] Bug 14805: Allow the user to delete multiple batches MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Allows the user to delete multiple patron card batches. Test plan: 1. Add first some 20 batches 2. Go to the edit page of some X batch by first selecting from the batch list the batch you want to edit and then after that by clicking edit. 3. Delete one batch by selecting one batch and then clicking delete. 4. Select 0 batches and click delete, notice you cannot delete. 5. Select 0 batches and click edit, notice you cannot edit. 6. Select 2 batches and click edit, notice you cannot edit. 7. Apply patch 8. Check that steps from 2-6 work like they worked before. (and add more batches so that you have ~20 of them) 9. Select 2 batches and click delete. Make sure they are deleted. 10. Try to figure out some anomalies this patch might have caused. Sponsored-by: Vaara-kirjastot Followed test plan, works as expected. Signed-off-by: Marc Véron Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- .../prog/en/modules/patroncards/manage.tt | 63 ++++++++++++++----- patroncards/manage.pl | 13 ++-- 2 files changed, 56 insertions(+), 20 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/manage.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/manage.tt index 58feb0e97d..40ea92b07f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/manage.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patroncards/manage.tt @@ -20,23 +20,38 @@ //-1) { - var msg = _("Are you sure you want to delete %s %s?").format("[% PROCESS translate_card_element element=card_element %]", element_id); - var answer = confirm(msg); - if (answer) { - window.location = "/cgi-bin/koha/patroncards/manage.pl?op=delete&card_element=[% card_element %]&element_id=" + element_id; - } - else { - return; // abort delete + var element_ids = selected_layouts("delete"); + + var answer; + if (element_ids.length > 1) { + var msg = _("Are you sure you want to delete %s batches?").format(element_ids.length); + answer = confirm(msg); + } else if (element_ids.length == 1) { + var msg = _("Are you sure you want to delete %s %s?").format("[% PROCESS translate_card_element element=card_element %]", element_ids[0]); + answer = confirm(msg); + } + + if (answer) { + var elements = ""; + for (var i = 0; i < element_ids.length; i++) { + if (element_ids[i] > -1) { + elements += element_ids[i] + "," + } + else { + return; // no layout selected + } } + + window.location = "/cgi-bin/koha/patroncards/manage.pl?op=delete&card_element=[% card_element %]&element_id=" + elements; } else { - return; // no layout selected - }; + return; // abort delete + } + }; + function Edit() { - var element_id = selected_layout("edit"); + var element_id = selected_layouts("edit"); if (element_id>-1) { window.location = "/cgi-bin/koha/patroncards/edit-[% card_element %].pl?op=edit&element_id=" + element_id; } @@ -67,7 +82,7 @@ } return GB_showCenter(_("Export patron cards"), "/cgi-bin/koha/patroncards/print.pl?" + getstr, 700, 800); }; - function selected_layout(op) { + function selected_layouts(op) { var selected = new Array; if (document.layouts.action.length) { for (i=0;i= 1)) { + if (op == "delete") { + var selectedDelete = new Array; + for (i = 0; i < selected.length; i++) { + selectedDelete.push(document.layouts.action[selected[i]].value); + } + return(selectedDelete); + } else { + // op == 'edit' returns only the object and not list + return(document.layouts.action[selected[0]].value); + } + } + else if (selected.length < 1) { + if (op == "edit") { + alert(_("Please select one %s to %s.").format("[% PROCESS translate_card_element element=card_element %]", op)); + return (-1); + } else { + alert(_("Please select at least one %s to %s.").format("[% PROCESS translate_card_element element=card_element %]", op)); + return (-1); + } } else { alert(_("Please select only one %s to %s.").format("[% PROCESS translate_card_element element=card_element %]", op)); diff --git a/patroncards/manage.pl b/patroncards/manage.pl index 316bb90b07..bd420b9642 100755 --- a/patroncards/manage.pl +++ b/patroncards/manage.pl @@ -80,11 +80,14 @@ my $branch_code = ($card_element eq 'batch' ? C4::Context->userenv->{'branch'} : if ($op eq 'delete') { my $err = 0; - if ($card_element eq 'layout') {$err = C4::Patroncards::Layout::delete(layout_id => $element_id);} - elsif ($card_element eq 'template') {$err = C4::Patroncards::Template::delete(template_id => $element_id);} - elsif ($card_element eq 'profile') {$err = C4::Patroncards::Profile::delete(profile_id => $element_id);} - elsif ($card_element eq 'batch') {$err = C4::Labels::Batch::delete(batch_id => $element_id, branch_code => $branch_code);} - else {warn sprintf("Unknown card element passed in for delete operation: %s.",$card_element); $errstr = 202;} + my @element_ids = split(/,/, $element_id); + foreach my $element_id (@element_ids) { + if ($card_element eq 'layout') {$err = C4::Patroncards::Layout::delete(layout_id => $element_id);} + elsif ($card_element eq 'template') {$err = C4::Patroncards::Template::delete(template_id => $element_id);} + elsif ($card_element eq 'profile') {$err = C4::Patroncards::Profile::delete(profile_id => $element_id);} + elsif ($card_element eq 'batch') {$err = C4::Labels::Batch::delete(batch_id => $element_id, branch_code => $branch_code);} + else {warn sprintf("Unknown card element passed in for delete operation: %s.",$card_element); $errstr = 202;} + } print $cgi->redirect("manage.pl?card_element=$card_element" . ($err ? "&error=102" : '')); exit; } -- 2.39.5