From 51dd3a9452b79ab62075ef44412a782c4493d020 Mon Sep 17 00:00:00 2001
From: Owen Leonard <oleonard@myacpl.org>
Date: Wed, 6 Mar 2019 19:59:53 +0000
Subject: [PATCH] Bug 3766: Cities/Towns and Road Types 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>
---
.../en/includes/member-alt-address-style-de.inc | 39 +++++++++++++++-------
.../en/includes/member-alt-address-style-fr.inc | 14 ++++++++
.../en/includes/member-alt-address-style-us.inc | 18 ++++++++--
.../en/includes/member-alt-contact-style-de.inc | 16 ++++++++-
.../en/includes/member-alt-contact-style-fr.inc | 20 +++++++++--
.../en/includes/member-alt-contact-style-us.inc | 20 +++++++++--
.../en/includes/member-main-address-style-de.inc | 2 +-
.../en/includes/member-main-address-style-fr.inc | 20 ++++++-----
.../en/includes/member-main-address-style-us.inc | 2 +-
.../prog/en/modules/members/memberentrygen.tt | 11 +++---
koha-tmpl/intranet-tmpl/prog/js/members.js | 15 +++++----
11 files changed, 131 insertions(+), 46 deletions(-)
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-de.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-de.inc
index 3171105ccc..82532998ab 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-de.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-de.inc
@@ -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 %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-fr.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-fr.inc
index 9d0cda01ac..6f376e4771 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-fr.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-fr.inc
@@ -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 %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-us.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-us.inc
index 6afd3e1898..ec3d6e274c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-us.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-address-style-us.inc
@@ -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 %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-de.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-de.inc
index cbc2f7eab7..b760addb5a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-de.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-de.inc
@@ -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 %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-fr.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-fr.inc
index 60c0fec2d2..333f5a718e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-fr.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-fr.inc
@@ -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 %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-us.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-us.inc
index bd8c0493ce..5191897f1f 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-us.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/member-alt-contact-style-us.inc
@@ -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 %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-de.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-de.inc
index a5c7c0fe27..818d7c6317 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-de.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-de.inc
@@ -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 %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-fr.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-fr.inc
index 245c773bc0..a79df88123 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-fr.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-fr.inc
@@ -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 %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-us.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-us.inc
index 4c95b59aef..0db6e834dd 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-us.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/member-main-address-style-us.inc
@@ -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 %]
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 6d4b0e867a..d4db454fe7 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
@@ -141,7 +141,7 @@
[% IF opadd %]
<a class="btn btn-default" href="/cgi-bin/koha/members/member.pl" class="toggler save_entryform">
[% ELSE %]
- <a class="btn btn-default btn-sm" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber | html %]">
+ <a class="btn btn-default" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber | html %]">
[% END %]
<i class="fa fa-times"></i> Cancel
</a>
@@ -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 %]
diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js
index e586e60d23..fec68e3fb0 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/members.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/members.js
@@ -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();
--
2.11.0