Skip to content

Commit

Permalink
Merge pull request civicrm#9 from mathavanveda/dedupe-workflow-45-loc
Browse files Browse the repository at this point in the history
select all option in toggleselect
  • Loading branch information
deepak-srivastava committed Apr 21, 2015
2 parents 8f8c598 + e8d6758 commit 34f243d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
24 changes: 19 additions & 5 deletions CRM/Contact/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -959,25 +959,39 @@ static function selectUnselectContacts() {
static function toggleDedupeSelect() {
$rgid = CRM_Utils_Type::escape($_REQUEST['rgid'], 'Integer');
$gid = CRM_Utils_Type::escape($_REQUEST['gid'], 'Integer');
$pnid = CRM_Utils_Type::escape($_REQUEST['pnid'], 'Integer');
$pnid = $_REQUEST['pnid'];
$isSelected = CRM_Utils_Type::escape($_REQUEST['is_selected'], 'Boolean');

$contactType = CRM_Core_DAO::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type');
$cacheKeyString = "merge $contactType";
$cacheKeyString .= $rgid ? "_{$rgid}" : '_0';
$cacheKeyString .= $gid ? "_{$gid}" : '_0';

$sql = "UPDATE civicrm_prevnext_cache SET is_selected = %1 WHERE id = %2 AND cacheKey LIKE %3";

$params = array(
1 => array($isSelected, 'Boolean'),
2 => array($pnid, 'Integer'),
3 => array("$cacheKeyString%", 'String') // using % to address rows with conflicts as well
);

//check pnid is_array or integer
$whereClause = NULL;
if (is_array($pnid) && !CRM_Utils_Array::crmIsEmptyArray($pnid)) {
$pnid = implode(', ', $pnid);
$pnid = CRM_Utils_Type::escape($pnid, 'String');
$whereClause = " id IN ( {$pnid} ) ";
}
else {
$pnid = CRM_Utils_Type::escape($pnid, 'Integer');
$whereClause = " id = %2";
$params[2] = array($pnid, 'Integer');
}

$sql = "UPDATE civicrm_prevnext_cache SET is_selected = %1 WHERE {$whereClause} AND cacheKey LIKE %3";
CRM_Core_DAO::executeQuery($sql, $params);

CRM_Utils_System::civiExit();
}

/**
* @param $name
*
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/xml/Menu/Contact.xml
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@
<item>
<path>civicrm/ajax/toggleDedupeSelect</path>
<page_callback>CRM_Contact_Page_AJAX::toggleDedupeSelect</page_callback>
<access_arguments>access CiviCRM</access_arguments>
<access_arguments>merge duplicate contacts</access_arguments>
</item>
<item>
<path>civicrm/activity/sms/add</path>
Expand Down
35 changes: 29 additions & 6 deletions templates/CRM/Contact/Page/DedupeFind.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<table id="dupePairs" class="nestedActivitySelector form-layout-compressed" cellspacing="0" width="100%">
<thead>
<tr class="columnheader">
<th class="crm-dedupe-merge">&nbsp;</th>
<th class="crm-dedupe-merge"><input type="checkbox" value="0" name="pnid_all" class="crm-dedupe-select-all"></th>
<th class="crm-empty">&nbsp;</th>
<th class="crm-contact">{ts}Contact{/ts} 1</th>
<th class="crm-contact">{ts}Email{/ts} 1</th>
Expand Down Expand Up @@ -231,9 +231,21 @@ CRM.$(function($) {
$(this).toggleClass('crm-row-selected');
$('input.crm-dedupe-select', this).prop('checked', $(this).hasClass('crm-row-selected'));
var sth = $('input.crm-dedupe-select', this);
toggleDedupeSelect(sth);
toggleDedupeSelect(sth, 0);
});


$('#dupePairs thead tr .crm-dedupe-merge').on('click', function() {
var checked = $('.crm-dedupe-select-all').prop('checked');
if (checked) {
$("#dupePairs tbody tr input[type='checkbox']").prop('checked', true);
}
else{
$("#dupePairs tbody tr input[type='checkbox']").prop('checked', false);
}
var sth = $('#dupePairs tbody tr');
toggleDedupeSelect(sth, 1);
});

// inline search boxes placed in tfoot
$('#dupePairsColFilters thead th').each( function () {
var title = $('#dupePairs thead th').eq($(this).index()).text();
Expand Down Expand Up @@ -271,9 +283,20 @@ CRM.$(function($) {
}
});

function toggleDedupeSelect(element) {
var is_selected = CRM.$(element).prop('checked') ? 1: 0;
var id = CRM.$(element).prop('name').substr(5);
function toggleDedupeSelect(element, isMultiple) {
if (!isMultiple) {
var is_selected = CRM.$(element).prop('checked') ? 1: 0;
var id = CRM.$(element).prop('name').substr(5);
}
else {
var id = [];
CRM.$(element).each(function() {
CRM.$(this).toggleClass('crm-row-selected');
var sth = CRM.$('input.crm-dedupe-select', this);
id.push(CRM.$(sth).prop('name').substr(5));
});
var is_selected = CRM.$('.crm-dedupe-select-all').prop('checked') ? 1 : 0;
}

var dataUrl = {/literal}"{crmURL p='civicrm/ajax/toggleDedupeSelect' h=0 q='snippet=4'}"{literal};
var rgid = {/literal}"{$rgid}"{literal};
Expand Down

0 comments on commit 34f243d

Please sign in to comment.