CRM-14288 - Refactor and simplify relationship form
[civicrm-core.git] / templates / CRM / Contact / Form / Relationship.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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 {if $cdType }
28 {include file="CRM/Custom/Form/CustomData.tpl"}
29 {else}
30 {if $action eq 4 } {* action = view *}
31 <div class="crm-block crm-content-block crm-relationship-view-block">
32 <table class="crm-info-panel">
33 {foreach from=$viewRelationship item="row"}
34 <tr>
35 <td class="label">{$row.relation}</td>
36 <td><a class="no-popup" href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.cid`"}">{$row.name}</a></td>
37 </tr>
38 {if $isCurrentEmployer}
39 <tr><td class="label">{ts}Current Employee?{/ts}</td><td>{ts}Yes{/ts}</td></tr>
40 {/if}
41 {if $row.start_date}
42 <tr><td class="label">{ts}Start Date{/ts}</td><td>{$row.start_date|crmDate}</td></tr>
43 {/if}
44 {if $row.end_date}
45 <tr><td class="label">{ts}End Date{/ts}</td><td>{$row.end_date|crmDate}</td></tr>
46 {/if}
47 {if $row.description}
48 <tr><td class="label">{ts}Description{/ts}</td><td>{$row.description}</td></tr>
49 {/if}
50 {foreach from=$viewNote item="rec"}
51 {if $rec }
52 <tr><td class="label">{ts}Note{/ts}</td><td>{$rec}</td></tr>
53 {/if}
54 {/foreach}
55 <tr>
56 <td class="label"><label>{ts}Permissions{/ts}</label></td>
57 <td>
58 {if $row.is_permission_a_b or $row.is_permission_b_a}
59 {if $row.is_permission_a_b}
60 <div>
61 {if $row.rtype EQ 'a_b' AND $is_contact_id_a}
62 {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view and update information about %2.{/ts}
63 {else}
64 {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view and update information about %2.{/ts}
65 {/if}
66 </div>
67 {/if}
68 {if $row.is_permission_b_a}
69 <div>
70 {if $row.rtype EQ 'a_b' AND $is_contact_id_a}
71 {ts 1=$row.display_name 2=$displayName}<strong>%1</strong> can view and update information about %2.{/ts}
72 {else}
73 {ts 1=$displayName 2=$row.display_name}<strong>%1</strong> can view and update information about %2.{/ts}
74 {/if}
75 </div>
76 {/if}
77 {else}
78 {ts}None{/ts}
79 {/if}
80 </td>
81 </tr>
82 <tr><td class="label">{ts}Status{/ts}</td><td>{if $row.is_active}{ts}Enabled{/ts}{else}{ts}Disabled{/ts}{/if}</td></tr>
83 {/foreach}
84 </table>
85 {include file="CRM/Custom/Page/CustomDataView.tpl"}
86 </div>
87 {/if}
88
89 {if $action eq 2 or $action eq 1} {* add and update actions *}
90 <div class="crm-block crm-form-block crm-relationship-form-block">
91 <table class="form-layout-compressed">
92 <tr class="crm-relationship-form-block-relationship_type_id">
93 <td class="label">{$form.relationship_type_id.label}</td>
94 <td>{$form.relationship_type_id.html}</td>
95 </tr>
96 <tr class="crm-relationship-form-block-related_contact_id">
97 <td class="label">{$form.related_contact_id.label}</td>
98 {* remove crm-select2 class - hack to prevent widget from being initialized so we can mess with it first *}
99 <td>{$form.related_contact_id.html|crmReplace:class:'crm-form-entityref'}</td>
100 </tr>
101 <tr class="crm-relationship-form-block-is_current_employer" style="display:none;">
102 <td class="label">{$form.is_current_employer.label}</td>
103 <td>{$form.is_current_employer.html}</td>
104 </tr>
105 <tr class="crm-relationship-form-block-start_date">
106 <td class="label">{$form.start_date.label}</td>
107 <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 />
108 <span class="description">{ts}If this relationship has start and/or end dates, specify them here.{/ts}</span></td>
109 </tr>
110 <tr class="crm-relationship-form-block-description">
111 <td class="label">{$form.description.label}</td>
112 <td>{$form.description.html}</td>
113 </tr>
114 <tr class="crm-relationship-form-block-note">
115 <td class="label">{$form.note.label}</td>
116 <td>{$form.note.html}</td>
117 </tr>
118 <tr class="crm-relationship-form-block-is_permission_a_b">
119 {capture assign="contact_b"}{if $action eq 1}{ts}selected contact(s){/ts}{else}{$display_name_b}{/if}{/capture}
120 <td class="label"><label>{ts}Permissions{/ts}</label></td>
121 <td>
122 {$form.is_permission_a_b.html}
123 {ts 1=$display_name_a 2=$contact_b}<strong>%1</strong> can view and update information about %2.{/ts}
124 </td>
125 </tr>
126 <tr class="crm-relationship-form-block-is_permission_b_a">
127 <td class="label"></td>
128 <td>
129 {$form.is_permission_b_a.html}
130 {ts 1=$contact_b|ucfirst 2=$display_name_a}<strong>%1</strong> can view and update information about %2.{/ts}
131 </td>
132 </tr>
133 <tr class="crm-relationship-form-block-is_active">
134 <td class="label">{$form.is_active.label}</td>
135 <td>{$form.is_active.html}</td>
136 </tr>
137 </table>
138 <div id="customData"></div>
139 <div class="spacer"></div>
140 </div>
141 {/if}
142 {if ($action EQ 1) OR ($action EQ 2) }
143 {*include custom data js file - setting includeWysiwygEditor=TRUE because it's already been loaded*}
144 {include file="CRM/common/customData.tpl" includeWysiwygEditor=TRUE}
145 <script type="text/javascript">
146 {literal}
147 cj(function($) {
148 var
149 $form = $("form#{/literal}{$form.formName}{literal}"),
150 relationshipData = {/literal}{$relationshipData|@json_encode}{literal};
151 $('[name=relationship_type_id]', $form).change(function() {
152 var
153 val = $(this).val(),
154 $contactField = $('[name=related_contact_id][type=text].crm-form-entityref', $form);
155 if (!val && $contactField.length) {
156 $contactField
157 .prop('disabled', true)
158 .attr('placeholder', {/literal}'{ts escape='js'}- first select relationship type -{/ts}'{literal});
159 // Re-render select2 element
160 CRM.utils.buildSelect2Element.call($contactField);
161 }
162 else if (val) {
163 var
164 pieces = val.split('_'),
165 rType = pieces[0],
166 source = pieces[1], // a or b
167 target = pieces[2], // b or a
168 contact_type = relationshipData[rType]['contact_type_' + target],
169 contact_sub_type = relationshipData[rType]['contact_sub_type_' + target];
170 // ContactField only exists for ADD action, not update
171 if ($contactField.length) {
172 var
173 profiles = $.parseJSON($contactField.attr('data-create-links')),
174 placeholder = {/literal}'{ts escape='js' 1=%1}- select %1 -{/ts}'{literal},
175 params = {params: {}};
176 if (contact_type) {
177 profiles = _.where(profiles, {name: 'new_' + contact_type.toLowerCase()});
178 params.params.contact_type = contact_type;
179 }
180 if (contact_sub_type) {
181 params.params.contact_sub_type = contact_sub_type;
182 // Todo: pass sub-type to new contact profile otherwise relationship create will fail. Disabling it completely for now.
183 profiles = [];
184 }
185 $contactField
186 .val('')
187 .prop('disabled', false)
188 .data('create-links', profiles)
189 .data('api-params', params)
190 .attr('placeholder', relationshipData[rType]['placeholder_' + target]);
191
192 // Re-render select2 element
193 CRM.utils.buildSelect2Element.call($contactField);
194 }
195
196 // Show/hide employer field
197 $('.crm-relationship-form-block-is_current_employer', $form).toggle(rType === {/literal}'{$employmentRelationship}'{literal});
198
199 // Swap the permission checkboxes to match selected relationship direction
200 $('#is_permission_a_b', $form).attr('name', 'is_permission_' + source + '_' + target);
201 $('#is_permission_b_a', $form).attr('name', 'is_permission_' + target + '_' + source);
202
203 CRM.buildCustomData('Relationship', rType);
204 }
205 }).change();
206 });
207 {/literal}
208 </script>
209 {/if}
210
211 {if $action eq 8}
212 <div class="status">
213 {ts}Are you sure you want to delete this Relationship?{/ts}
214 </div>
215 {/if}
216 <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
217 {/if} {* close of custom data else*}
218