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 (-16 / +23 lines)
Lines 77-101 $(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" class="validated">
79
 <form action="/cgi-bin/koha/admin/authorised_values.pl" name="Aform" method="post" class="validated">
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 ) %]
82
            <li>
84
            <label for="category" class="required">Category: </label>
83
                <label for="category" class="required">Category: </label>
85
            <input type="text" name="category"  id="category" size="32" maxlength="32" class="focus required" />
84
                <input type="text" name="category"  id="category" size="32" maxlength="32" class="focus required" />
86
            <span class="required">Required</span>
85
                <span class="required">Required</span>
87
			 [% ELSE %]<span class="label">Category</span>
86
                <input type="hidden" name="op" value="add_category" />
88
		<input type="hidden" name="category" value="[% category %]" />	 [% category %]
87
            </li>
89
			 [% END %]
88
        [% ELSE %]
90
        </li>
89
            <li>
90
                <span class="label">Category</span>
91
                <input type="hidden" name="op" value="add" />
92
                <input type="hidden" name="category" value="[% category %]" /> [% category %]
93
            </li>
91
        <li>
94
        <li>
92
            <label for="authorised_value">Authorized value: </label>
95
            <label for="authorised_value">Authorized value: </label>
93
     [% IF ( action_modify ) %]<input type="hidden" id="id" name="id" value="[% id %]" />[% END %]
96
            [% IF ( action_modify ) %]<input type="hidden" id="id" name="id" value="[% id %]" />[% END %]
94
            [% IF ( action_add_category ) %]
95
            <input type="text" id="authorised_value" name="authorised_value" value="[% authorised_value %]" maxlength="80" />
96
            [% ELSE %]
97
            <input type="text" id="authorised_value" name="authorised_value" value="[% authorised_value %]" maxlength="80" class="focus" />
97
            <input type="text" id="authorised_value" name="authorised_value" value="[% authorised_value %]" maxlength="80" class="focus" />
98
            [% END %]
99
        </li>
98
        </li>
100
        <li>
99
        <li>
101
            <label for="lib">Description: </label>
100
            <label for="lib">Description: </label>
Lines 154-159 $(document).ready(function() { Link Here
154
  </div>
153
  </div>
155
  [% END %]
154
  [% END %]
156
  </div>
155
  </div>
156
        [% END %]
157
        </fieldset>
157
        </fieldset>
158
       <fieldset class="action"> <input type="hidden" name="id" value="[% id %]" />
158
       <fieldset class="action"> <input type="hidden" name="id" value="[% id %]" />
159
        <input type="submit" value="Save" /> <a class="cancel" href="/cgi-bin/koha/admin/authorised_values.pl?searchfield=[% category %]">Cancel</a></fieldset>
159
        <input type="submit" value="Save" /> <a class="cancel" href="/cgi-bin/koha/admin/authorised_values.pl?searchfield=[% category %]">Cancel</a></fieldset>
Lines 178-193 $(document).ready(function() { Link Here
178
            An error occurred when updating this authorized value. Perhaps the value already exists.
178
            An error occurred when updating this authorized value. Perhaps the value already exists.
179
        [% CASE 'error_on_insert' %]
179
        [% CASE 'error_on_insert' %]
180
            An error occurred when inserting this authorized value. Perhaps the value or the category already exists.
180
            An error occurred when inserting this authorized value. Perhaps the value or the category already exists.
181
        [% CASE 'error_on_insert_cat' %]
182
            An error occurred when inserting this authorized value category. Perhaps the category name already exists.
181
        [% CASE 'error_on_delete' %]
183
        [% CASE 'error_on_delete' %]
182
            An error occurred when deleting this authorized value. Check the logs.
184
            An error occurred when deleting this authorized value. Check the logs.
183
        [% CASE 'success_on_update' %]
185
        [% CASE 'success_on_update' %]
184
            Authorized value updated successfully.
186
            Authorized value updated successfully.
185
        [% CASE 'success_on_insert' %]
187
        [% CASE 'success_on_insert' %]
186
            Authorized value added successfully.
188
            Authorized value added successfully.
189
        [% CASE 'success_on_insert_cat' %]
190
            Authorized value category added successfully.
187
        [% CASE 'success_on_delete' %]
191
        [% CASE 'success_on_delete' %]
188
            Authorized value deleted successfully.
192
            Authorized value deleted successfully.
189
        [% CASE 'already_exists' %]
193
        [% CASE 'already_exists' %]
190
            This authorized value already exists.
194
            This authorized value already exists.
195
        [% CASE 'cat_already_exists' %]
196
            This authorized value category already exists.
197
        [% CASE 'invalid_category_name' %]
198
            The authorized value category 'branches', 'itemtypes' and 'cn_source' are used internally by Koha and are not valid.
191
        [% CASE %]
199
        [% CASE %]
192
            [% m.code %]
200
            [% m.code %]
193
        [% END %]
201
        [% END %]
194
- 

Return to bug 17216