Bug 17216: Update the admin interface
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 29 Aug 2016 13:06:46 +0000 (14:06 +0100)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Tue, 11 Oct 2016 07:30:30 +0000 (07:30 +0000)
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
admin/authorised_values.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt

index 49fb661..f812038 100755 (executable)
@@ -26,6 +26,7 @@ use C4::Koha;
 use C4::Output;
 
 use Koha::AuthorisedValues;
+use Koha::AuthorisedValueCategories;
 use Koha::Libraries;
 
 my $input = new CGI;
@@ -112,6 +113,9 @@ if ($op eq 'add_form') {
     if ( $already_exists and ( not $id or $already_exists->id != $id ) ) {
         push @messages, {type => 'error', code => 'already_exists' };
     }
+    elsif ( $new_category eq 'branches' or $new_category eq 'itemtypes' or $new_category eq 'cn_source' ) {
+        push @messages, {type => 'error', code => 'invalid_category_name' };
+    }
     elsif ( $id ) { # Update
         my $av = Koha::AuthorisedValues->new->find( $id );
 
@@ -151,6 +155,36 @@ if ($op eq 'add_form') {
         }
     }
 
+    $op = 'list';
+    $searchfield = $new_category;
+} elsif ($op eq 'add_category' ) {
+    my $new_category = $input->param('category');
+
+    my $already_exists = Koha::AuthorisedValueCategories->find(
+        {
+            category_name => $new_category,
+        }
+    );
+
+    if ( $already_exists ) {
+        push @messages, {type => 'error', code => 'cat_already_exists' };
+    }
+    else { # Insert
+        my $av = Koha::AuthorisedValueCategory->new( {
+            category_name => $new_category,
+        } );
+
+        eval {
+            $av->store;
+        };
+
+        if ( $@ ) {
+            push @messages, {type => 'error', code => 'error_on_insert_cat' };
+        } else {
+            push @messages, { type => 'message', code => 'success_on_insert_cat' };
+        }
+    }
+
     $op = 'list';
     $searchfield = $new_category;
 } elsif ($op eq 'delete') {
@@ -174,22 +208,12 @@ $template->param(
 
 if ( $op eq 'list' ) {
     # build categories list
-    my @categories = Koha::AuthorisedValues->new->categories;
+    my @categories = Koha::AuthorisedValueCategories->search({}, { order_by => ['category_name'] } );
     my @category_list;
-    my %categories;    # a hash, to check that some hardcoded categories exist.
     for my $category ( @categories ) {
-        push( @category_list, $category );
-        $categories{$category} = 1;
+        push( @category_list, $category->category_name );
     }
 
-    # push koha system categories
-    foreach (qw(Asort1 Asort2 Bsort1 Bsort2 SUGGEST DAMAGED LOST REPORT_GROUP REPORT_SUBGROUP DEPARTMENT TERM SUGGEST_STATUS ITEMTYPECAT)) {
-        push @category_list, $_ unless $categories{$_};
-    }
-
-    #reorder the list
-    @category_list = sort {$a cmp $b} @category_list;
-
     $searchfield ||= $category_list[0];
 
     my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } );
index 2aa3b5f..f4f56cf 100644 (file)
@@ -77,25 +77,24 @@ $(document).ready(function() {
     [% 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 %]
 
  <form action="/cgi-bin/koha/admin/authorised_values.pl" name="Aform" method="post" class="validated">
-    <input type="hidden" name="op" value="add" />
         <fieldset class="rows"><ol>
-        <li>
-        [% IF ( action_add_category ) %]
-            <label for="category" class="required">Category: </label>
-            <input type="text" name="category"  id="category" size="32" maxlength="32" class="focus required" />
-            <span class="required">Required</span>
-                        [% ELSE %]<span class="label">Category</span>
-               <input type="hidden" name="category" value="[% category %]" />   [% category %]
-                        [% END %]
-        </li>
+        [% IF action_add_category %]
+            <li>
+                <label for="category" class="required">Category: </label>
+                <input type="text" name="category"  id="category" size="32" maxlength="32" class="focus required" />
+                <span class="required">Required</span>
+                <input type="hidden" name="op" value="add_category" />
+            </li>
+        [% ELSE %]
+            <li>
+                <span class="label">Category</span>
+                <input type="hidden" name="op" value="add" />
+                <input type="hidden" name="category" value="[% category %]" /> [% category %]
+            </li>
         <li>
             <label for="authorised_value">Authorized value: </label>
-     [% IF ( action_modify ) %]<input type="hidden" id="id" name="id" value="[% id %]" />[% END %]
-            [% IF ( action_add_category ) %]
-            <input type="text" id="authorised_value" name="authorised_value" value="[% authorised_value %]" maxlength="80" />
-            [% ELSE %]
+            [% IF ( action_modify ) %]<input type="hidden" id="id" name="id" value="[% id %]" />[% END %]
             <input type="text" id="authorised_value" name="authorised_value" value="[% authorised_value %]" maxlength="80" class="focus" />
-            [% END %]
         </li>
         <li>
             <label for="lib">Description: </label>
@@ -154,6 +153,7 @@ $(document).ready(function() {
   </div>
   [% END %]
   </div>
+        [% END %]
         </fieldset>
        <fieldset class="action"> <input type="hidden" name="id" value="[% id %]" />
         <input type="submit" value="Save" /> <a class="cancel" href="/cgi-bin/koha/admin/authorised_values.pl?searchfield=[% category %]">Cancel</a></fieldset>
@@ -178,16 +178,24 @@ $(document).ready(function() {
             An error occurred when updating this authorized value. Perhaps the value already exists.
         [% CASE 'error_on_insert' %]
             An error occurred when inserting this authorized value. Perhaps the value or the category already exists.
+        [% CASE 'error_on_insert_cat' %]
+            An error occurred when inserting this authorized value category. Perhaps the category name already exists.
         [% CASE 'error_on_delete' %]
             An error occurred when deleting this authorized value. Check the logs.
         [% CASE 'success_on_update' %]
             Authorized value updated successfully.
         [% CASE 'success_on_insert' %]
             Authorized value added successfully.
+        [% CASE 'success_on_insert_cat' %]
+            Authorized value category added successfully.
         [% CASE 'success_on_delete' %]
             Authorized value deleted successfully.
         [% CASE 'already_exists' %]
             This authorized value already exists.
+        [% CASE 'cat_already_exists' %]
+            This authorized value category already exists.
+        [% CASE 'invalid_category_name' %]
+            The authorized value category 'branches', 'itemtypes' and 'cn_source' are used internally by Koha and are not valid.
         [% CASE %]
             [% m.code %]
         [% END %]