Commit d7f587cc authored by mattwire's avatar mattwire
Browse files

Merge branch 'triggerChange' into 'master'

Trigger change and replace deprecated functions

See merge request !1
parents 0223022f ff938a24
......@@ -8,10 +8,9 @@ require_once 'CRM/Core/Form.php';
* @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
*/
class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
function buildQuickForm() {
$settingsStr = CRM_Core_BAO_Setting::getItem('CiviCRM Postcode Lookup', 'api_details');
function buildQuickForm() {
$settingsStr = \Civi::settings()->get('api_details');
$settingsArray = unserialize($settingsStr);
// Postcode loookup Provider
......@@ -200,11 +199,7 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
}
$settingsStr = serialize($settingsArray);
CRM_Core_BAO_Setting::setItem($settingsStr,
'CiviCRM Postcode Lookup',
'api_details'
);
\Civi::settings()->set('api_details', $settingsStr);
$message = "Settings saved.";
CRM_Core_Session::setStatus($message, 'Postcode Lookup', 'success');
......
......@@ -11,7 +11,7 @@ class CRM_Civicrmpostcodelookup_Page_Afd extends CRM_Civicrmpostcodelookup_Page_
#################
#Server settings
#################
$settingsStr = CRM_Core_BAO_Setting::getItem('CiviCRM Postcode Lookup', 'api_details');
$settingsStr = \Civi::settings()->get('api_details');
$settingsArray = unserialize($settingsStr);
$servertarget = $settingsArray['server'];
......
......@@ -11,7 +11,7 @@ class CRM_Civicrmpostcodelookup_Page_Civipostcode extends CRM_Civicrmpostcodeloo
#################
#Server settings
#################
$settingsStr = CRM_Core_BAO_Setting::getItem('CiviCRM Postcode Lookup', 'api_details');
$settingsStr = \Civi::settings()->get('api_details');
$settingsArray = unserialize($settingsStr);
$servertarget = $settingsArray['server'];
......
......@@ -11,7 +11,7 @@ class CRM_PostcodeLookup_Page_Ajax extends CRM_Civicrmpostcodelookup_Page_Postco
public static function getQasCredentials($account_type) {
$credentials = [];
$settingsStr = CRM_Core_BAO_Setting::getItem('CiviCRM Postcode Lookup', 'api_details');
$settingsStr = \Civi::settings()->get('api_details');
$settingsArray = unserialize($settingsStr);
$credentials['username'] = $settingsArray['username'];
......
......@@ -83,7 +83,7 @@ class CRM_Civicrmpostcodelookup_Page_GetAddressIo extends CRM_Civicrmpostcodeloo
#################
#API settings
#################
$settingsStr = CRM_Core_BAO_Setting::getItem('CiviCRM Postcode Lookup', 'api_details');
$settingsStr = \Civi::settings()->get('api_details');
$settingsArray = unserialize($settingsStr);
$servertarget = $settingsArray['server'];
......@@ -266,4 +266,4 @@ class CRM_Civicrmpostcodelookup_Page_GetAddressIo extends CRM_Civicrmpostcodeloo
return $address;
}
}
\ No newline at end of file
}
......@@ -11,7 +11,7 @@ class CRM_Civicrmpostcodelookup_Page_PostcodeAnywhere extends CRM_Civicrmpostcod
#################
#Server settings
#################
$settingsStr = CRM_Core_BAO_Setting::getItem('CiviCRM Postcode Lookup', 'api_details');
$settingsStr = \Civi::settings()->get('api_details');
$settingsArray = unserialize($settingsStr);
$servertarget = $settingsArray['server'];
......
......@@ -39,7 +39,7 @@ function civicrmpostcodelookup_civicrm_xmlMenu(&$files) {
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function civicrmpostcodelookup_civicrm_install() {
CRM_Core_BAO_Setting::setItem('', 'CiviCRM Postcode Lookup', 'api_details');
\Civi::settings()->set('api_details', '');
_civicrmpostcodelookup_civix_civicrm_install();
}
......@@ -149,7 +149,7 @@ function civicrmpostcodelookup_civicrm_buildForm($formName, &$form) {
];
if (in_array($formName, $postCodeLookupPages)) {
// Assign the postcode lookup provider to form, so that we can call the related function in AJAX
$settingsStr = CRM_Core_BAO_Setting::getItem('CiviCRM Postcode Lookup', 'api_details');
$settingsStr = \Civi::settings()->get('api_details');
$settingsArray = unserialize($settingsStr);
$form->assign('civiPostCodeLookupProvider', $settingsArray['provider']);
......
......@@ -13,11 +13,11 @@
<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>2019-06-06</releaseDate>
<version>1.7</version>
<releaseDate>2020-02-07</releaseDate>
<version>1.8</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.13</ver>
<ver>5.19</ver>
</compatibility>
<comments>Developed by Veda NFP Consulting LTD.</comments>
<civix>
......
{literal}
<script type="text/javascript">
cj(document).ready(function(){
CRM.$(function($) {
var locationTypes = {/literal}{if $civiPostCodeLookupLocationTypeJson}{$civiPostCodeLookupLocationTypeJson}{else}''{/if}{literal};
var blockId = '';
var blockNo = '';
if (cj('#editrow-street_address-Primary').length > 0 ) {
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>';
cj('#editrow-street_address-Primary').before(postCodeHtml);
$('#editrow-street_address-Primary').before(postCodeHtml);
}
else if (cj('#editrow-street_address-5').length > 0 ) {
else if ($('#editrow-street_address-5').length > 0) {
var blockId = '5';
var blockNo = '5';
var targetHtml = '';
var divHtml = cj('#editrow-street_address-5').html();
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>';
cj('#editrow-street_address-5').before(postCodeHtml);
$('#editrow-street_address-5').before(postCodeHtml);
}
// Include lookup in billing section as well
if (cj('#billing_street_address-5').length > 0 ) {
if ($('#billing_street_address-5').length > 0) {
var billingblockId = '5';
var billingblockNo = '5';
var billingtargetHtml = '';
var billingdivHtml = cj('#billing_street_address-5').html();
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>';
cj('.billing_street_address-5-section').before(billingpostCodeHtml);
$('.billing_street_address-5-section').before(billingpostCodeHtml);
var billingPostcodeElement = '#inputPostCodeBillingSection_'+billingblockNo;
}
//Location Types from settings
if (locationTypes) {
cj.each(locationTypes, function (id, index) {
if (cj('#editrow-street_address-'+ id).length > 0 ) {
$.each(locationTypes, function (id, index) {
if ($('#editrow-street_address-' + id).length > 0) {
blockId = id;
blockNo = id;
var targetHtml = '';
// var divHtml = cj('#editrow-street_address-'+ id).html();
// 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>';
cj('#editrow-street_address-'+ id).before(postCodeHtml);
$('#editrow-street_address-'+ id).before(postCodeHtml);
}
});
}
var buttonElement = '#postcodeLookupButton_'+blockNo;
var houseElement = '#inputNumber_'+blockNo;
var postcodeElement = '#inputPostCode_'+blockNo;
var addressResultElement = '#addressResult_'+blockNo;
var addressResultsElement = '#addressResults_'+blockNo;
var minCharacters = 4;
var delay = 200;
var postcodeProvider = '{/literal}{$civiPostCodeLookupProvider}{literal}';
if (postcodeProvider !== 'civipostcode') {
cj(postcodeElement).attr("placeholder", "Type full postcode to find addresses");
$(postcodeElement).attr("placeholder", "Type full postcode to find addresses");
minCharacters = 5;
}
cj(function() {
var sourceUrl = CRM.url('civicrm/{/literal}{$civiPostCodeLookupProvider}{literal}/ajax/search', {"json": 1});
var sourceUrl = CRM.url('civicrm/{/literal}{$civiPostCodeLookupProvider}{literal}/ajax/search', {"json": 1});
$(postcodeElement).autocomplete({
source: sourceUrl,
minLength: minCharacters,
data: {postcode: $( postcodeElement ).val(), number: $(houseElement).val(), mode: '0'},
search: function( event, ui ) {
$('#loaderimage_'+blockNo).show();
},
response: function( event, ui ) {
$('#loaderimage_'+blockNo).hide();
},
select: function(event, ui) {
if (ui.item.id !== '') {
findAddressValues(ui.item.id, blockNo, blockPrefix = '');
$('#loaderimage_'+blockNo).show();
}
return false;
},
html: true, // optional (jquery.ui.autocomplete.html.js required)
//optional (if other layers overlap autocomplete list)
open: function(event, ui) {
$(".ui-autocomplete").css("z-index", 1000);
}
});
cj(postcodeElement).autocomplete({
// Postcode lookup in billing section
if ($('#billing_street_address-5').length > 0 ) {
$(billingPostcodeElement).autocomplete({
source: sourceUrl,
minLength: minCharacters,
data: {postcode: cj( postcodeElement ).val(), number: cj(houseElement).val(), mode: '0'},
data: {postcode: $( billingPostcodeElement ).val(), number: $(houseElement).val(), mode: '0'},
search: function( event, ui ) {
cj('#loaderimage_'+blockNo).show();
$('#loaderimage_'+blockNo).show();
},
response: function( event, ui ) {
cj('#loaderimage_'+blockNo).hide();
$('#loaderimage_'+blockNo).hide();
},
select: function(event, ui) {
if (ui.item.id != '') {
findAddressValues(ui.item.id, blockNo, blockPrefix = '');
cj('#loaderimage_'+blockNo).show();
if (ui.item.id !== '') {
findAddressValues(ui.item.id, '5', blockPrefix = 'billing_');
$('#loaderimage_'+blockNo).show();
}
return false;
},
html: true, // optional (jquery.ui.autocomplete.html.js required)
//optional (if other layers overlap autocomplete list)
open: function(event, ui) {
cj(".ui-autocomplete").css("z-index", 1000);
$(".ui-autocomplete").css("z-index", 1000);
}
});
}
// Postcode lookup in billing section
if (cj('#billing_street_address-5').length > 0 ) {
cj(billingPostcodeElement).autocomplete({
source: sourceUrl,
minLength: minCharacters,
data: {postcode: cj( billingPostcodeElement ).val(), number: cj(houseElement).val(), mode: '0'},
search: function( event, ui ) {
cj('#loaderimage_'+blockNo).show();
},
response: function( event, ui ) {
cj('#loaderimage_'+blockNo).hide();
},
select: function(event, ui) {
if (ui.item.id != '') {
findAddressValues(ui.item.id, '5', blockPrefix = 'billing_');
cj('#loaderimage_'+blockNo).show();
}
return false;
},
html: true, // optional (jquery.ui.autocomplete.html.js required)
//optional (if other layers overlap autocomplete list)
open: function(event, ui) {
cj(".ui-autocomplete").css("z-index", 1000);
}
});
}
});
});
function findAddressValues(id , blockNo, blockPrefix) {
$('#loaderimage_'+blockNo).show();
setAddressFields(false, blockNo, blockPrefix);
var sourceUrl = CRM.url('civicrm/{/literal}{$civiPostCodeLookupProvider}{literal}/ajax/get', {"json": 1});
$.ajax({
dataType: 'json',
data: {id: id, mode: '0'},
url: sourceUrl,
success: function (data) {
setAddressFields(data.address, blockNo, blockPrefix);
setAddressFields(true, blockNo, blockPrefix);
},
complete: function (data) {
$('#loaderimage_'+blockNo).hide();
}
});
}
function findAddressValues(id , blockNo, blockPrefix) {
cj('#loaderimage_'+blockNo).show();
setAddressFields(false, blockNo, blockPrefix);
var sourceUrl = CRM.url('civicrm/{/literal}{$civiPostCodeLookupProvider}{literal}/ajax/get', {"json": 1});
cj.ajax({
dataType: 'json',
data: {id: id, mode: '0'},
url: sourceUrl,
success: function (data) {
setAddressFields(data.address, blockNo, blockPrefix);
setAddressFields(true, blockNo, blockPrefix);
},
complete: function (data) {
cj('#loaderimage_'+blockNo).hide();
}
});
}
function setAddressFields(address, blockNo, blockPrefix) {
var postcodeElement = '#' + blockPrefix + 'postal_code-'+ blockNo;
var streetAddressElement = '#' + blockPrefix + 'street_address-'+ blockNo;
var AddstreetAddressElement = '#' + blockPrefix + 'supplemental_address_1-'+ blockNo;
var AddstreetAddressElement1 = '#' + blockPrefix + 'supplemental_address_2-'+ blockNo;
var cityElement = '#' + blockPrefix + 'city-'+ blockNo;
var countyElement = '#address_'+ blockNo +'_state_province_id';
var allFields = {
postcode: postcodeElement,
line1: streetAddressElement,
line2: AddstreetAddressElement,
line3: AddstreetAddressElement1,
city: cityElement
};
if(address == true) {
for(var field in allFields) {
cj(allFields[field]).removeAttr('disabled');
function setAddressFields(address, blockNo, blockPrefix) {
var postcodeElement = '#' + blockPrefix + 'postal_code-'+ blockNo;
var streetAddressElement = '#' + blockPrefix + 'street_address-'+ blockNo;
var AddstreetAddressElement = '#' + blockPrefix + 'supplemental_address_1-'+ blockNo;
var AddstreetAddressElement1 = '#' + blockPrefix + 'supplemental_address_2-'+ blockNo;
var cityElement = '#' + blockPrefix + 'city-'+ blockNo;
var countyElement = '#address_'+ blockNo +'_state_province_id';
var allFields = {
postcode: postcodeElement,
line1: streetAddressElement,
line2: AddstreetAddressElement,
line3: AddstreetAddressElement1,
city: cityElement
};
if(address === true) {
for(var field in allFields) {
$(allFields[field]).removeAttr('disabled');
}
}
}
else if(address == false) {
for(var field in allFields) {
cj(allFields[field]).attr('disabled', 'disabled');
else if(address === false) {
for (var field in allFields) {
$(allFields[field]).attr('disabled', 'disabled');
}
}
}
else {
cj(streetAddressElement).val('');
cj(AddstreetAddressElement).val('');
cj(AddstreetAddressElement1).val('');
cj(cityElement).val('');
cj(postcodeElement).val('');
cj(countyElement).val('');
cj(streetAddressElement).val(address.street_address);
cj(AddstreetAddressElement).val(address.supplemental_address_1);
cj(AddstreetAddressElement1).val(address.supplemental_address_2);
cj(cityElement).val(address.town);
cj(postcodeElement).val(address.postcode);
if(typeof(address.state_province_id) != "undefined" && address.state_province_id !== null) {
cj(countyElement).val(address.state_province_id);
else {
$(streetAddressElement).val('');
$(AddstreetAddressElement).val('');
$(AddstreetAddressElement1).val('');
$(cityElement).val('');
$(postcodeElement).val('');
$(countyElement).val('');
$(streetAddressElement).val(address.street_address);
$(AddstreetAddressElement).val(address.supplemental_address_1);
$(AddstreetAddressElement1).val(address.supplemental_address_2);
$(cityElement).val(address.town);
$(postcodeElement).val(address.postcode);
if (typeof(address.state_province_id) !== 'undefined' && address.state_province_id !== null) {
$(countyElement).val(address.state_province_id);
}
// Trigger change on all the elements we touch so that other functions can react
// eg. a checkbox for "My billing address is the same".
$(streetAddressElement).trigger("change");
$(AddstreetAddressElement).trigger("change");
$(AddstreetAddressElement1).trigger("change");
$(cityElement).trigger("change");
$(postcodeElement).trigger("change");
$(countyElement).trigger("change");
}
cj(countyElement).trigger("change");
}
}
});
</script>
{/literal}
{* HEADER *}
<!-- <div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="top"}
</div> -->
<div class="crm-block crm-form-block crm-export-form-block">
{* FIELD EXAMPLE: OPTION 1 (AUTOMATIC LAYOUT) *}
{foreach from=$elementNames item=elementName}
<div class="crm-section">
<div class="label">{$form.$elementName.label}</div>
......@@ -16,13 +9,6 @@
</div>
{/foreach}
{* FIELD EXAMPLE: OPTION 2 (MANUAL LAYOUT)
<!-- <div>
<span>{$form.favorite_color.label}</span>
<span>{$form.favorite_color.html}</span>
</div> -->
{* FOOTER *}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
......@@ -32,59 +18,54 @@
{literal}
<script>
cj( document ).ready(function() {
cj('#server').parent().append('<br />Without trailing slash. Example: http://pce.afd.co.uk , http://civipostcode.com');
CRM.$(function($) {
$('#server').parent().append('<br />Without trailing slash. Example: http://pce.afd.co.uk , http://civipostcode.com');
hideAllFields();
showFields();
cj('#provider').change(function() {
$('#provider').change(function() {
hideAllFields();
showFields();
});
});
function hideAllFields() {
cj('#server').parent().parent().hide();
cj('#api_key').parent().parent().hide();
cj('#serial_number').parent().parent().hide();
cj('#username').parent().parent().hide();
cj('#password').parent().parent().hide();
}
function showFields() {
var providerVal = cj("#provider").val();
if (providerVal == 'experian') {
cj('#username').parent().parent().show();
cj('#password').parent().parent().show();
}
if (providerVal == 'afd') {
cj('#server').parent().parent().show();
cj('#serial_number').parent().parent().show();
cj('#password').parent().parent().show();
cj('#server').val('http://pce.afd.co.uk');
}
if (providerVal == 'civipostcode') {
cj('#server').parent().parent().show();
cj('#api_key').parent().parent().show();
cj('#server').val('http://civipostcode.com');
}
if (providerVal == 'postcodeanywhere') {
cj('#server').parent().parent().show();
cj('#api_key').parent().parent().show();
cj('#username').parent().parent().show();
cj('#server').val('http://services.postcodeanywhere.co.uk');
function hideAllFields() {
$('#server').parent().parent().hide();
$('#api_key').parent().parent().hide();
$('#serial_number').parent().parent().hide();
$('#username').parent().parent().hide();
$('#password').parent().parent().hide();
}
if (providerVal == 'getaddressio') {
cj('#server').parent().parent().show();
cj('#api_key').parent().parent().show();
cj('#server').val('https://api.getAddress.io');
function showFields() {
var providerVal = $("#provider").val();
if (providerVal === 'experian') {
$('#username').parent().parent().show();
$('#password').parent().parent().show();
}
else if (providerVal === 'afd') {
$('#server').parent().parent().show();
$('#serial_number').parent().parent().show();
$('#password').parent().parent().show();
$('#server').val('http://pce.afd.co.uk');
}
else if (providerVal === 'civipostcode') {
$('#server').parent().parent().show();
$('#api_key').parent().parent().show();
$('#server').val('http://civipostcode.com');
}
else if (providerVal === 'postcodeanywhere') {
$('#server').parent().parent().show();
$('#api_key').parent().parent().show();
$('#username').parent().parent().show();
$('#server').val('http://services.postcodeanywhere.co.uk');
}
else if (providerVal === 'getaddressio') {
$('#server').parent().parent().show();
$('#api_key').parent().parent().show();
$('#server').val('https://api.getAddress.io');
}
}
}
});
</script>
{/literal}
......
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