2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2014 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
26 {* template for handling share address functionality*}
29 {$form.address.$blockId.use_shared_address.html}{$form.address.$blockId.use_shared_address.label} {help id="id-sharedAddress" file="CRM/Contact/Form/Contact.hlp"}
30 <div id="shared-address-{$blockId}" class="form-layout-compressed">
31 {$form.address.$blockId.master_contact_id.label}
32 {$form.address.$blockId.master_contact_id.html}
33 <div class="shared-address-list">
34 {if !empty($sharedAddresses.$blockId.shared_address_display)}
35 {foreach item='sa' from=$sharedAddresses.$blockId.shared_address_display.options}
36 {assign var="sa_name" value="selected_shared_address-`$blockId`"}
37 {assign var="sa_id" value="`$sa_name`-`$sa.id`"}
38 <input type="radio" name="{$sa_name}" id="{$sa_id}" value="{$sa.id}" {if $sa.id eq $sharedAddresses.$blockId.shared_address_display.master_id}checked="checked"{/if}>
39 <label for="{$sa_id}">{$sa.display_text}</label>{if $sa.location_type}({$sa.location_type}){/if}<br/>
49 <script type="text/javascript">
51 var blockNo = {/literal}{$blockId}{literal},
52 $contentArea = $('#shared-address-' + blockNo + ' .shared-address-list'),
53 $masterElement = $('input[name="address[' + blockNo + '][master_id]"]');
55 function showHideSharedAddress() {
56 // based on checkbox, show or hide
57 var share = $(this).prop('checked');
58 $('#shared-address-' + blockNo).toggle(!!share);
59 $('table#address_table_' + blockNo +', .crm-address-custom-set-block-' + blockNo).toggle(!share);
62 // "Use another contact's address" checkbox
63 $('#address\\[' + blockNo + '\\]\\[use_shared_address\\]').each(showHideSharedAddress).click(showHideSharedAddress);
65 // When an address is selected
66 $contentArea.off().on('click', 'input', function() {
67 $masterElement.val($(this).val());
70 // When shared contact is selected/unselected
71 $('input[name="address[' + blockNo +'][master_contact_id]"]').change(function() {
73 sharedContactId = $el.val();
75 $contentArea.html('');
76 $masterElement.val('');
78 if (!sharedContactId || isNaN(sharedContactId)) {
82 $.post(CRM.url('civicrm/ajax/inline'), {
83 'contact_id': sharedContactId,
85 'class_name': 'CRM_Contact_Page_AJAX',
86 'fn_name': 'getAddressDisplay'
89 // Avoid race conditions - check that value hasn't been changed by the user while we were waiting for response
90 if (response && $el.val() === sharedContactId) {
91 var selected = ' checked="checked"',
94 $.each(response, function(i, val) {
98 $('input[name="address[' + blockNo + '][master_id]"]').val(val.id);
100 var name = 'selected_shared_address-'+ blockNo,
101 id = name + '-' + val.id;
102 addressHTML += '<input type="radio" name="' + name + '" id="' + id + '" value="' + val.id + '"' + selected +'><label for="' + id + '">' + val.display_text + '</label>('+val.location_type+')<br/>';
106 addressHTML = {/literal}"{ts escape='js'}Selected contact does not have an address. Please edit that contact to add an address, or select a different contact.{/ts}"{literal};
109 $contentArea.html(addressHTML);