View | Details | Raw Unified | Return to bug 17355
Collapse All | Expand All

(-)a/admin/authorised_values.pl (-1 / +37 lines)
Lines 191-196 if ($op eq 'add_form') { Link Here
191
    }
191
    }
192
192
193
    $op = 'list';
193
    $op = 'list';
194
} elsif ($op eq 'del_category' ) {
195
    my $del_category = $input->param('category');
196
    if ( Koha::AuthorisedValues->new->search({ category => $del_category })->count > 0 ) {
197
        push @messages, {type => 'error', code => 'error_on_delete_cat_notempty' };
198
    } else {
199
        my $cat = Koha::AuthorisedValueCategories->new->find( $del_category );
200
        my $deleted = eval {$cat->delete};
201
        if ( $@ or not $deleted ) {
202
            push @messages, {type => 'error', code => 'error_on_delete_cat' };
203
        } else {
204
            push @messages, { type => 'message', code => 'success_on_delete_cat' };
205
        }
206
    }
207
    $op = 'list';
208
    $template->param( delete_success => 1 );
194
} elsif ($op eq 'delete') {
209
} elsif ($op eq 'delete') {
195
    my $av = Koha::AuthorisedValues->new->find( $id );
210
    my $av = Koha::AuthorisedValues->new->find( $id );
196
    my $deleted = eval {$av->delete};
211
    my $deleted = eval {$av->delete};
Lines 214-225 if ( $op eq 'list' ) { Link Here
214
    # build categories list
229
    # build categories list
215
    my @categories = Koha::AuthorisedValueCategories->search({ category_name => { -not_in => ['', 'branches', 'itemtypes', 'cn_source']}}, { order_by => ['category_name'] } );
230
    my @categories = Koha::AuthorisedValueCategories->search({ category_name => { -not_in => ['', 'branches', 'itemtypes', 'cn_source']}}, { order_by => ['category_name'] } );
216
    my @category_list;
231
    my @category_list;
232
    my $deletable = 1;
217
    for my $category ( @categories ) {
233
    for my $category ( @categories ) {
218
        push( @category_list, $category->category_name );
234
        push( @category_list, $category->category_name );
219
    }
235
    }
220
221
    $searchfield ||= $category_list[0];
236
    $searchfield ||= $category_list[0];
237
    my %cant_del = (
238
        LOC => 1,
239
        LOST => 1,
240
        WITHDRAWN => 1,
241
        Bsort1 => 1,
242
        Bsort2 => 1,
243
        Asort1 => 1,
244
        Asort2 => 1,
245
        SUGGEST => 1,
246
        DAMAGED => 1,
247
        LOST => 1,
248
        MANUAL_INV => 1,
249
        BOR_NOTES => 1,
250
        LOC => 1,
251
        CCODE => 1,
252
        NOT_LOAN => 1,
253
        );
222
254
255
    if ( $cant_del{$searchfield} ) {
256
        undef $deletable ;
257
    }
223
    my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } );
258
    my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } );
224
    my @loop_data = ();
259
    my @loop_data = ();
225
    # builds value list
260
    # builds value list
Lines 239-244 if ( $op eq 'list' ) { Link Here
239
        loop     => \@loop_data,
274
        loop     => \@loop_data,
240
        category => $searchfield,
275
        category => $searchfield,
241
        categories => \@category_list,
276
        categories => \@category_list,
277
        deletable => $deletable,
242
    );
278
    );
243
279
244
}
280
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt (-2 / +11 lines)
Lines 182-193 $(document).ready(function() { Link Here
182
            An error occurred when inserting this authorized value category. Perhaps the category name already exists.
182
            An error occurred when inserting this authorized value category. Perhaps the category name already exists.
183
        [% CASE 'error_on_delete' %]
183
        [% CASE 'error_on_delete' %]
184
            An error occurred when deleting this authorized value. Check the logs.
184
            An error occurred when deleting this authorized value. Check the logs.
185
        [% CASE 'error_on_delete_cat_notempty' %]
186
            This category cannot be deleted as it contains values.
185
        [% CASE 'success_on_update' %]
187
        [% CASE 'success_on_update' %]
186
            Authorized value updated successfully.
188
            Authorized value updated successfully.
187
        [% CASE 'success_on_insert' %]
189
        [% CASE 'success_on_insert' %]
188
            Authorized value added successfully.
190
            Authorized value added successfully.
189
        [% CASE 'success_on_insert_cat' %]
191
        [% CASE 'success_on_insert_cat' %]
190
            Authorized value category added successfully.
192
            Authorized value category added successfully.
193
        [% CASE 'success_on_delete_cat' %]
194
            Authorized value deleted successfully.
191
        [% CASE 'success_on_delete' %]
195
        [% CASE 'success_on_delete' %]
192
            Authorized value deleted successfully.
196
            Authorized value deleted successfully.
193
        [% CASE 'already_exists' %]
197
        [% CASE 'already_exists' %]
Lines 296-302 $(document).ready(function() { Link Here
296
</tr>
300
</tr>
297
[% END %]
301
[% END %]
298
</tbody></table>[% ELSE %]
302
</tbody></table>[% ELSE %]
299
<div class="dialog message">There are no authorized values defined for [% category %]</div>
303
<div class="dialog message">There are no authorized values defined for [% category %]
304
[% IF deletable %]
305
    <a class="delete btn btn-default btn-xs" href="/cgi-bin/koha/admin/authorised_values.pl?op=del_category&amp;category=[% searchfield %]"><i class="fa fa-trash"></i> Delete category</a>
306
[% END %]</div>
307
</td>
308
309
</div>
300
[% END %]
310
[% END %]
301
311
302
[% IF ( isprevpage ) %]
312
[% IF ( isprevpage ) %]
303
- 

Return to bug 17355