Commit b26cdcb0 authored by mattwire's avatar mattwire
Browse files

Merge branch 'cleanuppostcodeselector' into 'master'

Cleanup the postcode selector that was being added multiple times in some cases

See merge request !2
parents d7f587cc a5a33820
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).
-------------------------------------------------------------------------------
......
# 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
......@@ -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']));
}
}
......
<?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>
......
{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;
......
......@@ -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}">
&nbsp;&nbsp;<img id="loaderimage_{$blockId}" src="{$config->resourceBase}i/loading.gif" style="width:15px;height:15px; display: none" />
</td>
</tr>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment