From a5a3382066aef6fd22341e5c98c9bc5a04eb644d Mon Sep 17 00:00:00 2001 From: Matthew Wire <mjw@mjwconsult.co.uk> Date: Sat, 21 Mar 2020 17:50:03 +0000 Subject: [PATCH] Cleanup the postcode selector that was being added multiple times in some cases --- LICENSE.txt | 2 +- README.md | 36 +++++++++----- civicrmpostcodelookup.php | 9 ++-- info.xml | 12 ++--- .../Form/Postcodelookup.tpl | 49 +++++++------------ .../Form/Edit/Address/street_address.tpl | 1 - 6 files changed, 52 insertions(+), 57 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 7d971a4..7232c58 100755 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,5 +1,5 @@ Package: uk.co.vedaconsulting.module.civicrmpostcodelookup -Copyright (C) 2015, FIXME <FIXME> +Copyright (C) 2020, CiviCRM.org Licensed under the GNU Affero Public License 3.0 (below). ------------------------------------------------------------------------------- diff --git a/README.md b/README.md index cf3120a..ab13e93 100755 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Postcode lookup for CiviCRM -### Overview ### +## Overview For having postcode lookup feature in CiviCRM backend and Front end profiles. -### Supported Providers ### +### Supported Providers * [AFD](http://www.afd.co.uk) * [Civipostcode](http://civipostcode.com/) @@ -12,23 +12,37 @@ For having postcode lookup feature in CiviCRM backend and Front end profiles. * [PostcodeAnywhere](http://www.postcodeanywhere.co.uk/) * [getAddress()](https://getaddress.io/) -### Installation ### +### Installation -1. See: https://docs.civicrm.org/sysadmin/en/latest/customize/extensions/#installing-a-new-extension -1. Configure postcode lookup provider details in Administer >> Postcode Lookup(civicrm/admin/postcodelookup/settings?reset=1) +1. See: https://docs.civicrm.org/sysadmin/en/latest/customize/extensions/#installing-a-new-extension. +1. Configure postcode lookup provider details in *Administer->Postcode Lookup*. -### Permissions ### +### Permissions **From version 1.6 you need to give the `Access CiviCRM Postcode lookups` permission to anyone who can do postcode lookups (eg. anonymous user).** Previously the permission required was `Access CiviEvent`. ### Integration with Drupal Webform This drupal module provides integration with Drupal Webform: https://github.com/compucorp/webform_civicrm_postcode -### Usage ### +### Usage -* For backend, postcode lookup features is automatically enabled for address fields when adding/editing contacts and configuring event location. -* For front end profiles, postcode lookup feature is enabled only if 'Street Address' field of type 'Primary' or 'Billing' is added to the profile. Include 'Supplemental Address 1' and 'Supplemental Address 2' fields in the profile for address lines based on the rules in the Royal Mail programmers guide. +* For backend, postcode lookup features is automatically enabled for address fields when adding/editing +contacts and configuring event location. +* For front end profiles, postcode lookup feature is enabled for payment billing address, primary address +and all location types set in *Administer->Postcode lookup*. -### Support ### +Include 'Supplemental Address 1' and 'Supplemental Address 2' fields in the profile for address lines based on the rules in the Royal Mail programmers guide. + +## Changelog + +### 1.9 +* Cleanup the postcode selector that was being added multiple times in some cases. +* Only show a single loading "spinner" when searching for postcodes. + +### 1.8 +* Update jQuery and trigger change on all billing fields that we touch to trigger other functions (eg. billing address is the same). This fixes issues when "My Billing address is the same" is checked. +* Switch to \Civi::settings to get/set settings (removes a deprecated function warning). + +### 1.7 +* Fixed parsing of address. -support (at) vedaconsulting.co.uk diff --git a/civicrmpostcodelookup.php b/civicrmpostcodelookup.php index cb306e9..7ab13c5 100755 --- a/civicrmpostcodelookup.php +++ b/civicrmpostcodelookup.php @@ -152,12 +152,9 @@ function civicrmpostcodelookup_civicrm_buildForm($formName, &$form) { $settingsStr = \Civi::settings()->get('api_details'); $settingsArray = unserialize($settingsStr); $form->assign('civiPostCodeLookupProvider', $settingsArray['provider']); - - //MV#4367, assign location types value from settings to tpl/js - if (!empty($settingsArray['location_type_id'])) { - $form->assign('civiPostCodeLookupLocationType', $settingsArray['location_type_id']); - $form->assign('civiPostCodeLookupLocationTypeJson', json_encode($settingsArray['location_type_id'])); - } + $settingsArray['location_type_id'] = $settingsArray['location_type_id'] ?? []; + $settingsArray['location_type_id'][] = 'Primary'; + $form->assign('civiPostCodeLookupLocationTypeJson', json_encode($settingsArray['location_type_id'])); } } diff --git a/info.xml b/info.xml index bd06ba9..8e75595 100755 --- a/info.xml +++ b/info.xml @@ -1,20 +1,20 @@ <?xml version="1.0"?> <extension key="uk.co.vedaconsulting.module.civicrmpostcodelookup" type="module"> <file>civicrmpostcodelookup</file> - <name>CiviCRM Postcode Lookup</name> - <description>Extension to enable postcode lookup feature in CiviCRM using AFD, Civipostcode, Experian or PostcodeAnywhere.</description> + <name>CiviCRM UK Postcode Lookup</name> + <description>Extension to enable postcode lookup feature in CiviCRM using AFD, Civipostcode, Experian, PostcodeAnywhere or getaddress.io.</description> <license>AGPL-3.0</license> <maintainer> - <author>Parvez Saleh</author> - <email>parvez@vedaconsulting.co.uk</email> + <author>Parvez Saleh (Veda), Matthew Wire (MJW)</author> + <email>parvez@vedaconsulting.co.uk, support@mjw.pt</email> </maintainer> <urls> <url desc="Main Extension Page">https://lab.civicrm.org/extensions/ukpostcodes</url> <url desc="Support">https://lab.civicrm.org/extensions/ukpostcodes/issues</url> <url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url> </urls> - <releaseDate>2020-02-07</releaseDate> - <version>1.8</version> + <releaseDate>2020-02-22</releaseDate> + <version>1.9</version> <develStage>stable</develStage> <compatibility> <ver>5.19</ver> diff --git a/templates/CRM/Civicrmpostcodelookup/Form/Postcodelookup.tpl b/templates/CRM/Civicrmpostcodelookup/Form/Postcodelookup.tpl index 6a027f1..fe72565 100755 --- a/templates/CRM/Civicrmpostcodelookup/Form/Postcodelookup.tpl +++ b/templates/CRM/Civicrmpostcodelookup/Form/Postcodelookup.tpl @@ -1,50 +1,35 @@ {literal} <script type="text/javascript"> CRM.$(function($) { - var locationTypes = {/literal}{if $civiPostCodeLookupLocationTypeJson}{$civiPostCodeLookupLocationTypeJson}{else}''{/if}{literal}; + var locationTypes = {/literal}{$civiPostCodeLookupLocationTypeJson}{literal}; var blockId = ''; var blockNo = ''; + var addressSelector = ''; + var postCodeHtml = ''; - if ($('#editrow-street_address-Primary').length > 0) { - var blockId = 'Primary'; - var blockNo = 'Primary'; - var targetHtml = ''; - var postCodeHtml = '<div class="crm-section addressLookup form-item"><div class="label"><label for="addressLookup">Search for an address</label></div><div class="edit-value content"><div class="postcodelookup-textbox-wrapper"><input placeholder="Start typing a postcode" name="inputPostCode_' + blockId + '" id ="inputPostCode_' + blockId + '" style="width: 25em;"></div><div class="loader-image"><img id="loaderimage_' + blockId + '" src="{/literal}{$config->resourceBase}{literal}i/loading.gif" style="width:15px;height:15px; display: none" /></div></div><div class="clear"></div></div>'; - $('#editrow-street_address-Primary').before(postCodeHtml); - } - else if ($('#editrow-street_address-5').length > 0) { - var blockId = '5'; - var blockNo = '5'; - var targetHtml = ''; - var divHtml = $('#editrow-street_address-5').html(); - var postCodeHtml = '<div class="crm-section addressLookup form-item"><div class="label"><label for="addressLookup">Search for an address</label></div><div class="edit-value content"><div class="postcodelookup-textbox-wrapper"><input placeholder="Start typing a postcode" name="inputPostCode_' + blockId + '" id ="inputPostCode_' + blockId + '" style="width: 25em;"></div><div class="loader-image"><img id="loaderimage_' + blockId + '" src="{/literal}{$config->resourceBase}{literal}i/loading.gif" style="width:15px;height:15px; display: none" /></div></div><div class="clear"></div></div>'; - $('#editrow-street_address-5').before(postCodeHtml); + // Location Types from settings + if (locationTypes) { + $.each(locationTypes, function (id, index) { + addressSelector = '#editrow-street_address-' + id; + if ($(addressSelector).length > 0) { + blockId = id; + blockNo = id; + postCodeHtml = '<div class="crm-section addressLookup form-item"><div class="label"><label for="addressLookup">Search for an address</label></div><div class="edit-value content"><div class="postcodelookup-textbox-wrapper"><input placeholder="Start typing a postcode" name="inputPostCode_' + blockId + '" id ="inputPostCode_' + blockId + '" style="width: 25em;"></div></div><div class="clear"></div></div>'; + if ($('#inputPostCode_' + blockId).length === 0) { + $(addressSelector).before(postCodeHtml); + } + } + }); } // Include lookup in billing section as well if ($('#billing_street_address-5').length > 0) { var billingblockId = '5'; var billingblockNo = '5'; - var billingtargetHtml = ''; - var billingdivHtml = $('#billing_street_address-5').html(); - var billingpostCodeHtml = '<div class="crm-section addressLookup form-item"><div class="label"><label for="addressLookup">Search for an address</label></div><div class="edit-value content"><div class="postcodelookup-textbox-wrapper"><input placeholder="Start typing a postcode" name="inputPostCodeBillingSection_' + billingblockId + '" id ="inputPostCodeBillingSection_' + billingblockId + '" style="width: 25em;"></div><div class="loader-image"><img id="loaderimage_' + billingblockId + '" src="{/literal}{$config->resourceBase}{literal}i/loading.gif" style="width:15px;height:15px; display: none" /></div></div><div class="clear"></div></div>'; + var billingpostCodeHtml = '<div class="crm-section addressLookup form-item"><div class="label"><label for="addressLookup">Search for an address</label></div><div class="edit-value content"><div class="postcodelookup-textbox-wrapper"><input placeholder="Start typing a postcode" name="inputPostCodeBillingSection_' + billingblockId + '" id ="inputPostCodeBillingSection_' + billingblockId + '" style="width: 25em;"></div></div><div class="clear"></div></div>'; $('.billing_street_address-5-section').before(billingpostCodeHtml); - var billingPostcodeElement = '#inputPostCodeBillingSection_'+billingblockNo; } - //Location Types from settings - if (locationTypes) { - $.each(locationTypes, function (id, index) { - if ($('#editrow-street_address-' + id).length > 0) { - blockId = id; - blockNo = id; - var targetHtml = ''; - // var divHtml = $('#editrow-street_address-'+ id).html(); - var postCodeHtml = '<div class="crm-section addressLookup form-item"><div class="label"><label for="addressLookup">Search for an address</label></div><div class="edit-value content"><div class="postcodelookup-textbox-wrapper"><input placeholder="Start typing a postcode" name="inputPostCode_' + blockId + '" id ="inputPostCode_' + blockId + '" style="width: 25em;"></div><div class="loader-image"><img id="loaderimage_' + blockId + '" src="{/literal}{$config->resourceBase}{literal}i/loading.gif" style="width:15px;height:15px; display: none" /></div></div><div class="clear"></div></div>'; - $('#editrow-street_address-'+ id).before(postCodeHtml); - } - }); - } var houseElement = '#inputNumber_'+blockNo; var postcodeElement = '#inputPostCode_'+blockNo; diff --git a/templates/CRM/Contact/Form/Edit/Address/street_address.tpl b/templates/CRM/Contact/Form/Edit/Address/street_address.tpl index 2087880..97aaf4e 100755 --- a/templates/CRM/Contact/Form/Edit/Address/street_address.tpl +++ b/templates/CRM/Contact/Form/Edit/Address/street_address.tpl @@ -28,7 +28,6 @@ <td colspan="2"> <label for="addressLookup">Search for an address</label><br> <input placeholder="Start typing a postcode" name="inputPostCode_{$blockId}" id ="inputPostCode_{$blockId}"> - <img id="loaderimage_{$blockId}" src="{$config->resourceBase}i/loading.gif" style="width:15px;height:15px; display: none" /> </td> </tr> -- GitLab