Bug 19673: Allow to set patron attributes to 0 with batch patron modification
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 21 Dec 2017 00:35:47 +0000 (21:35 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 28 Mar 2018 19:04:47 +0000 (16:04 -0300)
This patch will have to be tested deeply to make sure it will not
introduce regression!

The idea is to display an empty option in the patron attributes select
and ignore it. That way we can deal with false values 0 and "" which
were skipped before.

Test plan:
Add several patron attributes
Use the batch patron modification tool to add/update/remove them
Play with empty "" and 0 values, as well as other values
Modify several attributes in a row

Signed-off-by: Charles Farmer <charles.farmer@inLibro.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt
tools/modborrowers.pl

index 175c9c8..bbf39a0 100644 (file)
                                             <li class="attributes">
                                                 <label style="width:auto;">Attribute:
                                                     <select name="patron_attributes">
+                                                        <option value=""></option>
                                                         [% FOREACH pac IN patron_attributes_codes %]
                                                             <option value="[% pac.attribute_code %]" data-type="[% pac.type %]" data-category="[% pac.category_lib %]">[% pac.attribute_lib %]</option>
                                                         [% END %]
 
         function updateAttrValues (select_attr) {
             var attr_code = $(select_attr).val();
-            var type = $(select_attr).find("option:selected").attr('data-type');
-            var category = $(select_attr).find("option:selected").attr('data-category');
-            var span = $(select_attr).parent().parent().find('span.patron_attributes_value');
-            var information_category_node = $(select_attr).parent().parent().find('span.information_category');
+            var selected_option = $(select_attr).find("option:selected");
+            var type = $(selected_option).attr('data-type');
+            var category = $(selected_option).attr('data-category');
+            var li_node = $(select_attr).parent().parent();
+            var span = $(li_node).find('span.patron_attributes_value');
+            var information_category_node = $(li_node).find('span.information_category');
             information_category_node.html("");
-            if ( category.length > 0 ) {
+
+            if ( category && category.length > 0 ) {
                 information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category));
             }
+            var disable_input_node = $(li_node).find("input:checkbox[name='disable_input']");
             if ( type == 'select' ) {
                 var options = '<option value = ""></option>';
                 for ( var i = 0 ; i < patron_attributes_values[attr_code].length ; i++ ) {
                     options += '<option value="'+patron_attributes_values[attr_code][i]+'">'+patron_attributes_lib[attr_code][i]+'</option>';
                 }
                 span.html('<select name="patron_attributes_value">' + options + '</select>');
+                $(disable_input_node).show();
+            } else if ( $(selected_option).val() != "" ) {
+                span.html('<input type="text" name="patron_attributes_value"/>');
+                $(disable_input_node).show();
             } else {
-                span.html('<input type="text" name="patron_attributes_value"/>')
+                span.html('');
+                $(disable_input_node).hide();
             }
         }
 
index 586ae53..e53e3a3 100755 (executable)
@@ -320,9 +320,6 @@ if ( $op eq 'do' ) {
                 };
                 push @errors, { error => $@ } if $@;
             } else {
-                # Attribute's value is empty, we don't want to modify it
-                ++$i and next if not $attribute->{attribute};
-
                 eval {
                     C4::Members::Attributes::UpdateBorrowerAttribute( $borrowernumber, $attribute );
                 };