Add view-only option on permissioned relationships:
[civicrm-core.git] / templates / CRM / Contact / Form / Relationship.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2018 |
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 {* this template is used for adding/editing/viewing relationships *}
27
28 {if $action eq 4 } {* action = view *}
29 <div class="crm-block crm-content-block crm-relationship-view-block">
30 <table class="crm-info-panel">
31 {foreach from=$viewRelationship item="row"}
32 <tr>
33 <td class="label">{$row.relation}</td>
34 <td><a class="no-popup" href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.cid`"}">{$row.name}</a></td>
35 </tr>
36 {if $isCurrentEmployer}
37 <tr><td class="label">{ts}Current Employee?{/ts}</td><td>{ts}Yes{/ts}</td></tr>
38 {/if}
39 {if $row.start_date}
40 <tr><td class="label">{ts}Start Date{/ts}</td><td>{$row.start_date|crmDate}</td></tr>
41 {/if}
42 {if $row.end_date}
43 <tr><td class="label">{ts}End Date{/ts}</td><td>{$row.end_date|crmDate}</td></tr>
44 {/if}
45 {if $row.description}
46 <tr><td class="label">{ts}Description{/ts}</td><td>{$row.description}</td></tr>
47 {/if}
48 {foreach from=$viewNote item="rec"}
49 {if $rec }
50 <tr><td class="label">{ts}Note{/ts}</td><td>{$rec}</td></tr>
51 {/if}
52 {/foreach}
53 <tr>
54 <td class="label"><label>{ts}Permissions{/ts}</label></td>
55 <td>
56 {if $row.is_permission_a_b or $row.is_permission_b_a}
57 {if $row.is_permission_a_b}
58 <div>
59 {if $row.rtype EQ 'a_b' AND $is_contact_id_a}
60 {if $row.is_permission_a_b == 1}
61 {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view and update information about %2.{/ts}
62 {else}
63 {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view information about %2.{/ts}
64 {/if}
65 {else}
66 {if $row.is_permission_a_b == 1}
67 {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view and update information about %2.{/ts}
68 {else}
69 {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view information about %2.{/ts}
70 {/if}
71 {/if}
72 </div>
73 {/if}
74 {if $row.is_permission_b_a}
75 <div>
76 {if $row.rtype EQ 'a_b' AND $is_contact_id_a}
77 {if $row.is_permission_b_a == 1}
78 {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view and update information about %2.{/ts}
79 {else}
80 {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view information about %2.{/ts}
81 {/if}
82 {else}
83 {if $row.is_permission_b_a == 1}
84 {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view and update information about %2.{/ts}
85 {else}
86 {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view and update information about %2.{/ts}
87 {/if}
88 {/if}
89 </div>
90 {/if}
91 {else}
92 {ts}None{/ts}
93 {/if}
94 </td>
95 </tr>
96 <tr><td class="label">{ts}Status{/ts}</td><td>{if $row.is_active}{ts}Enabled{/ts}{else}{ts}Disabled{/ts}{/if}</td></tr>
97 {/foreach}
98 </table>
99 {include file="CRM/Custom/Page/CustomDataView.tpl"}
100 </div>
101 {/if}
102
103 {if $action eq 2 or $action eq 1} {* add and update actions *}
104 <div class="crm-block crm-form-block crm-relationship-form-block">
105 <table class="form-layout-compressed">
106 <tr class="crm-relationship-form-block-relationship_type_id">
107 <td class="label">{$form.relationship_type_id.label}</td>
108 <td>{$form.relationship_type_id.html}</td>
109 </tr>
110 <tr class="crm-relationship-form-block-related_contact_id">
111 <td class="label">{$form.related_contact_id.label}</td>
112 <td>{$form.related_contact_id.html}</td>
113 </tr>
114 <tr class="crm-relationship-form-block-is_current_employer" style="display:none;">
115 <td class="label">{$form.is_current_employer.label}</td>
116 <td>{$form.is_current_employer.html}</td>
117 </tr>
118 <tr class="crm-relationship-form-block-start_date">
119 <td class="label">{$form.start_date.label}</td>
120 <td>{include file="CRM/common/jcalendar.tpl" elementName=start_date}<span>{$form.end_date.label} {include file="CRM/common/jcalendar.tpl" elementName=end_date}</span><br />
121 <span class="description">{ts}If this relationship has start and/or end dates, specify them here.{/ts}</span></td>
122 </tr>
123 <tr class="crm-relationship-form-block-description">
124 <td class="label">{$form.description.label}</td>
125 <td>{$form.description.html}</td>
126 </tr>
127 <tr class="crm-relationship-form-block-note">
128 <td class="label">{$form.note.label}</td>
129 <td>{$form.note.html}</td>
130 </tr>
131 <tr class="crm-relationship-form-block-is_permission_a_b">
132 {capture assign="contact_b"}{if $action eq 1}{ts}selected contact(s){/ts}{else}{$display_name_b}{/if}{/capture}
133 <td class="label"><label>{ts}Permissions{/ts}</label></td>
134 <td>
135 {ts 1=$display_name_a 2=$contact_b}Permission for <strong>%1</strong> to access information about %2.{/ts}<br />
136 {$form.is_permission_a_b.html}
137 </td>
138 </tr>
139 <tr class="crm-relationship-form-block-is_permission_b_a">
140 <td class="label"></td>
141 <td>
142 {ts 1=$contact_b|ucfirst 2=$display_name_a}Permission for <strong>%1</strong> to access information about %2.{/ts}<br />
143 {$form.is_permission_b_a.html}
144 </td>
145 </tr>
146 <tr class="crm-relationship-form-block-is_active">
147 <td class="label">{$form.is_active.label}</td>
148 <td>{$form.is_active.html}</td>
149 </tr>
150 </table>
151 <div id="customData"></div>
152 <div class="spacer"></div>
153 </div>
154 {/if}
155 {if ($action EQ 1) OR ($action EQ 2) }
156 {*include custom data js file *}
157 {include file="CRM/common/customData.tpl"}
158 <script type="text/javascript">
159 {literal}
160 CRM.$(function($) {
161 var
162 $form = $("form.{/literal}{$form.formClass}{literal}"),
163 $relationshipTypeSelect = $('[name=relationship_type_id]', $form),
164 relationshipData = {},
165 contactTypes = {/literal}{$contactTypes|@json_encode}{literal};
166
167 (function init () {
168 // Refresh options if relationship types were edited
169 $('body').on('crmOptionsEdited', 'a.crm-option-edit-link', refreshRelationshipData);
170 // Initial load and trigger change on select
171 refreshRelationshipData().done(function() {
172 $relationshipTypeSelect.change();
173 });
174 $relationshipTypeSelect.change(function() {
175 var $select = $(this);
176
177 // ensure we have relationship data before changing anything
178 getRelationshipData().then(function() {
179 updateSelect($select);
180 })
181 });
182 })();
183
184 /**
185 * Fetch contact types and reset relationship data
186 */
187 function refreshRelationshipData() {
188 // reset
189 relationshipData = {};
190
191 return getRelationshipData();
192 }
193
194 /**
195 * Fetches the relationship data using latest relationship types
196 */
197 function getRelationshipData() {
198 var defer = $.Deferred();
199
200 if (!$.isEmptyObject(relationshipData)) {
201 defer.resolve(relationshipData);
202 }
203
204 CRM.api3("RelationshipType", "get", {"options": {"limit":0}})
205 .done(function (data) {
206 $.each(data.values, function (key, relType) {
207 // Loop over the suffixes for a relationship type
208 $.each(["a", "b"], function (index, suffix) {
209 var subtype = relType["contact_subtype_" + suffix];
210 var type = subtype || relType["contact_type_" + suffix];
211 var label = getContactTypeLabel(type) || "Contact";
212 label = label.toLowerCase();
213 relType["placeholder_" + suffix] = "- select " + label + " -";
214 });
215
216 relationshipData[relType["id"]] = relType;
217 });
218
219 defer.resolve(relationshipData);
220 });
221
222 return defer.promise();
223 }
224
225 /**
226 * Gets a contact type label based on a provided name
227 * @param {String} name - the name of the contact type
228 */
229 function getContactTypeLabel(name) {
230 var label = "";
231
232 $.each(contactTypes, function(index, contactType) {
233 if (contactType.name === name) {
234 label = contactType.label;
235 return false;
236 }
237 });
238
239 return label;
240 }
241
242 function updateSelect($select) {
243 var
244 val = $select.val(),
245 $contactField = $('#related_contact_id[type=text]', $form);
246 if (!val && $contactField.length) {
247 $contactField
248 .prop('disabled', true)
249 .attr('placeholder', {/literal}'{ts escape='js'}- first select relationship type -{/ts}'{literal})
250 .change();
251 }
252 else if (val) {
253 var
254 pieces = val.split('_'),
255 rType = pieces[0],
256 source = pieces[1], // a or b
257 target = pieces[2], // b or a
258 contact_type = relationshipData[rType]['contact_type_' + target],
259 contact_sub_type = relationshipData[rType]['contact_sub_type_' + target];
260 // ContactField only exists for ADD action, not update
261 if ($contactField.length) {
262 var api = {params: {}};
263 if (contact_type) {
264 api.params.contact_type = contact_type;
265 }
266 if (contact_sub_type) {
267 api.params.contact_sub_type = contact_sub_type;
268 }
269 $contactField
270 .val('')
271 .prop('disabled', false)
272 .data('api-params', api)
273 .data('user-filter', {})
274 .attr('placeholder', relationshipData[rType]['placeholder_' + target])
275 .change();
276 }
277
278 // Show/hide employer field
279 $('.crm-relationship-form-block-is_current_employer', $form).toggle(rType === {/literal}'{$employmentRelationship}'{literal});
280
281 // Swap the permission checkboxes to match selected relationship direction
282 $('#is_permission_a_b', $form).attr('name', 'is_permission_' + source + '_' + target);
283 $('#is_permission_b_a', $form).attr('name', 'is_permission_' + target + '_' + source);
284
285 CRM.buildCustomData('Relationship', rType);
286 }
287 }
288 });
289 {/literal}
290 </script>
291 {/if}
292
293 {if $action eq 8}
294 <div class="status">
295 {ts}Are you sure you want to delete this Relationship?{/ts}
296 </div>
297 {/if}
298 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>