Commit 01252d16 authored by mathavan's avatar mathavan
Browse files

#4367 location type settings and update js for postcodelookup field based on location type

parent 81960cbd
......@@ -68,6 +68,15 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
false
);
//MV#4367 Location Types
$locationTypes = array_flip(CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'));
$this->addCheckBox('location_type_id',
ts('Location Types'),
$locationTypes,
NULL, NULL, NULL, NULL,
array('  ')
);
$this->addButtons(array(
array(
......@@ -169,6 +178,11 @@ class CRM_Civicrmpostcodelookup_Form_Setting extends CRM_Core_Form {
$settingsArray['username'] = $values['username'];
}
//MV#4367 amend Location Types into settings
if (!empty($values['location_type_id'])) {
$settingsArray['location_type_id'] = $values['location_type_id'];
}
$settingsStr = serialize($settingsArray);
CRM_Core_BAO_Setting::setItem($settingsStr,
......
......@@ -153,17 +153,27 @@ function civicrmpostcodelookup_civicrm_navigationMenu( &$params ) {
}
function civicrmpostcodelookup_civicrm_buildForm($formName, &$form) {
if ($formName == 'CRM_Contact_Form_Contact' ||
$formName == 'CRM_Profile_Form_Edit' ||
$formName == 'CRM_Event_Form_Registration_Register' ||
$formName == 'CRM_Contribute_Form_Contribution_Main' ||
$formName == 'CRM_Event_Form_ManageEvent_Location'
) {
$postCodeLookupPages = array(
'CRM_Contact_Form_Contact'
, 'CRM_Contact_Form_Inline_Address'
, 'CRM_Profile_Form_Edit'
, 'CRM_Event_Form_Registration_Register'
, 'CRM_Contribute_Form_Contribution_Main'
, 'CRM_Event_Form_ManageEvent_Location'
, 'CRM_Financial_Form_Payment'
);
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');
$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']));
}
// Get CiviCRM version
$civiVersion = CRM_Civicrmpostcodelookup_Utils::getCiviVersion();
$form->assign('civiVersion', $civiVersion);
......
......@@ -4,6 +4,9 @@
</style>
<script type="text/javascript">
cj(document).ready(function(){
var locationTypes = {/literal}{$civiPostCodeLookupLocationTypeJson}{literal};
var blockId = '';
var blockNo = '';
if (cj('#editrow-street_address-Primary').length > 0 ) {
var blockId = 'Primary';
var blockNo = 'Primary';
......@@ -32,7 +35,19 @@ cj(document).ready(function(){
var billingPostcodeElement = '#inputPostCodeBillingSection_'+billingblockNo;
}
//Location Types from settings
if (locationTypes) {
cj.each(locationTypes, function (id, index) {
if (cj('#editrow-street_address-'+ id).length > 0 ) {
blockId = id;
blockNo = id;
var targetHtml = '';
// var divHtml = cj('#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);
}
});
}
var buttonElement = '#postcodeLookupButton_'+blockNo;
var houseElement = '#inputNumber_'+blockNo;
......
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