From bfc9bb248daeedbf808e08782824f38e3dd15c05 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 29 Aug 2016 14:06:46 +0100 Subject: [PATCH] Bug 17216: Update the admin interface Signed-off-by: Owen Leonard --- admin/authorised_values.pl | 48 ++++++++++++++++------ .../prog/en/modules/admin/authorised_values.tt | 38 ++++++++++------- 2 files changed, 59 insertions(+), 27 deletions(-) diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl index b782901..0a79e8d 100755 --- a/admin/authorised_values.pl +++ b/admin/authorised_values.pl @@ -27,6 +27,7 @@ use C4::Koha; use C4::Output; use Koha::AuthorisedValues; +use Koha::AuthorisedValueCategories; my $input = new CGI; my $id = $input->param('id'); @@ -113,6 +114,9 @@ if ($op eq 'add_form') { if ( $already_exists and ( not $id or $already_exists->id != $id ) ) { push @messages, {type => 'error', code => 'already_exists' }; } + elsif ( $new_category eq 'branches' or $new_category eq 'itemtypes' or $new_category eq 'cn_source' ) { + push @messages, {type => 'error', code => 'invalid_category_name' }; + } elsif ( $id ) { # Update my $av = Koha::AuthorisedValues->new->find( $id ); @@ -154,6 +158,36 @@ if ($op eq 'add_form') { $op = 'list'; $searchfield = $new_category; +} elsif ($op eq 'add_category' ) { + my $new_category = $input->param('category'); + + my $already_exists = Koha::AuthorisedValueCategories->find( + { + category_name => $new_category, + } + ); + + if ( $already_exists ) { + push @messages, {type => 'error', code => 'cat_already_exists' }; + } + else { # Insert + my $av = Koha::AuthorisedValueCategory->new( { + category_name => $new_category, + } ); + + eval { + $av->store; + }; + + if ( $@ ) { + push @messages, {type => 'error', code => 'error_on_insert_cat' }; + } else { + push @messages, { type => 'message', code => 'success_on_insert_cat' }; + } + } + + $op = 'list'; + $searchfield = $new_category; } elsif ($op eq 'delete') { my $av = Koha::AuthorisedValues->new->find( $input->param('id') ); my $deleted = eval {$av->delete}; @@ -175,22 +209,12 @@ $template->param( if ( $op eq 'list' ) { # build categories list - my @categories = Koha::AuthorisedValues->new->categories; + my @categories = Koha::AuthorisedValueCategories->search({}, { order_by => ['category_name'] } ); my @category_list; - my %categories; # a hash, to check that some hardcoded categories exist. for my $category ( @categories ) { - push( @category_list, $category ); - $categories{$category} = 1; + push( @category_list, $category->category_name ); } - # push koha system categories - foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS ITEMTYPECAT)) { - push @category_list, $_ unless $categories{$_}; - } - - #reorder the list - @category_list = sort {$a cmp $b} @category_list; - $searchfield ||= $category_list[0]; my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } ); 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 2aa3b5f..f4f56cf 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 @@ -77,25 +77,24 @@ $(document).ready(function() { [% IF ( action_modify ) %]
NOTE: If you change an authorized value code, existing records using it won't be updated. Changes to value descriptions will show immediately.
[% END %]
-
    -
  1. - [% IF ( action_add_category ) %] - - - Required - [% ELSE %]Category - [% category %] - [% END %] -
  2. + [% IF action_add_category %] +
  3. + + + Required + +
  4. + [% ELSE %] +
  5. + Category + + [% category %] +
  6. - [% IF ( action_modify ) %][% END %] - [% IF ( action_add_category ) %] - - [% ELSE %] + [% IF ( action_modify ) %][% END %] - [% END %]
  7. @@ -154,6 +153,7 @@ $(document).ready(function() { [% END %] + [% END %]
Cancel
@@ -178,16 +178,24 @@ $(document).ready(function() { An error occurred when updating this authorized value. Perhaps the value already exists. [% CASE 'error_on_insert' %] An error occurred when inserting this authorized value. Perhaps the value or the category already exists. + [% CASE 'error_on_insert_cat' %] + 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 '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' %] 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_name' %] + The authorized value category 'branches', 'itemtypes' and 'cn_source' are used internally by Koha and are not valid. [% CASE %] [% m.code %] [% END %] -- 2.8.1