Bug 3766: Cities/Towns only on one address

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>
This commit is contained in:
Owen Leonard 2019-03-06 19:59:53 +00:00 committed by Nick Clemens
parent 693bbc76e7
commit 4605d76a73
11 changed files with 130 additions and 45 deletions

View 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>
@ -35,6 +23,19 @@
</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 ) %]
@ -81,6 +82,20 @@
[% 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 %]

View file

@ -82,6 +82,20 @@
[% 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 %]

View file

@ -68,7 +68,21 @@
[% 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 %]
@ -138,7 +152,7 @@
<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 %]

View file

@ -68,7 +68,21 @@
<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 %]

View file

@ -63,12 +63,26 @@
[% 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 %]

View file

@ -51,12 +51,26 @@
[% 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 %]

View 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 %]

View 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 %]

View 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 %]

View file

@ -425,12 +425,9 @@
[% 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 %]

View 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();