Bug 3766: Cities/Towns only on one address
authorOwen Leonard <oleonard@myacpl.org>
Wed, 6 Mar 2019 19:59:53 +0000 (19:59 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Wed, 17 Apr 2019 12:25:25 +0000 (12:25 +0000)
This patch ties the alternate address and alternate contact address
fields in the patron entry form to the cities and towns data. This
provides a dropdown of predefined city data to these address fields.

To test, apply the patch and edit a patron record.

Test city selection for all three address fields: Main address,
alternate address, and alternate contact. Confirm that city selection
works correctly and that your changes are saved correctly.

Perform these tests with all AddressFormat options: French, German, and
US.

Signed-off-by: Liz Rea <wizzyrea@gmail.com>

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

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-de.inc
koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-fr.inc
koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-us.inc
koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-de.inc
koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-fr.inc
koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-us.inc
koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-de.inc
koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-fr.inc
koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-us.inc
koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
koha-tmpl/intranet-tmpl/prog/js/members.js

index 3171105..8253299 100644 (file)
@@ -1,17 +1,5 @@
         <fieldset class="rows" id="memberentry_address">
         <legend id="alt_address_lgd">Alternate address</legend><ol>
-        [% UNLESS noB_address %]
-            <li>
-                [% IF ( mandatoryB_address ) %]
-                    <label for="B_address" class="required">
-                [% ELSE %]
-                    <label for="B_address">
-                [% END %]
-                Address: </label>
-                    <input type="text" id="B_address" name="B_address" size="40" value="[% patron.B_address | html %]" />
-      [% IF ( mandatoryB_address ) %]<span class="required">Required</span>[% END %]
-            </li>
-        [% END %]
 
         [% IF roadtypes %]
                 <li>
             </li>
         [% END %]
 
+        [% UNLESS noB_address %]
+            <li>
+                [% IF ( mandatoryB_address ) %]
+                    <label for="B_address" class="required">
+                [% ELSE %]
+                    <label for="B_address">
+                [% END %]
+                Address: </label>
+                    <input type="text" id="B_address" name="B_address" size="40" value="[% patron.B_address | html %]" />
+      [% IF ( mandatoryB_address ) %]<span class="required">Required</span>[% END %]
+            </li>
+        [% END %]
+
         [% UNLESS noB_streetnumber %]
             <li>
                 [% IF ( mandatoryB_streetnumber ) %]
                 [% END %]
                 City: </label>
                 <input type="text" id="B_city" name="B_city" size="20" value="[% patron.B_city | html %]" />
+                [% IF cities.count %]or choose
+                    <select class="select_city" data-addressfield="B_" name="select_city">
+                        <option value="|||"></option>
+                        [% FOREACH c IN cities %]
+                            [% IF c.city_name == patron.B_city && c.city_state == patron.B_state && c.city_zipcode == patron.B_zipcode %]
+                            <option value="[% c.city_zipcode | html %]|[% c.city_name | html %]|[% c.city_state | html %]|[% c.city_country | html %]" selected="selected">
+                            [% ELSE %]
+                            <option value="[% c.city_zipcode | html %]|[% c.city_name | html %]|[% c.city_state | html %]|[% c.city_country | html %]">
+                            [% END %]
+                                [% c.city_name | html %] [% c.city_state | html %] [% c.city_zipcode | html %]
+                            </option>
+                        [% END %]
+                    </select>
+                [% END %]
       [% IF ( mandatoryB_city ) %]<span class="required">Required</span>[% END %]
             </li>
         [% END %]
index 9d0cda0..6f376e4 100644 (file)
     [% END %]
     City: </label>
     <input type="text" id="B_city" name="B_city" size="20" value="[% patron.B_city | html %]" />
+                [% IF cities.count %]or choose
+                    <select class="select_city" data-addressfield="B_" name="select_city">
+                        <option value="|||"></option>
+                        [% FOREACH c IN cities %]
+                            [% IF c.city_name == patron.B_city && c.city_state == patron.B_state && c.city_zipcode == patron.B_zipcode %]
+                            <option value="[% c.city_zipcode | html %]|[% c.city_name | html %]|[% c.city_state | html %]|[% c.city_country | html %]" selected="selected">
+                            [% ELSE %]
+                            <option value="[% c.city_zipcode | html %]|[% c.city_name | html %]|[% c.city_state | html %]|[% c.city_country | html %]">
+                            [% END %]
+                                [% c.city_name | html %] [% c.city_state | html %] [% c.city_zipcode | html %]
+                            </option>
+                        [% END %]
+                    </select>
+                [% END %]
     [% IF ( mandatoryB_city ) %]<span class="required">Required</span>[% END %]
     </li>
 [% END %]
index 6afd3e1..ec3d6e2 100644 (file)
                 [% END %]
                 City: </label>
                 <input type="text" id="B_city" name="B_city" size="20" value="[% patron.B_city | html %]" />
-      [% IF ( mandatoryB_city ) %]<span class="required">Required</span>[% END %]
+                [% IF cities.count %]or choose
+                    <select class="select_city" data-addressfield="B_" name="select_city">
+                        <option value="|||"></option>
+                        [% FOREACH c IN cities %]
+                            [% IF c.city_name == patron.B_city && c.city_state == patron.B_state && c.city_zipcode == patron.B_zipcode %]
+                            <option value="[% c.city_zipcode | html %]|[% c.city_name | html %]|[% c.city_state | html %]|[% c.city_country | html %]" selected="selected">
+                            [% ELSE %]
+                            <option value="[% c.city_zipcode | html %]|[% c.city_name | html %]|[% c.city_state | html %]|[% c.city_country | html %]">
+                            [% END %]
+                                [% c.city_name | html %] [% c.city_state | html %] [% c.city_zipcode | html %]
+                            </option>
+                        [% END %]
+                    </select>
+                [% END %]
+                [% IF ( mandatoryB_city ) %]<span class="required">Required</span>[% END %]
             </li>
         [% END %]
         [% UNLESS noB_state %]
                 <label for="contactnote">
                 [% END %]
                 Contact note: </label>
-                <textarea id="contactnote" name="contactnote" cols="40" rows="2">[% contactnote | html %]</textarea>
+                <textarea id="contactnote" name="contactnote" cols="40" rows="2">[% patron.contactnote | html %]</textarea>
         [% IF ( mandatorycontactnote ) %]<span class="required">Required</span>[% END %]
             </li>
         [% END %]
index cbc2f7e..b760add 100644 (file)
                 <label for="altcontactaddress3">
                 [% END %]
                 City:</label>
-                <input type="text" name="altcontactaddress3" id="altcontactaddress3" value="[% patron.altcontactaddress3 | html %]" size="20" />
+                <input type="text" name="altcontactaddress3" id="altcontactcity" value="[% patron.altcontactaddress3 | html %]" size="20" />
+                [% IF cities.count %]or choose
+                    <select class="select_city" data-addressfield="altcontact" name="select_city">
+                        <option value="|||"></option>
+                        [% FOREACH c IN cities %]
+                            [% IF c.city_name == patron.altcontactaddress3 && c.city_state == patron.altcontactstate && c.city_zipcode == patron.altcontactzipcode %]
+                            <option value="[% c.city_zipcode | html %]|[% c.city_name | html %]|[% c.city_state | html %]|[% c.city_country | html %]" selected="selected">
+                            [% ELSE %]
+                            <option value="[% c.city_zipcode | html %]|[% c.city_name | html %]|[% c.city_state | html %]|[% c.city_country | html %]">
+                            [% END %]
+                                [% c.city_name | html %] [% c.city_state | html %] [% c.city_zipcode | html %]
+                            </option>
+                        [% END %]
+                    </select>
+                [% END %]
                 [% IF ( mandatoryaltcontactaddress3 ) %]<span class="required">Required</span>[% END %]
             </li>
         [% END %]
index 60c0fec..333f5a7 100644 (file)
 [% UNLESS noaltcontactaddress3 %]
     <li>
     [% IF ( mandatoryaltcontactaddress3 ) %]
-        <label for="altcontactaddress3" class="required">
+        <label for="altcontactcity" class="required">
     [% ELSE %]
-        <label for="altcontactaddress3">
+        <label for="altcontactcity">
     [% END %]
     City:</label>
-    <input type="text" name="altcontactaddress3" id="altcontactaddress3" value="[% patron.altcontactaddress3 | html %]" size="20" />
+    <input type="text" name="altcontactaddress3" id="altcontactcity" value="[% patron.altcontactaddress3 | html %]" size="20" />
+    [% IF cities.count %]or choose
+        <select class="select_city" data-addressfield="altcontact" name="select_city">
+            <option value="|||"></option>
+            [% FOREACH c IN cities %]
+                [% IF c.city_name == patron.altcontactaddress3 && c.city_state == patron.altcontactstate && c.city_zipcode == patron.altcontactzipcode %]
+                <option value="[% c.city_zipcode | html %]|[% c.city_name | html %]|[% c.city_state | html %]|[% c.city_country | html %]" selected="selected">
+                [% ELSE %]
+                <option value="[% c.city_zipcode | html %]|[% c.city_name | html %]|[% c.city_state | html %]|[% c.city_country | html %]">
+                [% END %]
+                    [% c.city_name | html %] [% c.city_state | html %] [% c.city_zipcode | html %]
+                </option>
+            [% END %]
+        </select>
+    [% END %]
     [% IF ( mandatoryaltcontactaddress3 ) %]<span class="required">Required</span>[% END %]
     </li>
 [% END %]
index bd8c049..5191897 100644 (file)
         [% UNLESS noaltcontactaddress3 %]
             <li>
                 [% IF ( mandatoryaltcontactaddress3 ) %]
-                <label for="altcontactaddress3" class="required">
+                <label for="altcontactcity" class="required">
                 [% ELSE %]
-                <label for="altcontactaddress3">
+                <label for="altcontactcity">
                 [% END %]
                 City:</label>
-                <input type="text" name="altcontactaddress3" id="altcontactaddress3" value="[% patron.altcontactaddress3 | html %]" size="20" />
+                <input type="text" name="altcontactaddress3" id="altcontactcity" value="[% patron.altcontactaddress3 | html %]" size="20" />
+                [% IF cities.count %]or choose
+                    <select class="select_city" data-addressfield="altcontact" name="select_city">
+                        <option value="|||"></option>
+                        [% FOREACH c IN cities %]
+                            [% IF c.city_name == patron.altcontactaddress3 && c.city_state == patron.altcontactstate && c.city_zipcode == patron.altcontactzipcode %]
+                            <option value="[% c.city_zipcode | html %]|[% c.city_name | html %]|[% c.city_state | html %]|[% c.city_country | html %]" selected="selected">
+                            [% ELSE %]
+                            <option value="[% c.city_zipcode | html %]|[% c.city_name | html %]|[% c.city_state | html %]|[% c.city_country | html %]">
+                            [% END %]
+                                [% c.city_name | html %] [% c.city_state | html %] [% c.city_zipcode | html %]
+                            </option>
+                        [% END %]
+                    </select>
+                [% END %]
                 [% IF ( mandatoryaltcontactaddress3 ) %]<span class="required">Required</span>[% END %]
             </li>
         [% END %]
index a5c7c0f..818d7c6 100644 (file)
@@ -81,7 +81,7 @@
       City: </label>
         <input type="text" id="city" name="city" size="20" value="[% patron.city | html %]" />
         [% IF cities.count %]or choose
-        <select id="select_city" name="select_city">
+        <select class="select_city" data-addressfield="" name="select_city">
             <option value="|||"></option>
             [% FOREACH c IN cities %]
                 [% IF c.city_name == patron.city && c.city_state == patron.state && c.city_zipcode == patron.zipcode %]
index 245c773..a79df88 100644 (file)
@@ -2,14 +2,16 @@
     <legend id="main_address_lgd">Main address</legend><ol>
 [% UNLESS nostreettype %]
     [% UNLESS nostreetnumber %]
-        [% IF ( mandatorystreetnumber ) %]
-            <label for="streetnumber" class="required">
-        [% ELSE %]
-            <label for="streetnumber">
-        [% END %]
-            Street number: </label>
-            <input type="text" id="streetnumber" name="streetnumber" size="5" value="[% patron.streetnumber | html %]" />
-        [% IF ( mandatorystreetnumber ) %]<span class="required">Required</span>[% END %]
+        <li>
+            [% IF ( mandatorystreetnumber ) %]
+                <label for="streetnumber" class="required">
+            [% ELSE %]
+                <label for="streetnumber">
+            [% END %]
+                Street number: </label>
+                <input type="text" id="streetnumber" name="streetnumber" size="5" value="[% patron.streetnumber | html %]" />
+            [% IF ( mandatorystreetnumber ) %]<span class="required">Required</span>[% END %]
+        </li>
     [% END %]
 
     [% IF roadtypes %]
@@ -80,7 +82,7 @@
     City: </label>
     <input type="text" id="city" name="city" size="20" value="[% patron.city | html %]" />
     [% IF cities.count %]or choose
-        <select id="select_city" name="select_city">
+        <select class="select_city" data-addressfield="" name="select_city">
             <option value="|||"></option>
         [% FOREACH c IN cities %]
             [% IF c.city_name == patron.city && c.city_state == patron.state && c.city_zipcode == patron.zipcode %]
index 4c95b59..0db6e83 100644 (file)
@@ -69,7 +69,7 @@
       City: </label>
         <input type="text" id="city" name="city" size="20" value="[% patron.city | html %]" />
         [% IF cities.count %]or choose
-        <select id="select_city" name="select_city">
+        <select class="select_city" data-addressfield="" name="select_city">
             <option value="|||"></option>
             [% FOREACH c IN cities %]
                 [% IF c.city_name == patron.city && c.city_state == patron.state && c.city_zipcode == patron.zipcode %]
index 1ca6d63..62fc2db 100644 (file)
 
 [% END %]
 [% UNLESS noaddress && noaddress2 && nocity && nostate && nozipcode && nocountry %]
-    [% SWITCH Koha.Preference( 'AddressFormat' ) %]
-        [% CASE 'de' %]
-            [% INCLUDE 'member-main-address-style-de.inc' %]
-        [% CASE # us %]
-            [% INCLUDE 'member-main-address-style-us.inc' %]
-     [% END %]
+    [% IF Koha.Preference( 'AddressFormat' ) %]
+        [% INCLUDE "member-main-address-style-${ Koha.Preference( 'AddressFormat' ) }.inc" %]
+    [% END %]
 [% END # nostreet && nocity etc group%]
 
 [% UNLESS nophone && nophonepro && nomobile && noemail && noemailpro && nofax %]
index cfd3a83..bcca8ef 100644 (file)
@@ -293,14 +293,15 @@ $(document).ready(function(){
         $("#quick_add_form #guarantorsearch, #guarantorsearch").val(LABEL_SET_TO_PATRON);
     });
 
-    $(document.body).on('change','select[name="select_city"]',function(){
-        $('select[name="select_city"]').val( $(this).val() );
+    $(document.body).on('change','.select_city',function(){
+        var selected_city = $(this).val();
+        var addressfield = $(this).data("addressfield");
         var myRegEx=new RegExp(/(.*)\|(.*)\|(.*)\|(.*)/);
-        $(this).val().match(myRegEx);
-        $('input[name="zipcode"]').val( RegExp.$1 );
-        $('input[name="city"]').val( RegExp.$2 );
-        $('input[name="state"]').val( RegExp.$3 );
-        $('input[name="country"]').val( RegExp.$4 );
+        var matches = selected_city.match( myRegEx );
+        $("#" + addressfield + "zipcode").val( matches[1] );
+        $("#" + addressfield + "city").val( matches[2] );
+        $("#" + addressfield + "state").val( matches[3] );
+        $("#" + addressfield + "country").val( matches[4] );
     });
 
     dateformat = $("#dateofbirth").siblings(".hint").first().html();