'weight' => 7,
),
'contact_ajax_check_similar' => array(
- 'html_type' => 'checkbox',
'title' => ts('Check for Similar Contacts'),
'weight' => 8,
+ 'html_type' => NULL,
),
'user_dashboard_options' => array(
'html_type' => 'checkboxes',
$this->addElement('select', 'editor_id', ts('WYSIWYG Editor'), $wysiwyg_options, $extra);
$this->addElement('submit', 'ckeditor_config', ts('Configure CKEditor'));
+ $this->addRadio('contact_ajax_check_similar', ts('Check for Similar Contacts'), array(
+ '1' => ts('While Typing'),
+ '0' => ts('When Saving'),
+ '2' => ts('Never'),
+ ));
+
$editOptions = CRM_Core_OptionGroup::values('contact_edit_options', FALSE, FALSE, FALSE, 'AND v.filter = 0');
$this->assign('editOptions', $editOptions);
$this->postProcessCommon();
+ // Fixme - shouldn't be needed
+ Civi::settings()->set('contact_ajax_check_similar', $this->_params['contact_ajax_check_similar']);
+
// If "Configure CKEditor" button was clicked
if (!empty($this->_params['ckeditor_config'])) {
// Suppress the "Saved" status message and redirect to the CKEditor Config page
* @return bool
* email/openId
*/
- public static function formRule($fields, &$errors, $contactId = NULL) {
+ public static function formRule($fields, &$errors, $contactId, $contactType) {
$config = CRM_Core_Config::singleton();
// validations.
}
}
+ // Check for duplicate contact if it wasn't already handled by ajax or disabled
+ if (!Civi::settings()->get('contact_ajax_check_similar')) {
+ self::checkDuplicateContacts($fields, $errors, $contactId, $contactType);
+ }
+
return $primaryID;
}
$className = 'CRM_Contact_Form_Edit_' . $this->_contactType;
$className::buildQuickForm($this);
+ // Ajax duplicate checking
+ $checkSimilar = $this->_action == CRM_Core_Action::ADD && Civi::settings()->get('contact_ajax_check_similar');
+ $this->assign('checkSimilar', $checkSimilar);
+ if ($checkSimilar == 1) {
+ $ruleParams = array('used' => 'Supervised', 'contact_type' => $this->_contactType);
+ $this->assign('ruleFields', CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams));
+ }
+
// build Custom data if Custom data present in edit option
$buildCustomData = 'noCustomDataPresent';
if (array_key_exists('CustomData', $this->_editOptions)) {
*/
public static function formRule($fields, $files, $contactID = NULL) {
$errors = array();
- $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
+ $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID, 'Household');
// make sure that household name is set
if (empty($fields['household_name'])) {
$errors['household_name'] = 'Household Name should be set.';
}
- //check for duplicate - dedupe rules
- CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Household');
-
return empty($errors) ? TRUE : $errors;
}
}
if (!$inlineEditMode) {
- $checkSimilar = Civi::settings()->get('contact_ajax_check_similar');
-
- if ($checkSimilar == NULL) {
- $checkSimilar = 0;
- }
- $form->assign('checkSimilar', $checkSimilar);
-
//External Identifier Element
$form->addField('external_identifier', array('label' => 'External ID'));
*/
public static function formRule($fields, $files, $contactID = NULL) {
$errors = array();
- $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
+ $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID, 'Individual');
// make sure that firstName and lastName or a primary OpenID is set
if (!$primaryID && (empty($fields['first_name']) || empty($fields['last_name']))) {
$errors['_qf_default'] = ts('First Name and Last Name OR an email OR an OpenID in the Primary Location should be set.');
}
- //check for duplicate - dedupe rules
- CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Individual');
-
return empty($errors) ? TRUE : $errors;
}
*/
public static function formRule($fields, $files, $contactID = NULL) {
$errors = array();
- $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID);
+ $primaryID = CRM_Contact_Form_Contact::formRule($fields, $errors, $contactID, 'Organization');
// make sure that organization name is set
if (empty($fields['organization_name'])) {
$errors['organization_name'] = 'Organization Name should be set.';
}
- //check for duplicate - dedupe rules
- CRM_Contact_Form_Contact::checkDuplicateContacts($fields, $errors, $contactID, 'Organization');
-
// add code to make sure that the uniqueness criteria is satisfied
return empty($errors) ? TRUE : $errors;
}
$dupes = CRM_Contact_BAO_Contact::getDuplicateContacts(
$params['match'],
$params['match']['contact_type'],
- 'Unsupervised',
+ $params['rule_type'],
array(),
CRM_Utils_Array::value('check_permissions', $params),
CRM_Utils_Array::value('dedupe_rule_id', $params)
);
- $values = empty($dupes) ? array() : array_fill_keys($dupes, array());
+ $values = array();
+ if ($dupes && !empty($params['return'])) {
+ return civicrm_api3('Contact', 'get', array(
+ 'return' => $params['return'],
+ 'id' => array('IN' => $dupes),
+ 'options' => CRM_Utils_Array::value('options', $params),
+ 'sequential' => CRM_Utils_Array::value('sequential', $params),
+ 'check_permissions' => CRM_Utils_Array::value('check_permissions', $params),
+ ));
+ }
+ foreach ($dupes as $dupe) {
+ $values[$dupe] = array('id' => $dupe);
+ }
return civicrm_api3_create_success($values, $params, 'Contact', 'duplicatecheck');
}
'description' => 'This will default to the built in unsupervised rule',
'type' => CRM_Utils_Type::T_INT,
);
+ $params['rule_type'] = array(
+ 'title' => 'Dedupe Rule Type',
+ 'description' => 'If no rule id specified, pass "Unsupervised" or "Supervised"',
+ 'type' => CRM_Utils_Type::T_STRING,
+ 'api.default' => 'Unsupervised',
+ );
// @todo declare 'match' parameter. We don't have a standard for type = array yet.
}
'group' => 'core',
'name' => 'contact_ajax_check_similar',
'type' => 'String',
- 'html_type' => 'Text',
+ 'html_type' => 'radio',
'default' => '1',
'add' => '4.1',
- 'title' => 'Ajax Check Similar',
+ 'title' => 'Check for Similar Contacts',
'is_domain' => 1,
'is_contact' => 0,
'description' => NULL,
</td>
</tr>
<tr class="crm-preferences-display-form-block-contact_ajax_check_similar">
- <td class="label"></td>
- <td>{$form.contact_ajax_check_similar.html} {$form.contact_ajax_check_similar.label}</td>
+ <td class="label">{$form.contact_ajax_check_similar.label}</td>
+ <td>{$form.contact_ajax_check_similar.html}</td>
</tr>
<tr class="crm-preferences-display-form-block-description">
<td> </td>
- <td class="description">{ts}When enabled, checks for contacts with similar names as the user types values into the contact form name fields.{/ts}
+ {capture assign=dedupeRules}href="{crmURL p='civicrm/contact/deduperules' q='reset=1'}"{/capture}
+ <td class="description">{ts 1=$dedupeRules}When enabled, checks for possible matches on the "New Contact" form using the Supervised <a %1>matching rule specified in your system</a>.{/ts}
</td>
</tr>
<tr class="crm-preferences-display-form-block-activity_assignee_notification">
alert(ts('Select an entity.'));
return;
}
- if (!_.includes(action, 'get') && action != 'check') {
+ if (!_.includes(action, 'get') && !_.includes(action, 'check')) {
var msg = action === 'delete' ? ts('This will delete data from CiviCRM. Are you sure?') : ts('This will write to the database. Continue?');
CRM.confirm({title: ts('Confirm %1', {1: action}), message: msg}).on('crmConfirm:yes', execute);
} else {
$('div' + addClass).last().show();
});
});
+
+ {/literal}{* Ajax check for matching contacts *}
+ {if $checkSimilar == 1}
+ var contactType = {$contactType|@json_encode},
+ rules = {$ruleFields|@json_encode},
+ {literal}
+ ruleFields = {},
+ $ruleElements = $(),
+ matchMessage;
+ $.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() {
+ // Close msg if it exists
+ matchMessage && matchMessage.close && matchMessage.close();
+ if ($(this).is('input[type=text]') && $(this).val().length < 2) {
+ return;
+ }
+ var match = {contact_type: contactType};
+ $.each(ruleFields, function(fieldName, ruleField) {
+ if (ruleField.length > 1) {
+ match[fieldName] = ruleField.filter(':checked').val();
+ } else {
+ match[fieldName] = ruleField.val();
+ }
+ });
+ CRM.api3('contact', 'duplicatecheck', {
+ match: match,
+ rule_type: 'Supervised',
+ options: {sort: 'sort_name'},
+ return: ['display_name', 'email']
+ }).done(function(data) {
+ 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>
<script type="text/javascript">
{literal}
CRM.$(function($) {
- {/literal}
- var cid = "{$contactId}",
- viewIndividual = "{crmURL p='civicrm/contact/view' q='reset=1&cid=' h=0}",
- checkSimilar = {$checkSimilar},
- lastnameMsg;
- {literal}
if ($('#contact_sub_type *').length == 0) {//if they aren't any subtype we don't offer the option
$('#contact_sub_type').parent().hide();
}
- if (cid.length || !checkSimilar) {
- return;//no dupe check if this is a modif or if checkSimilar is disabled (contact_ajax_check_similar in civicrm_setting table)
- }
- $('#last_name').change(function() {
- // Close msg if it exists
- lastnameMsg && lastnameMsg.close && lastnameMsg.close();
- if (this.value == '') return;
- CRM.api3('contact', 'get', {
- sort_name: $('#last_name').val(),
- contact_type: 'Individual',
- 'return': 'display_name,sort_name,email'
- }).done(function(data) {
- 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 person 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="'+viewIndividual+contact.id+'">'+ contact.display_name +'</a> '+contact.email+'</li>';
- });
- msg += '</ul>';
- lastnameMsg = CRM.alert(msg, title);
- $('.matching-contacts-actions a').click(function() {
- // No confirmation dialog on click
- $('[data-warn-changes=true]').attr('data-warn-changes', 'false');
- });
- });
- });
});
</script>
{/literal}