[Koha-patches] [PATCH 1/1] Bug 7154: Followup: Adds tables on modify + class filled wih AV

Jonathan Druart jonathan.druart at biblibre.com
Fri Jan 6 16:09:00 CET 2012


- FIX display/hide attr on memberentry.pl when category changes
- Attr classes filled with AV 'PA_CLASS' category (you have to create AV
  with a new category 'PA_CLASS' to fill class list)
- Use tables (classes separation) on member modification and attr management
  (admin). Theses array are sorted by name.
---
 admin/patron-attr-types.pl                         |   28 +++++-
 .../prog/en/modules/admin/patron-attr-types.tt     |   62 +++++++----
 .../prog/en/modules/members/memberentrygen.tt      |  108 +++++++++++---------
 members/memberentry.pl                             |   17 +++-
 members/moremember.pl                              |    2 +-
 5 files changed, 136 insertions(+), 81 deletions(-)

diff --git a/admin/patron-attr-types.pl b/admin/patron-attr-types.pl
index 377159b..5011bcb 100755
--- a/admin/patron-attr-types.pl
+++ b/admin/patron-attr-types.pl
@@ -22,6 +22,8 @@
 use strict;
 use warnings;
 use CGI;
+use List::MoreUtils qw/uniq/;
+
 use C4::Auth;
 use C4::Context;
 use C4::Output;
@@ -84,6 +86,7 @@ sub add_attribute_type_form {
         confirm_op => 'add_attribute_type_confirmed',
     );
     authorised_value_category_list($template);
