// 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));
}
}
*/
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,
</span>
{/if}
- <table id="shared-address-{$blockId}" class="form-layout-compressed hiddenElement">
- {include file="CRM/Contact/Form/NewContact.tpl" blockNo="$blockId"}
- </table>
+ <div id="shared-address-{$blockId}" class="form-layout-compressed hiddenElement">
+ {$form.address.$blockId.master_contact_id.label}
+ {$form.address.$blockId.master_contact_id.html}
+ </div>
</td>
</tr>
});
// 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( ) {
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'
},
cj( '#shared-address-' + blockNo + ' .shared-address-list' ).remove( );
cj( '#shared-address-' + blockNo ).append( '<tr class="shared-address-list"><td></td><td>' + helpText + '</td></tr>');
}
-
- 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
});
</script>
{/literal}