From df8c81c47305dc7067f008614b2c240765ffb7ad Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Wed, 21 Feb 2024 22:49:28 +0000 Subject: [PATCH] Bug 35067: Save a parent category for authorised value category --- admin/authorised_values.pl | 34 ++++++++++++------- .../en/modules/admin/authorised_values.tt | 32 +++++++++++++---- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/admin/authorised_values.pl b/admin/authorised_values.pl index 2130e86819d..c41e87bdf9b 100755 --- a/admin/authorised_values.pl +++ b/admin/authorised_values.pl @@ -67,6 +67,11 @@ if ($op eq 'add_form') { }; } + my @category_names = Koha::AuthorisedValueCategories->search( + { category_name => { -not_in => [ '', 'branches', 'itemtypes', 'cn_source' ] } }, + { order_by => ['category_name'] } + )->as_list; + if ($id) { $template->param(action_modify => 1); } elsif ( ! $category ) { @@ -88,7 +93,8 @@ if ($op eq 'add_form') { ); } $template->param( - branches_loop => \@branches_loop, + branches_loop => \@branches_loop, + category_names => \@category_names, ); } elsif ($op eq 'add') { @@ -151,6 +157,7 @@ if ($op eq 'add_form') { $searchfield = $new_category; } elsif ($op eq 'add_category' ) { my $new_category = $input->param('category'); + my $parent = $input->param('parent') || undef; my $already_exists = Koha::AuthorisedValueCategories->find( { @@ -166,9 +173,12 @@ if ($op eq 'add_form') { } } else { # Insert - my $av = Koha::AuthorisedValueCategory->new( { - category_name => $new_category, - } ); + my $av = Koha::AuthorisedValueCategory->new( + { + category_name => $new_category, + parent => $parent, + } + ); eval { $av->store; @@ -206,21 +216,21 @@ if ($op eq 'add_form') { $op = 'list'; } +my $avc = Koha::AuthorisedValueCategories->find( $searchfield ); + $template->param( - op => $op, + op => $op, searchfield => $searchfield, - messages => \@messages, + messages => \@messages, + avc => $avc, ); if ( $op eq 'list' ) { # build categories list my @category_names = Koha::AuthorisedValueCategories->search( - { - category_name => - { -not_in => [ '', 'branches', 'itemtypes', 'cn_source' ] } - }, - { order_by => ['category_name'] } - )->get_column('category_name'); + { category_name => { -not_in => [ '', 'branches', 'itemtypes', 'cn_source' ] } }, + { order_by => ['category_name'] } + )->as_list; $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 8ae422c444f..98a0d756bda 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 @@ -133,6 +133,14 @@ Required +
  • + + +
  • [% ELSE %]
      @@ -246,16 +254,20 @@

      + [% IF avc.parent %] + Show parent category: [% avc.parent | html %] + [% END %] + [% IF loop %] @@ -326,18 +338,26 @@ + [% FOR c IN category_names %] - + + [% END # /FOR c %] -- 2.30.2
      Category DescriptionParent category  
      [% c | html %][% c.category_name | html %] + [% PROCESS category_descriptions code_category = c.category_name %] + - [% PROCESS category_descriptions code_category = c %] + [% IF c.parent %] + [% c.parent | html %] + [% ELSE %] +   + [% END %] - Add + Add