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

(-)a/admin/authorised_values.pl (-12 / +36 lines)
Lines 27-32 use C4::Koha; Link Here
27
use C4::Output;
27
use C4::Output;
28
28
29
use Koha::AuthorisedValues;
29
use Koha::AuthorisedValues;
30
use Koha::AuthorisedValueCategories;
30
31
31
my $input = new CGI;
32
my $input = new CGI;
32
my $id          = $input->param('id');
33
my $id          = $input->param('id');
Lines 113-118 if ($op eq 'add_form') { Link Here
113
    if ( $already_exists and ( not $id or $already_exists->id != $id ) ) {
114
    if ( $already_exists and ( not $id or $already_exists->id != $id ) ) {
114
        push @messages, {type => 'error', code => 'already_exists' };
115
        push @messages, {type => 'error', code => 'already_exists' };
115
    }
116
    }
117
    elsif ( $new_category eq 'branches' or $new_category eq 'itemtypes' or $new_category eq 'cn_source' ) {
118
        push @messages, {type => 'error', code => 'invalid_category_name' };
119
    }
116
    elsif ( $id ) { # Update
120
    elsif ( $id ) { # Update
117
        my $av = Koha::AuthorisedValues->new->find( $id );
121
        my $av = Koha::AuthorisedValues->new->find( $id );
118
122
Lines 154-159 if ($op eq 'add_form') { Link Here
154
158
155
    $op = 'list';
159
    $op = 'list';
156
    $searchfield = $new_category;
160
    $searchfield = $new_category;
161
} elsif ($op eq 'add_category' ) {
162
    my $new_category = $input->param('category');
163
164
    my $already_exists = Koha::AuthorisedValueCategories->find(
165
        {
166
            category_name => $new_category,
167
        }
168
    );
169
170
    if ( $already_exists ) {
171
        push @messages, {type => 'error', code => 'cat_already_exists' };
172
    }
173
    else { # Insert
174
        my $av = Koha::AuthorisedValueCategory->new( {
175
            category_name => $new_category,
176
        } );
177
178
        eval {
179
            $av->store;
180
        };
181
182
        if ( $@ ) {
183
            push @messages, {type => 'error', code => 'error_on_insert_cat' };
184
        } else {
185
            push @messages, { type => 'message', code => 'success_on_insert_cat' };
186
        }
187
    }
188
189
    $op = 'list';
190
    $searchfield = $new_category;
157
} elsif ($op eq 'delete') {
191
} elsif ($op eq 'delete') {
158
    my $av = Koha::AuthorisedValues->new->find( $input->param('id') );
192
    my $av = Koha::AuthorisedValues->new->find( $input->param('id') );
159
    my $deleted = eval {$av->delete};
193
    my $deleted = eval {$av->delete};
Lines 175-196 $template->param( Link Here
175
209
176
if ( $op eq 'list' ) {
210
if ( $op eq 'list' ) {
177
    # build categories list
211
    # build categories list
178
    my @categories = Koha::AuthorisedValues->new->categories;
212
    my @categories = Koha::AuthorisedValueCategories->search({}, { order_by => ['category_name'] } );
179
    my @category_list;
213
    my @category_list;
180
    my %categories;    # a hash, to check that some hardcoded categories exist.
181
    for my $category ( @categories ) {
214
    for my $category ( @categories ) {
182
        push( @category_list, $category );
215
        push( @category_list, $category->category_name );
183
        $categories{$category} = 1;
184
    }
216
    }
185
217
186
    # push koha system categories
187
    foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS ITEMTYPECAT)) {
188
        push @category_list, $_ unless $categories{$_};
189
    }
190
191
    #reorder the list
192
    @category_list = sort {$a cmp $b} @category_list;
193
194
    $searchfield ||= $category_list[0];
218
    $searchfield ||= $category_list[0];
195
219
196
    my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } );
220
    my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } );
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt (-14 / +22 lines)
Lines 77-99 $(document).ready(function() { Link Here
77
    [% IF ( action_modify ) %]<div class="note"><i class="fa fa-exclamation"></i> <strong>NOTE:</strong> If you change an authorized value code, existing records using it won't be updated. Changes to value descriptions will show immediately.</div>[% END %]
77
    [% IF ( action_modify ) %]<div class="note"><i class="fa fa-exclamation"></i> <strong>NOTE:</strong> If you change an authorized value code, existing records using it won't be updated. Changes to value descriptions will show immediately.</div>[% END %]
78
78
79
 <form action="/cgi-bin/koha/admin/authorised_values.pl" name="Aform" method="post">
79
 <form action="/cgi-bin/koha/admin/authorised_values.pl" name="Aform" method="post">
80
    <input type="hidden" name="op" value="add" />
81
        <fieldset class="rows"><ol>
80
        <fieldset class="rows"><ol>
82
        <li>
81
        [% IF action_add_category %]
83
        [% IF ( action_add_category ) %]<label for="category">Category: </label>
82
            <li>
84
            <input type="text" name="category"  id="category" size="32" maxlength="32" class="focus" />
83
                <label for="category">Category: </label>
85
			 [% ELSE %]<span class="label">Category</span>
84
                <input type="hidden" name="op" value="add_category" />
86
		<input type="hidden" name="category" value="[% category %]" />	 [% category %]
85
                <input type="text" name="category"  id="category" size="32" maxlength="32" class="focus" />
87
			 [% END %]
86
            </li>
88
        </li>
87
        [% ELSE %]
88
            <li>
89
                <span class="label">Category</span>
90
                <input type="hidden" name="op" value="add" />
91
                <input type="hidden" name="category" value="[% category %]" /> [% category %]
92
            </li>
89
        <li>
93
        <li>
90
            <label for="authorised_value">Authorized value: </label>
94
            <label for="authorised_value">Authorized value: </label>
91
     [% IF ( action_modify ) %]<input type="hidden" id="id" name="id" value="[% id %]" />[% END %]
95
            [% IF ( action_modify ) %]<input type="hidden" id="id" name="id" value="[% id %]" />[% END %]
92
            [% IF ( action_add_category ) %]
93
            <input type="text" id="authorised_value" name="authorised_value" value="[% authorised_value %]" maxlength="80" />
94
            [% ELSE %]
95
            <input type="text" id="authorised_value" name="authorised_value" value="[% authorised_value %]" maxlength="80" class="focus" />
96
            <input type="text" id="authorised_value" name="authorised_value" value="[% authorised_value %]" maxlength="80" class="focus" />
96
            [% END %]
97
        </li>
97
        </li>
98
        <li>
98
        <li>
99
            <label for="lib">Description: </label>
99
            <label for="lib">Description: </label>
Lines 152-157 $(document).ready(function() { Link Here
152
  </div>
152
  </div>
153
  [% END %]
153
  [% END %]
154
  </div>
154
  </div>
155
        [% END %]
155
        </fieldset>
156
        </fieldset>
156
       <fieldset class="action"> <input type="hidden" name="id" value="[% id %]" />
157
       <fieldset class="action"> <input type="hidden" name="id" value="[% id %]" />
157
        <input type="submit" value="Save" /> <a class="cancel" href="/cgi-bin/koha/admin/authorised_values.pl?searchfield=[% category %]">Cancel</a></fieldset>
158
        <input type="submit" value="Save" /> <a class="cancel" href="/cgi-bin/koha/admin/authorised_values.pl?searchfield=[% category %]">Cancel</a></fieldset>
Lines 176-191 $(document).ready(function() { Link Here
176
            An error occurred when updating this authorized value. Perhaps the value already exists.
177
            An error occurred when updating this authorized value. Perhaps the value already exists.
177
        [% CASE 'error_on_insert' %]
178
        [% CASE 'error_on_insert' %]
178
            An error occurred when inserting this authorized value. Perhaps the value or the category already exists.
179
            An error occurred when inserting this authorized value. Perhaps the value or the category already exists.
180
        [% CASE 'error_on_insert_cat' %]
181
            An error occurred when inserting this authorized value category. Perhaps the category name already exists.
179
        [% CASE 'error_on_delete' %]
182
        [% CASE 'error_on_delete' %]
180
            An error occurred when deleting this authorized value. Check the logs.
183
            An error occurred when deleting this authorized value. Check the logs.
181
        [% CASE 'success_on_update' %]
184
        [% CASE 'success_on_update' %]
182
            Authorized value updated successfully.
185
            Authorized value updated successfully.
183
        [% CASE 'success_on_insert' %]
186
        [% CASE 'success_on_insert' %]
184
            Authorized value added successfully.
187
            Authorized value added successfully.
188
        [% CASE 'success_on_insert_cat' %]
189
            Authorized value category added successfully.
185
        [% CASE 'success_on_delete' %]
190
        [% CASE 'success_on_delete' %]
186
            Authorized value deleted successfully.
191
            Authorized value deleted successfully.
187
        [% CASE 'already_exists' %]
192
        [% CASE 'already_exists' %]
188
            This authorized value already exists.
193
            This authorized value already exists.
194
        [% CASE 'cat_already_exists' %]
195
            This authorized value category already exists.
196
        [% CASE 'invalid_category_name' %]
197
            The authorized value category 'branches', 'itemtypes' and 'cn_source' are used internally by Koha and are not valid.
189
        [% CASE %]
198
        [% CASE %]
190
            [% m.code %]
199
            [% m.code %]
191
        [% END %]
200
        [% END %]
192
- 

Return to bug 17216