+    pa_classes($template);
 }
 
 sub error_add_attribute_type_form {
@@ -237,9 +240,9 @@ sub edit_attribute_type_form {
         $template->param(display_checkout_checked => 'checked="checked"');
     }
     authorised_value_category_list($template, $attr_type->authorised_value_category());
+    pa_classes( $template, $attr_type->class );
 
     $template->param ( category_type => $attr_type->category_type );
-    $template->param ( class => $attr_type->class );
 
     $template->param(
         attribute_type_form => 1,
@@ -251,9 +254,21 @@ sub edit_attribute_type_form {
 
 sub patron_attribute_type_list {
     my $template = shift;
-    
+
     my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes();
-    $template->param(available_attribute_types => \@attr_types);
+    my @classes = sort uniq( map {$_->{class}} @attr_types );
+    my @attributes_loop;
+    for my $class (@classes) {
+        my @items;
+        for my $attr (@attr_types) {
+            push @items, $attr if $attr->{class} eq $class
+        }
+        push @attributes_loop, {
+            class => $class,
+            items => \@items
+        };
+    }
+    $template->param(available_attribute_types => \@attributes_loop);
     $template->param(display_list => 1);
 }
 
@@ -270,3 +285,10 @@ sub authorised_value_category_list {
     }
     $template->param(authorised_value_categories => \@list);
 }
+
+sub pa_classes {
+    my $template = shift;
+    my $selected = @_ ? shift : '';
+
+    $template->param(classes_val_loop => GetAuthorisedValues( 'PA_CLASS', $selected ) );
+}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt
index 4d32646..968791d 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt
@@ -201,8 +201,21 @@ function CheckAttributeTypeForm(f) {
         </li>
         <li>
             <label for="class">Class: </label>
-            <input type="text" id="class" name="class"  size="20" value="[% class | html %]"/>
-            <span>Group attributes types with a block title</span>
+            <select name="class">
+                <option value="" />
+                [% FOREACH class IN classes_val_loop %]
+                    [% IF ( class.selected ) %]
+                        <option value="[% class.authorised_value %]" selected="selected">
+                            [% class.lib %]
+                        </option>
+                    [% ELSE %]
+                        <option value="[% class.authorised_value %]" >
+                            [% class.lib %]
+                        </option>
+                    [% END %]
+                [% END %]
+            </select>
+            <span>Group attributes types with a block title (based on Authorised values category 'PA_CLASS')</span>
         </li>
     </ol>
   </fieldset>
@@ -267,29 +280,32 @@ function CheckAttributeTypeForm(f) {
     &mdash; it was already absent from the database.</div>
 [% END %]
 [% IF ( available_attribute_types ) %]
-  <table id="patron_attributes_types">
-    <thead>
-      <tr>
-        <th>Class</th>
-        <th>Code</th>
-        <th>Description</th>
-        <th>Actions</th>
-      </tr>
-    </thead>
-    <tbody>
-      [% FOREACH available_attribute_type IN available_attribute_types %]
+  [% FOREACH attribute IN available_attribute_types %]
+    [% IF attribute.class %]
+        <h4>[% attribute.class %]</h4>
+    [% END %]
+    <table class="patron_attributes_types">
+      <thead>
         <tr>
-          <td>[% available_attribute_type.class |html %]</td>
-          <td>[% available_attribute_type.code |html %]</td>
-          <td>[% available_attribute_type.description %]</td>
-          <td>
-            <a href="[% available_attribute_type.script_name %]?op=edit_attribute_type&amp;code=[% available_attribute_type.code |html %]">Edit</a>
-            <a href="[% available_attribute_type.script_name %]?op=delete_attribute_type&amp;code=[% available_attribute_type.code |html %]">Delete</a>
-          </td>
+          <th>Code</th>
+          <th>Description</th>
+          <th>Actions</th>
         </tr>
-      [% END %]
-    </tbody>
-  </table>
+      </thead>
+      <tbody>
+        [% FOREACH item IN attribute.items %]
+          <tr>
+            <td>[% item.code |html %]</td>
+            <td>[% item.description %]</td>
+            <td>
+              <a href="[% item.script_name %]?op=edit_attribute_type&amp;code=[% item.code |html %]">Edit</a>
+              <a href="[% item.script_name %]?op=delete_attribute_type&amp;code=[% item.code |html %]">Delete</a>
+            </td>
+          </tr>
+        [% END %]
+      </tbody>
+    </table>
+  [% END %]
 [% ELSE %]
   <p>There are no saved patron attribute types.</p>
 [% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
index 9c31271..d355111 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
@@ -63,16 +63,19 @@
     }
 
     function update_category_code(category_type) {
-        var mytable = $("#attributes_table>tbody");
+        if ( $(category_type).is("select") ) {
+            category_type = $("#categorycode").find("option:selected").attr("data-typename");
+        }
+        var mytables = $(".attributes_table>tbody");
 
-        mytable.find("tr").each(function(){
+        mytables.find("tr").each(function(){
             $(this).hide()
         });
 
-        mytable.find("tr[data-category_type="+category_type+"]").each(function(){
+        mytables.find("tr[data-category_type="+category_type+"]").each(function(){
             $(this).show();
         });
-        mytable.find("tr[data-category_type='']").each(function(){
+        mytables.find("tr[data-category_type='']").each(function(){
             $(this).show();
         });
 
@@ -1192,7 +1195,7 @@
 			       [% IF ( opduplicate ) %] 
 			           <textarea id="debarredcomment" name="debarredcomment" cols="55" rows="3" onclick="this.value=''">[% debarredcomment %]</textarea>
 			       [% ELSE %]
-				   <textarea id="debarredcomment" name="debarredcomment" cols="55" rows="3" ">[% debarredcomment %]</textarea> 
+				   <textarea id="debarredcomment" name="debarredcomment" cols="55" rows="3" >[% debarredcomment %]</textarea>
 			       [% END %]
 	        </li>
 
@@ -1207,62 +1210,67 @@
   <fieldset class="rows" id="memberentry_patron_attributes">
     <input type="hidden" name="setting_extended_patron_attributes" value="1" />
     <legend>Additional attributes and identifiers</legend>
-    <table id="attributes_table">
+    [% FOREACH pa_loo IN patron_attributes %]
+        [% IF pa_loo.class %]
+            <h4>[% pa_loo.class %]</h4>
+            <table id=aai_[% pa_loo.class %] class="attributes_table">
+        [% ELSE %]
+            <table id="aai" class="attributes_table">
+        [% END %]
         <thead>
             <tr>
-                <th>Class</th>
                 <th>Type</th>
                 <th colspan="2">Value</th>
             </tr>
         </thead>
         <tbody>
-        [% FOREACH patron_attribute IN patron_attributes %]
-        <tr data-category_type="[% patron_attribute.category_type %]">
-            <td>[% patron_attribute.class %]</td>
-            <td>
-                [% patron_attribute.code %] ([% patron_attribute.description %])
-            </td>
-            <td>
-                <input type="hidden" id="[% patron_attribute.form_id %]_code" name="[% patron_attribute.form_id %]_code" value="[% patron_attribute.code |html %]" />
-                [% IF ( patron_attribute.use_dropdown ) %]
-                    <select id="[% patron_attribute.form_id %]" name="[% patron_attribute.form_id %]">
-                        <option value="" />
-                        [% FOREACH auth_val_loo IN patron_attribute.auth_val_loop %]
-                            [% IF ( auth_val_loo.selected ) %]
-                                <option value="[% auth_val_loo.authorised_value %]" selected="selected">
-                                    [% auth_val_loo.lib %]
-                                </option>
+            [% FOREACH patron_attribute IN pa_loo.items %]
+                <tr data-category_type="[% patron_attribute.category_type %]">
+                    <td>
+                        [% patron_attribute.code %] ([% patron_attribute.description %])
+                    </td>
+                    <td>
+                        <input type="hidden" id="[% patron_attribute.form_id %]_code" name="[% patron_attribute.form_id %]_code" value="[% patron_attribute.code |html %]" />
+                        [% IF ( patron_attribute.use_dropdown ) %]
+                            <select id="[% patron_attribute.form_id %]" name="[% patron_attribute.form_id %]">
+                                <option value="" />
+                                [% FOREACH auth_val_loo IN patron_attribute.auth_val_loop %]
+                                    [% IF ( auth_val_loo.selected ) %]
+                                        <option value="[% auth_val_loo.authorised_value %]" selected="selected">
+                                            [% auth_val_loo.lib %]
+                                        </option>
+                                    [% ELSE %]
+                                        <option value="[% auth_val_loo.authorised_value %]" >
+                                            [% auth_val_loo.lib %]
+                                        </option>
+                                    [% END %]
+                                [% END %]
+                            </select>
+                        [% ELSE %]
+                            [% IF ( opduplicate ) %]
+                            <input type="text" maxlength="64" value="[% patron_attribute.value %]"
+                                   id="[% patron_attribute.form_id %]" name="[% patron_attribute.form_id %]" onclick="this.value=''" />
                             [% ELSE %]
-                                <option value="[% auth_val_loo.authorised_value %]" >
-                                    [% auth_val_loo.lib %]
-                                </option>
+                            <input type="text" maxlength="64" value="[% patron_attribute.value %]"
+                                   id="[% patron_attribute.form_id %]" name="[% patron_attribute.form_id %]" />
                             [% END %]
                         [% END %]
-                    </select>
-                [% ELSE %]
-                    [% IF ( opduplicate ) %]
-                    <input type="text" maxlength="64" value="[% patron_attribute.value %]"
-                           id="[% patron_attribute.form_id %]" name="[% patron_attribute.form_id %]" onclick="this.value=''" />
-                    [% ELSE %]
-                    <input type="text" maxlength="64" value="[% patron_attribute.value %]"
-                           id="[% patron_attribute.form_id %]" name="[% patron_attribute.form_id %]" />
-                    [% END %]
-                [% END %]
-                [% IF ( patron_attribute.password_allowed ) %]
-                    (Password: <input type="password" maxlength="64" value="[% patron_attribute.password %]"
-                           id="[% patron_attribute.form_id %]_password" name="[% patron_attribute.form_id %]_password" />)
-                [% END %]
-            </td>
-            <td>
-                <a href="#" onclick="clear_entry(this); return false;">Clear</a>
-                [% IF ( patron_attribute.repeatable ) %]
-                <a href="#" onclick="clone_entry(this); return false;">New</a>
-                [% END %]
-            </td>
-        </tr>
-        [% END %]
+                        [% IF ( patron_attribute.password_allowed ) %]
+                            (Password: <input type="password" maxlength="64" value="[% patron_attribute.password %]"
+                                   id="[% patron_attribute.form_id %]_password" name="[% patron_attribute.form_id %]_password" />)
+                        [% END %]
+                    </td>
+                    <td>
+                        <a href="#" onclick="clear_entry(this); return false;">Clear</a>
+                        [% IF ( patron_attribute.repeatable ) %]
+                        <a href="#" onclick="clone_entry(this); return false;">New</a>
+                        [% END %]
+                    </td>
+                </tr>
+            [% END %]
         </tbody>
-    </table>
+        </table>
+    [% END %]
   </fieldset>
 [% END %][% END %][% END %]
 
diff --git a/members/memberentry.pl b/members/memberentry.pl
index 51ff108..8211880 100755
--- a/members/memberentry.pl
+++ b/members/memberentry.pl
@@ -25,6 +25,7 @@ use warnings;
 # external modules
 use CGI;
 # use Digest::MD5 qw(md5_base64);
+use List::MoreUtils qw/uniq/;
 
 # internal modules
 use C4::Auth;
@@ -407,7 +408,7 @@ if ($op eq 'add'){
 if ($op eq "modify")  {
     $template->param( updtype => 'M',modify => 1 );
     $template->param( step_1=>1, step_2=>1, step_3=>1, step_4=>1, step_5 => 1, step_6 => 1) unless $step;
-    if ( $step = 4 ) {
+    if ( $step == 4 ) {
         $template->param( category_type => $borrower_data->{'categorycode'} );
     }
 }
@@ -751,6 +752,7 @@ sub patron_attributes_form {
         return;
     }
     my $attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
+    my @classes = sort uniq( map {$_->{class}} @$attributes );
 
     # map patron's attributes into a more convenient structure
     my %attr_hash = ();
@@ -760,6 +762,7 @@ sub patron_attributes_form {
 
     my @attribute_loop = ();
     my $i = 0;
+    my %items_by_class;
     foreach my $type_code (map { $_->{code} } @types) {
         my $attr_type = C4::Members::AttributeTypes->fetch($type_code);
         my $entry = {
@@ -784,8 +787,7 @@ sub patron_attributes_form {
                 }
                 $i++;
                 $newentry->{form_id} = "patron_attr_$i";
-                #use Data::Dumper; die Dumper($entry) if  $entry->{use_dropdown};
-                push @attribute_loop, $newentry;
+                push @{$items_by_class{$attr_type->class()}}, $newentry;
             }
         } else {
             $i++;
@@ -795,9 +797,16 @@ sub patron_attributes_form {
                 $newentry->{auth_val_loop} = GetAuthorisedValues($attr_type->authorised_value_category());
             }
             $newentry->{form_id} = "patron_attr_$i";
-            push @attribute_loop, $newentry;
+            push @{$items_by_class{$attr_type->class()}}, $newentry;
         }
     }
+    while ( my ($class, @items) = each %items_by_class ) {
+        push @attribute_loop, {
+            class => $class,
+            items => @items
+        }
+    }
+
     $template->param(patron_attributes => \@attribute_loop);
 
 }
diff --git a/members/moremember.pl b/members/moremember.pl
index e48538e..d12203e 100755
--- a/members/moremember.pl
+++ b/members/moremember.pl
@@ -432,7 +432,7 @@ $template->param(%$data);
 
 if (C4::Context->preference('ExtendedPatronAttributes')) {
     my $attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
-    my @classes = uniq( map {$_->{class}} @$attributes );
+    my @classes = sort uniq( map {$_->{class}} @$attributes );
     my @attributes_loop;
     for my $class (@classes) {
         my @items;
-- 
1.7.7.3



More information about the Koha-patches mailing list