Skip to content

Commit

Permalink
Core#2918 Implement new UI for configuring dedupe rule usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
braders committed Feb 20, 2022
1 parent 5a02d44 commit faff5d8
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 3 deletions.
12 changes: 11 additions & 1 deletion CRM/Contact/Form/DedupeRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function preProcess() {
CRM_Utils_System::permissionDenied();
CRM_Utils_System::civiExit();
}

Civi::resources()->addScriptFile('civicrm', 'js/crm.dedupeRules.js');

$this->_options = CRM_Core_SelectValues::getDedupeRuleTypes();
$this->_rgid = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0);

Expand All @@ -65,6 +68,8 @@ public function preProcess() {
$this->_defaults['is_reserved'] = $rgDao->is_reserved;
$this->assign('isReserved', $rgDao->is_reserved);
$this->assign('ruleName', $rgDao->name);
$this->assign('ruleUsed', CRM_Core_SelectValues::getDedupeRuleTypes()[$rgDao->used]);
$this->assign('canChangeUsage', $rgDao->used === 'General');
$ruleDao = new CRM_Dedupe_DAO_DedupeRule();
$ruleDao->dedupe_rule_group_id = $this->_rgid;
$ruleDao->find();
Expand All @@ -76,6 +81,11 @@ public function preProcess() {
$count++;
}
}
else {
$this->_defaults['used'] = 'General';
$this->assign('ruleUsed', CRM_Core_SelectValues::getDedupeRuleTypes()['General']);
$this->assign('canChangeUsage', TRUE);
}
$supported = CRM_Dedupe_BAO_DedupeRuleGroup::supportedFields($this->_contactType);
if (is_array($supported)) {
foreach ($supported as $table => $fields) {
Expand All @@ -96,7 +106,7 @@ public function buildQuickForm() {
'objectExists', ['CRM_Dedupe_DAO_DedupeRuleGroup', $this->_rgid, 'title']
);

$this->addField('used', ['label' => ts('Usage')], TRUE);
$this->add('hidden', 'used');
$reserved = $this->addField('is_reserved', ['label' => ts('Reserved?')]);
if (!empty($this->_defaults['is_reserved'])) {
$reserved->freeze();
Expand Down
20 changes: 20 additions & 0 deletions css/civicrm.css
Original file line number Diff line number Diff line change
Expand Up @@ -3926,3 +3926,23 @@ span.crm-status-icon {
.crm-search-display-grid-layout-5 {
grid-template-columns: repeat(5, 1fr);
}

/* Dedupe rules */
.crm-dedupe-rules-form-block-used div {
max-width: 800px;
}
.crm-dedupe-rules-form-block-used p:first-child {
margin-top: 0;
}
.dedupe-rules-dialog [type=radio] {
margin-top: 4px;
}
.dedupe-rules-dialog p:first-child {
margin-top: 0;
}
.dedupe-rules-dialog input[type=radio] {
float: left;
}
.dedupe-rules-dialog label > * {
margin-left: 30px;
}
48 changes: 48 additions & 0 deletions js/crm.dedupeRules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// https://civicrm.org/licensing

CRM.$(function($) {
function updateDisplay() {
var used = jQuery('[name=used]').val();
var inputParent = jQuery('[name=usedDialog][value=' + used + ']').closest('div');
var title = inputParent.find('.dedupe-rules-dialog-title').text();
var desc = inputParent.find('.dedupe-rules-dialog-desc').text();
$('.js-dedupe-rules-current').text(title);
$('.js-dedupe-rules-desc').text(desc);
}
function setInitial() {
var used = jQuery('[name=used]').val();
jQuery('[name=usedDialog][value=' + used + ']').prop('checked', true);
updateDisplay();
}
function setSaveValue() {
var dialogVal = jQuery('[name=usedDialog]:checked').val();
jQuery('[name=used]').val(dialogVal);
updateDisplay();
}
function openDialog() {
var dialog = $('.dedupe-rules-dialog');
dialog.dialog({
title: dialog.attr('data-title'),
width: 800,
buttons: [
{
text: dialog.attr('data-button-close'),
icon: 'fa-close',
click: function() {
dialog.dialog('close');
}
},
{
text: dialog.attr('data-button-update'),
icon: 'fa-check',
click: function() {
setSaveValue();
dialog.dialog('close');
}
}
]
});
}
setInitial();
$('.js-dedupe-rules-change').on('click', openDialog);
});
36 changes: 34 additions & 2 deletions templates/CRM/Contact/Form/DedupeRules.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
</td>
</tr>
<tr class="crm-dedupe-rules-form-block-used">
<td class="label">{$form.used.label}</td>
<td>{$form.used.html} {help id="id-rule-used"}</td>
<td class="label">{ts}Usage{/ts}</td>
<td>
<div>
<p><strong>{ts}Currently set to: {/ts}<span class='js-dedupe-rules-current'></span></strong></p>
<p class='js-dedupe-rules-desc'></p>
<p><button class='crm-button js-dedupe-rules-change' type='button' {if NOT $canChangeUsage} disabled title='{ts 1=$ruleUsed}To change the usage for this rule, please configure another rule as %1{/ts}'{/if}>{ts}Change usage{/ts}</button></p>
</div>
</td>
</tr>
<tr class="crm-dedupe-rules-form-block-is_reserved">
<td class="label">{$form.is_reserved.label}</td>
Expand Down Expand Up @@ -97,3 +103,29 @@
</table>
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
</div>

<div class='dedupe-rules-dialog' data-title='{ts escape='js'}Change usage{/ts}' data-button-close='{ts escape='js'}Close{/ts}' data-button-update='{ts escape='js'}Update{/ts}' hidden>
<p>{ts}CiviCRM includes three types of dedupe rule. <strong>You can only configure one 'Unsupervised' and one 'Supervised' rule for each contact type, but you can configure any number of additional 'General' rules to provide other criteria to scan for possible duplicates.</strong>{/ts}</p>
<p>{ts}Selecting 'Unsupervised' or 'Supervised' will convert the previously configured rule of that type to 'General'.{/ts}</p>
<div>
<label>
<input type="radio" name="usedDialog" value="Unsupervised">
<p><strong class='dedupe-rules-dialog-title'>{ts}Unsupervised{/ts}</strong></p>
<p class='dedupe-rules-dialog-desc'>{ts}The 'Unsupervised' rule for each contact type is automatically used when new contacts are created through online registrations including Events, Membership, Contributions and Profile pages. They are also selected by default when you Import contacts. They are generally configured with a narrow definition of what constitutes a duplicate.{/ts}</p>
</label>
</div>
<div>
<label>
<input type="radio" name="usedDialog" value="Supervised">
<p><strong class='dedupe-rules-dialog-title'>{ts}Supervised{/ts}</strong></p>
<p class='dedupe-rules-dialog-desc'>{ts}The 'Supervised' rule for each contact type is automatically used to check for possible duplicates when contacts are added or edited via the user interface. Supervised Rules should be configured with a broader definition of what constitutes a duplicate.{/ts}</p>
</label>
</div>
<div>
<label>
<input type="radio" name="usedDialog" value="General">
<p><strong class='dedupe-rules-dialog-title'>{ts}General{/ts}</strong></p>
<p class='dedupe-rules-dialog-desc'>{ts}You can configure any number of 'General' rules, to provide other criteria to scan for possible duplicates.{/ts}</p>
</label>
</div>
</div>

0 comments on commit faff5d8

Please sign in to comment.