Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
2c4c49ca | 3 | | CiviCRM version 4.7 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
8c9251b3 | 5 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
6 | +--------------------------------------------------------------------+ |
7 | | This file is a part of CiviCRM. | | |
8 | | | | |
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. | | |
12 | | | | |
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. | | |
17 | | | | |
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 | +--------------------------------------------------------------------+ | |
25 | *} | |
26 | {* template for handling share address functionality*} | |
27 | <tr> | |
28 | <td> | |
88820b18 CW |
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"> | |
1a90e0dd CW |
31 | {$form.address.$blockId.master_contact_id.label} |
32 | {$form.address.$blockId.master_contact_id.html} | |
88820b18 CW |
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}> | |
ac44bb1c | 39 | <label for="{$sa_id}">{$sa.display_text}</label>{if $sa.location_type}({$sa.location_type}){/if}<br/> |
88820b18 CW |
40 | {/foreach} |
41 | {/if} | |
42 | </div> | |
1a90e0dd | 43 | </div> |
6a488035 TO |
44 | </td> |
45 | </tr> | |
46 | ||
47 | ||
48 | {literal} | |
49 | <script type="text/javascript"> | |
ae8f569f | 50 | CRM.$(function($) { |
88820b18 CW |
51 | var blockNo = {/literal}{$blockId}{literal}, |
52 | $contentArea = $('#shared-address-' + blockNo + ' .shared-address-list'), | |
53 | $masterElement = $('input[name="address[' + blockNo + '][master_id]"]'); | |
ae8f569f | 54 | |
30b9fdd1 | 55 | function showHideSharedAddress() { |
ae8f569f | 56 | // based on checkbox, show or hide |
30b9fdd1 | 57 | var share = $(this).prop('checked'); |
88820b18 CW |
58 | $('#shared-address-' + blockNo).toggle(!!share); |
59 | $('table#address_table_' + blockNo +', .crm-address-custom-set-block-' + blockNo).toggle(!share); | |
6a488035 | 60 | } |
6a488035 | 61 | |
30b9fdd1 CW |
62 | // "Use another contact's address" checkbox |
63 | $('#address\\[' + blockNo + '\\]\\[use_shared_address\\]').each(showHideSharedAddress).click(showHideSharedAddress); | |
6a488035 | 64 | |
88820b18 CW |
65 | // When an address is selected |
66 | $contentArea.off().on('click', 'input', function() { | |
67 | $masterElement.val($(this).val()); | |
68 | }); | |
69 | ||
30b9fdd1 CW |
70 | // When shared contact is selected/unselected |
71 | $('input[name="address[' + blockNo +'][master_contact_id]"]').change(function() { | |
72 | var $el = $(this), | |
88820b18 CW |
73 | sharedContactId = $el.val(); |
74 | ||
75 | $contentArea.html(''); | |
76 | $masterElement.val(''); | |
6a488035 | 77 | |
30b9fdd1 | 78 | if (!sharedContactId || isNaN(sharedContactId)) { |
6a488035 TO |
79 | return; |
80 | } | |
81 | ||
30b9fdd1 | 82 | $.post(CRM.url('civicrm/ajax/inline'), { |
ae8f569f CW |
83 | 'contact_id': sharedContactId, |
84 | 'type': 'method', | |
ae8f569f CW |
85 | 'class_name': 'CRM_Contact_Page_AJAX', |
86 | 'fn_name': 'getAddressDisplay' | |
6a488035 | 87 | }, |
30b9fdd1 CW |
88 | function(response) { |
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"', | |
92 | addressHTML = ''; | |
93 | ||
94 | $.each(response, function(i, val) { | |
95 | if (addressHTML) { | |
6a488035 TO |
96 | selected = ''; |
97 | } else { | |
30b9fdd1 | 98 | $('input[name="address[' + blockNo + '][master_id]"]').val(val.id); |
6a488035 | 99 | } |
30b9fdd1 CW |
100 | var name = 'selected_shared_address-'+ blockNo, |
101 | id = name + '-' + val.id; | |
ac44bb1c | 102 | addressHTML += '<input type="radio" name="' + name + '" id="' + id + '" value="' + val.id + '"' + selected +'><label for="' + id + '">' + val.display_text + '</label>('+val.location_type+')<br/>'; |
6a488035 TO |
103 | }); |
104 | ||
30b9fdd1 CW |
105 | if (!addressHTML) { |
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}; | |
6a488035 | 107 | } |
30b9fdd1 | 108 | |
88820b18 | 109 | $contentArea.html(addressHTML); |
6a488035 TO |
110 | } |
111 | },'json'); | |
112 | }); | |
ae8f569f | 113 | }); |
6a488035 TO |
114 | </script> |
115 | {/literal} | |
116 | ||
117 |