forked from civicrm/civicrm-core
/
Contact.tpl
357 lines (337 loc) · 14.4 KB
/
Contact.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
{*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2018 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{* This form is for Contact Add/Edit interface *}
{if $addBlock}
{include file="CRM/Contact/Form/Edit/$blockName.tpl"}
{else}
{if $contactId}
{include file="CRM/Contact/Form/Edit/Lock.tpl"}
{/if}
<div class="crm-form-block crm-search-form-block">
{if call_user_func(array('CRM_Core_Permission','check'), 'administer CiviCRM') }
<a href='{crmURL p="civicrm/admin/setting/preferences/display" q="reset=1"}' title="{ts}Click here to configure the panes.{/ts}"><i class="crm-i fa-wrench"></i></a>
{/if}
<span style="float:right;"><a href="#expand" id="expand">{ts}Expand all tabs{/ts}</a></span>
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="top"}
</div>
<div class="crm-accordion-wrapper crm-contactDetails-accordion">
<div class="crm-accordion-header">
{ts}Contact Details{/ts}
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body" id="contactDetails">
<div id="contactDetails">
<div class="crm-section contact_basic_information-section">
{include file="CRM/Contact/Form/Edit/$contactType.tpl"}
</div>
<table class="crm-section contact_information-section form-layout-compressed">
{foreach from=$blocks item="label" key="block"}
{include file="CRM/Contact/Form/Edit/$block.tpl"}
{/foreach}
</table>
<table class="crm-section contact_source-section form-layout-compressed">
<tr class="last-row">
<td>{$form.contact_source.label} {help id="id-source"}<br />
{$form.contact_source.html|crmAddClass:twenty}
</td>
<td>{$form.external_identifier.label} {help id="id-external-id"}<br />
{$form.external_identifier.html}
</td>
{if $contactId}
<td>
<label for="internal_identifier_display">{ts}Contact ID{/ts} {help id="id-internal-id"}</label><br />
<input id="internal_identifier_display" type="text" class="crm-form-text six" size="6" readonly="readonly" value="{$contactId}">
</td>
{/if}
</tr>
</table>
<table class="image_URL-section form-layout-compressed">
<tr>
<td>
{$form.image_URL.label} {help id="id-upload-image" file="CRM/Contact/Form/Contact.hlp"}<br />
{$form.image_URL.html|crmAddClass:twenty}
{if !empty($imageURL)}
{include file="CRM/Contact/Page/ContactImage.tpl"}
{/if}
</td>
</tr>
</table>
{*add dupe buttons *}
<span class="crm-button crm-button_qf_Contact_refresh_dedupe">
{$form._qf_Contact_refresh_dedupe.html}
</span>
{if $isDuplicate}
<span class="crm-button crm-button_qf_Contact_upload_duplicate">
{$form._qf_Contact_upload_duplicate.html}
</span>
{/if}
<div class="spacer"></div>
</div>
</div><!-- /.crm-accordion-body -->
</div><!-- /.crm-accordion-wrapper -->
{foreach from = $editOptions item = "title" key="name"}
{if $name eq 'CustomData' }
<div id='customData'>{include file="CRM/Contact/Form/Edit/CustomData.tpl"}</div>
{else}
{include file="CRM/Contact/Form/Edit/$name.tpl"}
{/if}
{/foreach}
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
</div>
{literal}
<script type="text/javascript" >
CRM.$(function($) {
var $form = $("form.{/literal}{$form.formClass}{literal}"),
action = "{/literal}{$action}{literal}",
_ = CRM._;
$('.crm-accordion-body').each( function() {
//remove tab which doesn't have any element
if ( ! $.trim( $(this).text() ) ) {
ele = $(this);
prevEle = $(this).prev();
$(ele).remove();
$(prevEle).remove();
}
//open tab if form rule throws error
if ( $(this).children().find('span.crm-error').text().length > 0 ) {
$(this).parents('.collapsed').crmAccordionToggle();
}
});
if (action == '2') {
$('.crm-accordion-wrapper').not('.crm-accordion-wrapper .crm-accordion-wrapper').each(function() {
highlightTabs(this);
});
$('#crm-container').on('change click', '.crm-accordion-body :input, .crm-accordion-body a', function() {
highlightTabs($(this).parents('.crm-accordion-wrapper'));
});
}
function highlightTabs(tab) {
//highlight the tab having data inside.
$('.crm-accordion-body :input', tab).each( function() {
var active = false;
switch($(this).prop('type')) {
case 'checkbox':
case 'radio':
if($(this).is(':checked') && !$(this).is('[id$=IsPrimary],[id$=IsBilling]')) {
$('.crm-accordion-header:first', tab).addClass('active');
return false;
}
break;
case 'text':
case 'textarea':
if($(this).val()) {
$('.crm-accordion-header:first', tab).addClass('active');
return false;
}
break;
case 'select-one':
case 'select-multiple':
if($(this).val() && $('option[value=""]', this).length > 0) {
$('.crm-accordion-header:first', tab).addClass('active');
return false;
}
break;
case 'file':
if($(this).next().html()) {
$('.crm-accordion-header:first', tab).addClass('active');
return false;
}
break;
}
$('.crm-accordion-header:first', tab).removeClass('active');
});
}
$('a#expand').click( function() {
if( $(this).attr('href') == '#expand') {
var message = {/literal}"{ts escape='js'}Collapse all tabs{/ts}"{literal};
$(this).attr('href', '#collapse');
$('.crm-accordion-wrapper.collapsed').crmAccordionToggle();
}
else {
var message = {/literal}"{ts escape='js'}Expand all tabs{/ts}"{literal};
$('.crm-accordion-wrapper:not(.collapsed)').crmAccordionToggle();
$(this).attr('href', '#expand');
}
$(this).html(message);
return false;
});
$('.customDataPresent').change(function() {
var values = $("#contact_sub_type").val();
CRM.buildCustomData({/literal}"{$contactType}"{literal}, values).one('crmLoad', function() {
highlightTabs(this);
loadMultiRecordFields(values);
});
});
function loadMultiRecordFields(subTypeValues) {
if (subTypeValues === false) {
subTypeValues = null;
}
else if (!subTypeValues) {
subTypeValues = {/literal}"{$paramSubType}"{literal};
}
function loadNextRecord(i, groupValue, groupCount) {
if (i < groupCount) {
CRM.buildCustomData({/literal}"{$contactType}"{literal}, subTypeValues, null, i, groupValue, true).one('crmLoad', function() {
highlightTabs(this);
loadNextRecord(i+1, groupValue, groupCount);
});
}
}
{/literal}
{foreach from=$customValueCount item="groupCount" key="groupValue"}
{if $groupValue}{literal}
loadNextRecord(1, {/literal}{$groupValue}{literal}, {/literal}{$groupCount}{literal});
{/literal}
{/if}
{/foreach}
{literal}
}
loadMultiRecordFields();
{/literal}{if $oldSubtypes}{literal}
$('input[name=_qf_Contact_upload_view], input[name=_qf_Contact_upload_new]').click(function() {
var submittedSubtypes = $('#contact_sub_type').val();
var oldSubtypes = {/literal}{$oldSubtypes}{literal};
var warning = false;
$.each(oldSubtypes, function(index, subtype) {
if ( $.inArray(subtype, submittedSubtypes) < 0 ) {
warning = true;
}
});
if ( warning ) {
return confirm({/literal}'{ts escape="js"}One or more contact subtypes have been de-selected from the list for this contact. Any custom data associated with de-selected subtype will be removed as long as the contact does not have a contact subtype still selected. Click OK to proceed, or Cancel to review your changes before saving.{/ts}'{literal});
}
return true;
});
{/literal}{/if}{literal}
// Handle delete of multi-record custom data
$form.on('click', '.crm-custom-value-del', function(e) {
e.preventDefault();
var $el = $(this),
msg = '{/literal}{ts escape="js"}The record will be deleted immediately. This action cannot be undone.{/ts}{literal}';
CRM.confirm({title: $el.attr('title'), message: msg})
.on('crmConfirm:yes', function() {
var url = CRM.url('civicrm/ajax/customvalue');
var request = $.post(url, $el.data('post'));
CRM.status({success: '{/literal}{ts escape="js"}Record Deleted{/ts}{literal}'}, request);
var addClass = '.add-more-link-' + $el.data('post').groupID;
$el.closest('div.crm-custom-accordion').remove();
$('div' + addClass).last().show();
});
});
{/literal}{* Ajax check for matching contacts *}
{if $checkSimilar == 1}
var contactType = {$contactType|@json_encode},
rules = {*$ruleFields|@json_encode*}{literal}[
'first_name',
'last_name',
'nick_name',
'household_name',
'organization_name',
'email'
],
ruleFields = {},
$ruleElements = $(),
matchMessage,
runningCheck = 0;
$.each(rules, function(i, field) {
// Match regular fields
var $el = $('#' + field + ', #' + field + '_1_' + field, $form).filter(':input');
// Match custom fields
if (!$el.length && field.lastIndexOf('_') > 0) {
var pieces = field.split('_');
field = 'custom_' + pieces[pieces.length-1];
$el = $('#' + field + ', [name=' + field + '_-1]', $form).filter(':input');
}
if ($el.length) {
ruleFields[field] = $el;
$ruleElements = $ruleElements.add($el);
}
});
$ruleElements.on('change', checkMatches);
function checkMatches() {
if ($(this).is('input[type=text]') && $(this).val().length < 3) {
return;
}
var match = {contact_type: contactType},
checkNum = ++runningCheck;
$.each(ruleFields, function(fieldName, ruleField) {
if (ruleField.length > 1) {
match[fieldName] = ruleField.filter(':checked').val();
} else if (ruleField.is('input[type=text]')) {
if (ruleField.val().length > 2) {
match[fieldName] = ruleField.val() + '%'; // Todo: remove wildcard when switching to contact.match api
}
} else {
match[fieldName] = ruleField.val();
}
});
// CRM-20565 - Need a good default matching rule before using the dedupe engine for this. Using contact.get for now.
// CRM.api3('contact', 'duplicatecheck', {
// match: match,
// rule_type: 'Supervised',
// options: {sort: 'sort_name'},
// return: ['display_name', 'email']
// }).done(function(data) {
CRM.api3('contact', 'get', _.extend({
options: {sort: 'sort_name'},
return: ['display_name', 'email']
}, match)).done(function(data) {
// If a new request has started running, cancel this one.
if (checkNum < runningCheck) {
return;
}
// Close msg if it exists
matchMessage && matchMessage.close && matchMessage.close();
var title = data.count == 1 ? {/literal}"{ts escape='js'}Similar Contact Found{/ts}" : "{ts escape='js'}Similar Contacts Found{/ts}"{literal},
msg = "<em>{/literal}{ts escape='js'}If the contact you were trying to add is listed below, click their name to view or edit their record{/ts}{literal}:</em>";
if (data.is_error == 1 || data.count == 0) {
return;
}
msg += '<ul class="matching-contacts-actions">';
$.each(data.values, function(i, contact) {
contact.email = contact.email || '';
msg += '<li><a href="'+ CRM.url('civicrm/contact/view', {reset: 1, cid: contact.id}) + '">'+ contact.display_name +'</a> '+contact.email+'</li>';
});
msg += '</ul>';
matchMessage = CRM.alert(msg, title);
$('.matching-contacts-actions a').click(function() {
// No confirmation dialog on click
$('[data-warn-changes=true]').attr('data-warn-changes', 'false');
});
});
}
{/literal}{/if}{literal}
});
</script>
{/literal}
{* jQuery validate *}
{include file="CRM/Form/validate.tpl"}
{* include common additional blocks tpl *}
{include file="CRM/common/additionalBlocks.tpl"}
{/if}