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

(-)a/admin/authorised_values.pl (-12 / +36 lines)
Lines 26-31 use C4::Koha; Link Here
26
use C4::Output;
26
use C4::Output;
27
27
28
use Koha::AuthorisedValues;
28
use Koha::AuthorisedValues;
29
use Koha::AuthorisedValueCategories;
29
use Koha::Libraries;
30
use Koha::Libraries;
30
31
31
my $input = new CGI;
32
my $input = new CGI;
Lines 112-117 if ($op eq 'add_form') { Link Here
112
    if ( $already_exists and ( not $id or $already_exists->id != $id ) ) {
113
    if ( $already_exists and ( not $id or $already_exists->id != $id ) ) {
113
        push @messages, {type => 'error', code => 'already_exists' };
114
        push @messages, {type => 'error', code => 'already_exists' };
114
    }
115
    }
116
    elsif ( $new_category eq 'branches' or $new_category eq 'itemtypes' or $new_category eq 'cn_source' ) {
117
        push @messages, {type => 'error', code => 'invalid_category_name' };
118
    }
115
    elsif ( $id ) { # Update
119
    elsif ( $id ) { # Update
116
        my $av = Koha::AuthorisedValues->new->find( $id );
120
        my $av = Koha::AuthorisedValues->new->find( $id );
117
121
Lines 153-158 if ($op eq 'add_form') { Link Here
153
157
154
    $op = 'list';
158
    $op = 'list';
155
    $searchfield = $new_category;
159
    $searchfield = $new_category;
160
} elsif ($op eq 'add_category' ) {
161
    my $new_category = $input->param('category');
162
163
    my $already_exists = Koha::AuthorisedValueCategories->find(
164
        {
165
            category_name => $new_category,
166
        }
167
    );
168
169
    if ( $already_exists ) {
170
        push @messages, {type => 'error', code => 'cat_already_exists' };
171
    }
172
    else { # Insert
173
        my $av = Koha::AuthorisedValueCategory->new( {
174
            category_name => $new_category,
175
        } );
176
177
        eval {
178
            $av->store;
179
        };
180
181
        if ( $@ ) {
182
            push @messages, {type => 'error', code => 'error_on_insert_cat' };
183
        } else {
184
            push @messages, { type => 'message', code => 'success_on_insert_cat' };
185
        }
186
    }
187
188
    $op = 'list';
189
    $searchfield = $new_category;
156
} elsif ($op eq 'delete') {
190
} elsif ($op eq 'delete') {
157
    my $av = Koha::AuthorisedValues->new->find( $input->param('id') );
191
    my $av = Koha::AuthorisedValues->new->find( $input->param('id') );
158
    my $deleted = eval {$av->delete};
192
    my $deleted = eval {$av->delete};
Lines 174-195 $template->param( Link Here
174
208
175
if ( $op eq 'list' ) {
209
if ( $op eq 'list' ) {
176
    # build categories list
210
    # build categories list
177
    my @categories = Koha::AuthorisedValues->new->categories;
211
    my @categories = Koha::AuthorisedValueCategories->search({}, { order_by => ['category_name'] } );
178
    my @category_list;
212
    my @category_list;
179
    my %categories;    # a hash, to check that some hardcoded categories exist.
180
    for my $category ( @categories ) {
213
    for my $category ( @categories ) {
181
        push( @category_list, $category );
214
        push( @category_list, $category->category_name );
182
        $categories{$category} = 1;
183
    }
215
    }
184
216
185
    # push koha system categories
186
    foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS ITEMTYPECAT)) {
187
        push @category_list, $_ unless $categories{$_};
188
    }
189
190
    #reorder the list
191
    @category_list = sort {$a cmp $b} @category_list;
192
193
    $searchfield ||= $category_list[0];
217
    $searchfield ||= $category_list[0];
194
218
195
    my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } );
219
    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