From d004f054384057f0c40f31137866ea3139fd2d52 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 c40158f15dd..f46539b51ee 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 'cud-add') {
@@ -151,6 +157,7 @@ if ($op eq 'add_form') {
$searchfield = $new_category;
} elsif ($op eq 'cud-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 11ccab61a5a..e31befcfea0 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
@@ -134,6 +134,14 @@
Required
+
+
+
+
[% ELSE %]
@@ -247,16 +255,20 @@
+ [% IF avc.parent %]
+ Show parent category: [% avc.parent | html %]
+ [% END %]
+
[% IF loop %]
@@ -336,18 +348,26 @@
Category |
Description |
+ Parent category |
|
[% FOR c IN category_names %]
- [% 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
|
[% END # /FOR c %]
--
2.30.2