|
Lines 48-60
our ($template, $borrowernumber, $cookie)= get_template_and_user({
Link Here
|
| 48 |
|
48 |
|
| 49 |
################## ADD_FORM ################################## |
49 |
################## ADD_FORM ################################## |
| 50 |
# called by default. Used to create form to add or modify a record |
50 |
# called by default. Used to create form to add or modify a record |
| 51 |
if ($op eq 'add_form') { |
51 |
if ( $op eq 'add_form' or $op eq 'edit_form' ) { |
| 52 |
my ( @selected_branches, $category, $av ); |
52 |
my ( @selected_branches, $category, $category_name, $av ); |
| 53 |
if ($id) { |
53 |
if ($id) { |
| 54 |
$av = Koha::AuthorisedValues->new->find( $id ); |
54 |
$av = Koha::AuthorisedValues->new->find( $id ); |
| 55 |
@selected_branches = $av->library_limits ? $av->library_limits->as_list : (); |
55 |
@selected_branches = $av->library_limits ? $av->library_limits->as_list : (); |
| 56 |
} else { |
56 |
} else { |
| 57 |
$category = $input->param('category'); |
57 |
$category_name = $input->param('category'); |
|
|
58 |
$category = Koha::AuthorisedValueCategories->find($category_name); |
| 58 |
} |
59 |
} |
| 59 |
|
60 |
|
| 60 |
my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } ); |
61 |
my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } ); |
|
Lines 69-75
if ($op eq 'add_form') {
Link Here
|
| 69 |
|
70 |
|
| 70 |
if ($id) { |
71 |
if ($id) { |
| 71 |
$template->param(action_modify => 1); |
72 |
$template->param(action_modify => 1); |
| 72 |
} elsif ( ! $category ) { |
73 |
} elsif ( ! $category_name ) { |
| 73 |
$template->param(action_add_category => 1); |
74 |
$template->param(action_add_category => 1); |
| 74 |
} else { |
75 |
} else { |
| 75 |
$template->param(action_add_value => 1); |
76 |
$template->param(action_add_value => 1); |
|
Lines 83-94
if ($op eq 'add_form') {
Link Here
|
| 83 |
); |
84 |
); |
| 84 |
} else { |
85 |
} else { |
| 85 |
$template->param( |
86 |
$template->param( |
| 86 |
category_name => $category, |
87 |
category => $category, |
| 87 |
imagesets => C4::Koha::getImageSets(), |
88 |
category_name => $category_name, |
|
|
89 |
imagesets => C4::Koha::getImageSets(), |
| 88 |
); |
90 |
); |
| 89 |
} |
91 |
} |
| 90 |
$template->param( |
92 |
$template->param( |
| 91 |
branches_loop => \@branches_loop, |
93 |
branches_loop => \@branches_loop, |
|
|
94 |
num_pattern => Koha::AuthorisedValue::NUM_PATTERN_JS(), |
| 92 |
); |
95 |
); |
| 93 |
|
96 |
|
| 94 |
} elsif ($op eq 'cud-add') { |
97 |
} elsif ($op eq 'cud-add') { |
|
Lines 102-108
if ($op eq 'add_form') {
Link Here
|
| 102 |
: $image |
105 |
: $image |
| 103 |
); |
106 |
); |
| 104 |
my $duplicate_entry = 0; |
107 |
my $duplicate_entry = 0; |
| 105 |
my @branches = grep { $_ ne q{} } $input->multi_param('branches'); |
108 |
my @branches = grep { $_ ne q{} } $input->multi_param('branches'); |
| 106 |
|
109 |
|
| 107 |
if ( $new_category eq 'branches' or $new_category eq 'itemtypes' or $new_category eq 'cn_source' ) { |
110 |
if ( $new_category eq 'branches' or $new_category eq 'itemtypes' or $new_category eq 'cn_source' ) { |
| 108 |
push @messages, {type => 'error', code => 'invalid_category_name' }; |
111 |
push @messages, {type => 'error', code => 'invalid_category_name' }; |
|
Lines 150-156
if ($op eq 'add_form') {
Link Here
|
| 150 |
$op = 'list'; |
153 |
$op = 'list'; |
| 151 |
$searchfield = $new_category; |
154 |
$searchfield = $new_category; |
| 152 |
} elsif ($op eq 'cud-add_category' ) { |
155 |
} elsif ($op eq 'cud-add_category' ) { |
| 153 |
my $new_category = $input->param('category'); |
156 |
my $new_category = $input->param('category'); |
|
|
157 |
my $is_integer_only = $input->param('is_integer_only') ? 1 : 0; |
| 154 |
|
158 |
|
| 155 |
my $already_exists = Koha::AuthorisedValueCategories->find( |
159 |
my $already_exists = Koha::AuthorisedValueCategories->find( |
| 156 |
{ |
160 |
{ |
|
Lines 167-173
if ($op eq 'add_form') {
Link Here
|
| 167 |
} |
171 |
} |
| 168 |
else { # Insert |
172 |
else { # Insert |
| 169 |
my $av = Koha::AuthorisedValueCategory->new( { |
173 |
my $av = Koha::AuthorisedValueCategory->new( { |
| 170 |
category_name => $new_category, |
174 |
category_name => $new_category, is_integer_only => $is_integer_only, |
| 171 |
} ); |
175 |
} ); |
| 172 |
|
176 |
|
| 173 |
eval { |
177 |
eval { |
|
Lines 182-187
if ($op eq 'add_form') {
Link Here
|
| 182 |
} |
186 |
} |
| 183 |
} |
187 |
} |
| 184 |
|
188 |
|
|
|
189 |
$op = 'list'; |
| 190 |
} elsif ( $op eq 'edit_category' ) { |
| 191 |
my $category_name = $input->param('category'); |
| 192 |
my $is_integer_only = $input->param('is_integer_only') ? 1 : 0; |
| 193 |
my $category = Koha::AuthorisedValueCategories->find($category_name); |
| 194 |
|
| 195 |
if ($category) { |
| 196 |
$category->is_integer_only($is_integer_only)->store; |
| 197 |
} else { |
| 198 |
push @messages, {type => 'error', code => 'error_on_edit_cat' }; |
| 199 |
} |
| 200 |
|
| 185 |
$op = 'list'; |
201 |
$op = 'list'; |
| 186 |
} elsif ($op eq 'cud-delete') { |
202 |
} elsif ($op eq 'cud-delete') { |
| 187 |
my $av = Koha::AuthorisedValues->new->find( $id ); |
203 |
my $av = Koha::AuthorisedValues->new->find( $id ); |
|
Lines 214-231
$template->param(
Link Here
|
| 214 |
|
230 |
|
| 215 |
if ( $op eq 'list' ) { |
231 |
if ( $op eq 'list' ) { |
| 216 |
# build categories list |
232 |
# build categories list |
| 217 |
my @category_names = Koha::AuthorisedValueCategories->search( |
233 |
my $category_rs = Koha::AuthorisedValueCategories->search( |
| 218 |
{ |
234 |
{ |
| 219 |
category_name => |
235 |
category_name => |
| 220 |
{ -not_in => [ '', 'branches', 'itemtypes', 'cn_source' ] } |
236 |
{ -not_in => [ '', 'branches', 'itemtypes', 'cn_source' ] } |
| 221 |
}, |
237 |
}, |
| 222 |
{ order_by => ['category_name'] } |
238 |
{ order_by => ['category_name'] } |
| 223 |
)->get_column('category_name'); |
239 |
); |
|
|
240 |
my @category_names = $category_rs->get_column('category_name'); |
| 224 |
|
241 |
|
| 225 |
$searchfield ||= ""; |
242 |
$searchfield ||= ""; |
| 226 |
|
243 |
|
| 227 |
my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } )->as_list; |
244 |
my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } )->as_list; |
| 228 |
my @loop_data = (); |
245 |
my @loop_data = (); |
|
|
246 |
my $category = $category_rs->find($searchfield); |
| 247 |
my $is_integer_only = $category && $category->is_integer_only; |
| 229 |
# builds value list |
248 |
# builds value list |
| 230 |
for my $av ( @avs_by_category ) { |
249 |
for my $av ( @avs_by_category ) { |
| 231 |
my %row_data; # get a fresh hash for the row data |
250 |
my %row_data; # get a fresh hash for the row data |
|
Lines 236-241
if ( $op eq 'list' ) {
Link Here
|
| 236 |
$row_data{image} = getitemtypeimagelocation( 'intranet', $av->imageurl ); |
255 |
$row_data{image} = getitemtypeimagelocation( 'intranet', $av->imageurl ); |
| 237 |
$row_data{branches} = $av->library_limits ? $av->library_limits->as_list : []; |
256 |
$row_data{branches} = $av->library_limits ? $av->library_limits->as_list : []; |
| 238 |
$row_data{id} = $av->id; |
257 |
$row_data{id} = $av->id; |
|
|
258 |
$row_data{is_integer_only} = $is_integer_only; |
| 239 |
push(@loop_data, \%row_data); |
259 |
push(@loop_data, \%row_data); |
| 240 |
} |
260 |
} |
| 241 |
|
261 |
|