From 94c1a685fe69d68e63ec8ef22b361f8d8faa4e0f 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 Note that this does not capture all internal fields, and isn't a database solution to the problem of marking internal fields. To test: Add an empty authorised value category, delete it. Make sure it stays deleted. Try to delete an empty system authorised value, like ccode. You should not see the button. --- admin/authorised_values.pl | 38 +++++++++++++++++++++- .../prog/en/modules/admin/authorised_values.tt | 12 ++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl index 272ed00..bc7f2cd 100755 --- a/admin/authorised_values.pl +++ b/admin/authorised_values.pl @@ -191,6 +191,21 @@ if ($op eq 'add_form') { } $op = 'list'; +} elsif ($op eq 'del_category' ) { + 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' }; + } 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}; @@ -214,12 +229,32 @@ if ( $op eq 'list' ) { # build categories list my @categories = Koha::AuthorisedValueCategories->search({ category_name => { -not_in => ['', 'branches', 'itemtypes', 'cn_source']}}, { order_by => ['category_name'] } ); my @category_list; + my $deletable = 1; for my $category ( @categories ) { push( @category_list, $category->category_name ); } - $searchfield ||= $category_list[0]; + my %cant_del = ( + LOC => 1, + LOST => 1, + WITHDRAWN => 1, + Bsort1 => 1, + Bsort2 => 1, + Asort1 => 1, + Asort2 => 1, + SUGGEST => 1, + DAMAGED => 1, + LOST => 1, + MANUAL_INV => 1, + BOR_NOTES => 1, + LOC => 1, + CCODE => 1, + NOT_LOAN => 1, + ); + if ( $cant_del{$searchfield} ) { + undef $deletable ; + } my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } ); my @loop_data = (); # builds value list @@ -239,6 +274,7 @@ if ( $op eq 'list' ) { loop => \@loop_data, category => $searchfield, categories => \@category_list, + deletable => $deletable, ); } 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..4865e4f 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,12 +182,16 @@ $(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_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 successfully. [% CASE 'success_on_delete' %] Authorized value deleted successfully. [% CASE 'already_exists' %] @@ -296,7 +300,13 @@ $(document).ready(function() { [% END %] [% ELSE %] -
There are no authorized values defined for [% category %]
+
There are no authorized values defined for [% category %] +[% IF deletable %] + Delete category +[% END %]
+ + + [% END %] [% IF ( isprevpage ) %] -- 2.7.4