commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / templates / CRM / Contact / Form / ShareAddress.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.6 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2015 |
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>
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/>
40 {/foreach}
41 {/if}
42 </div>
43 </div>
44 </td>
45 </tr>
46
47
48 {literal}
49 <script type="text/javascript">
50 CRM.$(function($) {
51 var blockNo = {/literal}{$blockId}{literal},
52 $contentArea = $('#shared-address-' + blockNo + ' .shared-address-list'),
53 $masterElement = $('input[name="address[' + blockNo + '][master_id]"]');
54
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);
60 }
61
62 // "Use another contact's address" checkbox
63 $('#address\\[' + blockNo + '\\]\\[use_shared_address\\]').each(showHideSharedAddress).click(showHideSharedAddress);
64
65 // When an address is selected
66 $contentArea.off().on('click', 'input', function() {
67 $masterElement.val($(this).val());
68 });
69
70 // When shared contact is selected/unselected
71 $('input[name="address[' + blockNo +'][master_contact_id]"]').change(function() {
72 var $el = $(this),
73 sharedContactId = $el.val();
74
75 $contentArea.html('');
76 $masterElement.val('');
77
78 if (!sharedContactId || isNaN(sharedContactId)) {
79 return;
80 }
81
82 $.post(CRM.url('civicrm/ajax/inline'), {
83 'contact_id': sharedContactId,
84 'type': 'method',
85 'class_name': 'CRM_Contact_Page_AJAX',
86 'fn_name': 'getAddressDisplay'
87 },
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) {
96 selected = '';
97 } else {
98 $('input[name="address[' + blockNo + '][master_id]"]').val(val.id);
99 }
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/>';
103 });
104
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};
107 }
108
109 $contentArea.html(addressHTML);
110 }
111 },'json');
112 });
113 });
114 </script>
115 {/literal}
116
117