From c5491ceca98866490e50021f788ce946ab97406a Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 8 Jun 2017 09:16:45 -0400 Subject: [PATCH] Bug 17355 - Allow deletion of authorised value categories This is jsut a ptach I was toying with - as Jonathan mentions we need a way to prevent deletion of internal categories, I just listed them here (we would list more) Partial patch, so would need work but poking this bug as reminder :-) Signed-off-by: Liz Rea This is a good start --- admin/authorised_values.pl | 23 ++++++++++++++++++++++ .../prog/en/modules/admin/authorised_values.tt | 13 +++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl index 272ed00..fc07d09 100755 --- a/admin/authorised_values.pl +++ b/admin/authorised_values.pl @@ -191,6 +191,29 @@ if ($op eq 'add_form') { } $op = 'list'; +} elsif ($op eq 'del_category' ) { + my %cant_del = ( + LOC => 1, + LOST => 1, + WITHDRAWN => 1, + ); + + my $del_category = $input->param('category'); + if ( Koha::AuthorisedValues->new->search({ category => $del_category })->count > 0 ) { + push @messages, {type => 'error', code => 'error_on_delete_cat_notempty' }; + } elsif ( $cant_del{$del_category} ) { + push @messages, {type => 'error', code => 'invalid_category_del' }; + } else { + my $cat = Koha::AuthorisedValueCategories->new->find( $del_category ); + my $deleted = eval {$cat->delete}; + if ( $@ or not $deleted ) { + push @messages, {type => 'error', code => 'error_on_delete_cat' }; + } else { + push @messages, { type => 'message', code => 'success_on_delete_cat' }; + } + } + $op = 'list'; + $template->param( delete_success => 1 ); } elsif ($op eq 'delete') { my $av = Koha::AuthorisedValues->new->find( $id ); my $deleted = eval {$av->delete}; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt index 5aee840..6b9447b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt @@ -182,18 +182,26 @@ $(document).ready(function() { An error occurred when inserting this authorized value category. Perhaps the category name already exists. [% CASE 'error_on_delete' %] An error occurred when deleting this authorized value. Check the logs. + [% CASE 'error_on_delete_cat' %] + An error occurred when deleting this authorized value category. Check the logs. + [% CASE 'error_on_delete_cat_notempty' %] + This category cannot be deleted as it contains values. [% CASE 'success_on_update' %] Authorized value updated successfully. [% CASE 'success_on_insert' %] Authorized value added successfully. [% CASE 'success_on_insert_cat' %] Authorized value category added successfully. + [% CASE 'success_on_delete_cat' %] + Authorized value deleted added successfully. [% CASE 'success_on_delete' %] Authorized value deleted successfully. [% CASE 'already_exists' %] This authorized value already exists. [% CASE 'cat_already_exists' %] This authorized value category already exists. + [% CASE 'invalid_category_del' %] + The authorized value categories 'LOC', 'CCODE' and 'LOST' are used internally by Koha and may not be deleted. [% CASE 'invalid_category_name' %] The authorized value category 'branches', 'itemtypes' and 'cn_source' are used internally by Koha and are not valid. [% CASE %] @@ -296,7 +304,10 @@ $(document).ready(function() { [% END %] [% ELSE %] -
There are no authorized values defined for [% category %]
+
There are no authorized values defined for [% category %] + Delete category + +
[% END %] [% IF ( isprevpage ) %] -- 2.7.4