From: Coleman Watts Date: Sun, 16 Feb 2014 00:53:23 +0000 (-0800) Subject: CRM-13929 Refactor shared address form X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1a90e0dd836e05e943c2bd38e4bfb26ea2a0c25f;p=civicrm-core.git CRM-13929 Refactor shared address form --- diff --git a/CRM/Contact/Form/Edit/Address.php b/CRM/Contact/Form/Edit/Address.php index 0b45786e94..ee0a52eb22 100644 --- a/CRM/Contact/Form/Edit/Address.php +++ b/CRM/Contact/Form/Edit/Address.php @@ -288,14 +288,9 @@ class CRM_Contact_Form_Edit_Address { // shared address $form->addElement('checkbox', "address[$blockId][use_shared_address]", NULL, ts('Use another contact\'s address')); - // get the reserved for address - $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'shared_address', 'id', 'name'); - - if (!$profileId) { - CRM_Core_Error::fatal(ts('Your install is missing required "Shared Address" profile.')); - } - - CRM_Contact_Form_NewContact::buildQuickForm($form, $blockId, array($profileId)); + // Override the default profile links to add address form + $profileLinks = CRM_Core_BAO_UFGroup::getCreateLinks(array('new_individual', 'new_organization', 'new_household'), 'shared_address'); + $form->addEntityRef("address[$blockId][master_contact_id]", ts('Share With'), array('create' => $profileLinks)); } } diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 635979e3e6..b2077302a3 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -3257,7 +3257,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) */ static function getCreateLinks($profiles, $appendProfiles = array()) { $profiles = (array) $profiles; - $toGet = array_merge($profiles, $appendProfiles); + $toGet = array_merge($profiles, (array) $appendProfiles); $retrieved = civicrm_api3('uf_group', 'get', array( 'name' => array('IN' => $toGet), 'is_active' => 1, diff --git a/templates/CRM/Contact/Form/ShareAddress.tpl b/templates/CRM/Contact/Form/ShareAddress.tpl index 8bc63b20eb..6566a3f6aa 100644 --- a/templates/CRM/Contact/Form/ShareAddress.tpl +++ b/templates/CRM/Contact/Form/ShareAddress.tpl @@ -41,9 +41,10 @@ {/if} - - {include file="CRM/Contact/Form/NewContact.tpl" blockNo="$blockId"} -
+
+ {$form.address.$blockId.master_contact_id.label} + {$form.address.$blockId.master_contact_id.html} +
@@ -83,10 +84,7 @@ cj( function( ) { }); // start of code to add onchange event for hidden element - var contactHiddenElement = 'input[name="contact_select_id[' + blockNo +']"]'; - - // store initial value - var _default = cj( contactHiddenElement ).val(); + var contactHiddenElement = 'input[name="address[' + blockNo +'][master_contact_id]"]'; // observe changes cj( contactHiddenElement ).change(function( ) { @@ -98,11 +96,10 @@ cj( function( ) { var addressHTML = ''; var postUrl = {/literal}"{crmURL p='civicrm/ajax/inline' h=0}"{literal}; - $('div.crm-address_' + blockNo).block(); - cj.post( postUrl, { 'contact_id': sharedContactId, 'type': 'method', + 'async': false, 'class_name': 'CRM_Contact_Page_AJAX', 'fn_name': 'getAddressDisplay' }, @@ -137,25 +134,9 @@ cj( function( ) { cj( '#shared-address-' + blockNo + ' .shared-address-list' ).remove( ); cj( '#shared-address-' + blockNo ).append( '' + helpText + ''); } - - cj('div.crm-address_' + blockNo).unblock(); } },'json'); }); - - - // continuous check for changed value - setInterval(function( ) { - if ( cj( contactHiddenElement ).val( ) != _default ) { - // trigger native - cj( contactHiddenElement ).change( ); - - // update stored value - _default = cj( contactHiddenElement ).val( ); - } - - }, 500); - // end of code to add onchange event for hidden element }); {/literal}