Merge pull request #12277 from seamuslee001/dev_core_163
[civicrm-core.git] / templates / CRM / Contact / Page / DedupeFind.tpl
1 {*
2 +--------------------------------------------------------------------+
3 | CiviCRM version 5 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2018 |
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 {if $action eq 2 || $action eq 16}
27 <div class="form-item">
28 <div class="crm-accordion-wrapper crm-search_filters-accordion">
29 <div class="crm-accordion-header">
30 {ts}Filter Contacts{/ts}</a>
31 </div><!-- /.crm-accordion-header -->
32 <div class="crm-accordion-body">
33 <table class="no-border form-layout-compressed" id="searchOptions" style="width:100%;">
34 <tr>
35 <td class="crm-contact-form-block-contact1">
36 <label for="contact1">{ts}Contact 1{/ts}</label><br />
37 <input type="text" placeholder="Search Contact1" search-column="2" />
38 </td>
39 <td class="crm-contact-form-block-contact2">
40 <label for="contact2">{ts}Contact 2{/ts}</label><br />
41 <input type="text" placeholder="Search Contact2" search-column="4" />
42 </td>
43 <td class="crm-contact-form-block-email1">
44 <label for="email1">{ts}Email 1{/ts}</label><br />
45 <input type="text" placeholder="Search Email1" search-column="5" />
46 </td>
47 <td class="crm-contact-form-block-email2">
48 <label for="email2">{ts}Email 2{/ts}</label><br />
49 <input type="text" placeholder="Search Email2" search-column="6" />
50 </td>
51 </tr>
52 <tr>
53 <td class="crm-contact-form-block-street-address1">
54 <label for="street-adddress1">{ts}Street Address 1{/ts}</label><br />
55 <input type="text" placeholder="Search Street Address1" search-column="7" />
56 </td>
57 <td class="crm-contact-form-block-street-address2">
58 <label for="street-adddress2">{ts}Street Address 2{/ts}</label><br />
59 <input type="text" placeholder="Search Street Address2" search-column="8" />
60 </td>
61 <td class="crm-contact-form-block-postcode1">
62 <label for="postcode1">{ts}Postcode 1{/ts}</label><br />
63 <input type="text" placeholder="Search Postcode1" search-column="9" />
64 </td>
65 <td class="crm-contact-form-block-postcode2">
66 <label for="postcode2">{ts}Postcode 2{/ts}</label><br />
67 <input type="text" placeholder="Search Postcode2" search-column="10" />
68 </td>
69 </tr>
70 </table>
71 </div><!-- /.crm-accordion-body -->
72 </div><!-- /.crm-accordion-wrapper -->
73 <div>
74 Show / Hide columns:
75 <input type='checkbox' id ='steet-address' class='toggle-vis' data-column-main="7" data-column-dupe="8" >
76 <label for="steet-address">{ts}Street Address{/ts}&nbsp;</label>
77 <input type='checkbox' id ='post-code' class='toggle-vis' data-column-main="9" data-column-dupe="10" >
78 <label for="post-code">{ts}Post Code{/ts}&nbsp;</label>
79 <input type='checkbox' id ='conflicts' class='toggle-vis' data-column-main="11" >
80 <label for="conflicts">{ts}Conflicts{/ts}&nbsp; </label>
81 <input type='checkbox' id ='threshold' class='toggle-vis' data-column-main="12" >
82 <label for="threshold">{ts}Threshold{/ts}&nbsp;</label>
83 </div><br/>
84 <span id="dupePairs_length_selection">
85 <input type='checkbox' id ='crm-dedupe-display-selection' name="display-selection">
86 <label for="display-selection">{ts}Within Selections{/ts}&nbsp;</label>
87 </span>
88
89 <table id="dupePairs"
90 class="nestedActivitySelector crm-ajax-table"
91 cellspacing="0"
92 width="100%"
93 data-page-length="10",
94 data-searching='true',
95 data-dom='flrtip',
96 data-order='[]',
97 data-column-defs='{literal}[{"targets": [0,1,3,13], "orderable":false}, {"targets": [7,8,9,10,11,12], "visible":false}]{/literal}'>
98 <thead>
99 <tr class="columnheader">
100 <th data-data="is_selected_input" class="crm-dedupe-selection"><input type="checkbox" value="0" name="pnid_all" class="crm-dedupe-select-all"></th>
101 <th data-data="dst_image" class="crm-empty">&nbsp;</th>
102 <th data-data="dst" class="crm-contact">{ts}Contact{/ts} 1</th>
103 <th data-data="src_image" class="crm-empty">&nbsp;</th>
104 <th data-data="src" class="crm-contact-duplicate">{ts}Contact{/ts} 2 ({ts}Duplicate{/ts})</th>
105 <th data-data="dst_email" class="crm-contact">{ts}Email{/ts} 1</th>
106 <th data-data="src_email" class="crm-contact-duplicate">{ts}Email{/ts} 2 ({ts}Duplicate{/ts})</th>
107 <th data-data="dst_street" class="crm-contact">{ts}Street Address{/ts} 1</th>
108 <th data-data="src_street" class="crm-contact-duplicate">{ts}Street Address{/ts} 2 ({ts}Duplicate{/ts})</th>
109 <th data-data="dst_postcode" class="crm-contact">{ts}Postcode{/ts} 1</th>
110 <th data-data="src_postcode" class="crm-contact-duplicate">{ts}Postcode{/ts} 2 ({ts}Duplicate{/ts})</th>
111 <th data-data="conflicts" class="crm-contact-conflicts">{ts}Conflicts{/ts}</th>
112 <th data-data="weight" class="crm-threshold">{ts}Threshold{/ts}</th>
113 <th data-data="actions" class="crm-empty">&nbsp;</th>
114 </tr>
115 </thead>
116 <tbody>
117 </tbody>
118 </table>
119 </div>
120
121 {if $context eq 'search'}
122 {crmButton href=$backURL icon="times"}{ts}Done{/ts}{/crmButton}
123 {elseif $context eq 'conflicts'}
124 {if call_user_func(array('CRM_Core_Permission','check'), 'force merge duplicate contacts')}
125 {capture assign=backURL}{crmURL p="civicrm/contact/dedupemerge" q="`$urlQuery`&action=map&mode=aggressive" a=1}{/capture}
126 <a href="{$backURL}" title="{ts}Force Merge Selected Duplicates{/ts}" onclick="return confirm('{ts escape="js"}This will run the batch merge process on the selected duplicates. The operation will run in force merge mode - all selected duplicates will be merged into main contacts even in case of any conflicts. Click OK to proceed if you are sure you wish to run this operation.{/ts}');" class="button"><span><i class="crm-i fa-bolt"></i> {ts}Force Merge Selected Duplicates{/ts}</span></a>
127
128 {capture assign=backURL}{crmURL p="civicrm/contact/dedupemerge" q="`$urlQuery`&action=map" a=1}{/capture}
129 <a href="{$backURL}" title="{ts}Safe Merge Selected Duplicates{/ts}" onclick="return confirm('{ts escape="js"}This will run the batch merge process on the selected duplicates. The operation will run in safe mode - only records with no direct data conflicts will be merged. Click OK to proceed if you are sure you wish to run this operation.{/ts}');" class="button"><span><i class="crm-i fa-compress"></i> {ts}Safe Merge Selected Duplicates{/ts}</span></a>
130 {/if}
131
132 {capture assign=backURL}{crmURL p="civicrm/contact/dedupefind" q="`$urlQuery`&action=update&selected=0" a=1}{/capture}
133 <a href="{$backURL}" title="{ts}List All Duplicates{/ts}" class="button"><span><i class="crm-i fa-refresh"></i> {ts}List All Duplicates{/ts}</span></a>
134 {else}
135 {capture assign=backURL}{crmURL p="civicrm/contact/dedupefind" q="`$urlQuery`&action=renew" a=1}{/capture}
136 <a href="{$backURL}" title="{ts}Refresh List of Duplicates{/ts}" onclick="return confirm('{ts escape="js"}This will refresh the duplicates list. Click OK to proceed.{/ts}');" class="button">
137 <span><i class="crm-i fa-refresh"></i> {ts}Refresh Duplicates{/ts}</span>
138 </a>
139
140 {capture assign=backURL}{crmURL p="civicrm/contact/dedupemerge" q="`$urlQuery`&action=map" a=1}{/capture}
141 <a href="{$backURL}" title="{ts}Batch Merge Duplicate Contacts{/ts}" onclick="return confirm('{ts escape="js"}This will run the batch merge process on the selected duplicates. The operation will run in safe mode - only records with no direct data conflicts will be merged. Click OK to proceed if you are sure you wish to run this operation.{/ts}');" class="button"><span><i class="crm-i fa-compress"></i> {ts}Batch Merge Selected Duplicates{/ts}</span></a>
142
143 {capture assign=backURL}{crmURL p="civicrm/contact/dedupemerge" q=$urlQuery a=1}{/capture}
144 <a href="{$backURL}" title="{ts}Batch Merge Duplicate Contacts{/ts}" onclick="return confirm('{ts escape="js"}This will run the batch merge process on the listed duplicates. The operation will run in safe mode - only records with no direct data conflicts will be merged. Click OK to proceed if you are sure you wish to run this operation.{/ts}');" class="button"><span><i class="crm-i fa-compress"></i> {ts}Batch Merge All Duplicates{/ts}</span></a>
145
146 <a href='#' title="{ts}Flip Selected Duplicates{/ts}" class="crm-dedupe-flip-selections button"><span><i class="crm-i fa-exchange"></i> {ts}Flip Selected Duplicates{/ts}</span></a>
147
148 {capture assign=backURL}{crmURL p="civicrm/contact/deduperules" q="reset=1" a=1}{/capture}
149 <a href="{$backURL}" class="button crm-button-type-cancel">
150 <span><i class="crm-i fa-times"></i> {ts}Done{/ts}</span>
151 </a>
152 {/if}
153 <div style="clear: both;"></div>
154 {else}
155 {include file="CRM/Contact/Form/DedupeFind.tpl"}
156 {/if}
157
158 {* process the dupe contacts *}
159 {include file='CRM/common/dedupe.tpl'}
160 {literal}
161 <script type="text/javascript">
162 (function($) {
163 CRM.$('table#dupePairs').data({
164 "ajax": {
165 "url": {/literal}'{$sourceUrl}{if $isSelected}&selected=1{/if}'{literal}
166 },
167 "retrieve": true,
168 "processing": true,
169 "serverSide": true,
170 rowCallback: function (row, data) {
171 // Set the checked state of the checkbox in the table
172 $('input.crm-dedupe-select', row).prop('checked', data.is_selected == 1);
173 if (data.is_selected == 1) {
174 $(row).toggleClass('crm-row-selected');
175 }
176 // for action column at the last, set nowrap
177 $('td:last', row).attr('nowrap','nowrap');
178 // for conflicts column
179 var col = CRM.$('table#dupePairs thead th.crm-contact-conflicts').index();
180 $('td:eq(' + col + ')', row).attr('nowrap','nowrap');
181 }
182 });
183 $(function($) {
184
185 var sourceUrl = {/literal}'{$sourceUrl}'{literal};
186 var context = {/literal}'{$context}'{literal};
187
188 // redraw datatable if searching within selected records
189 $('#crm-dedupe-display-selection').on('click', function(){
190 reloadUrl = sourceUrl;
191 if($(this).prop('checked')){
192 reloadUrl = sourceUrl+'&selected=1';
193 }
194 CRM.$('table#dupePairs').DataTable().ajax.url(reloadUrl).draw();
195 });
196
197 $('#dupePairs_length_selection').appendTo('#dupePairs_length');
198
199 // apply selected class on click of a row
200 $('#dupePairs tbody').on('click', 'tr', function(e) {
201 $(this).toggleClass('crm-row-selected');
202 $('input.crm-dedupe-select', this).prop('checked', $(this).hasClass('crm-row-selected'));
203 var ele = $('input.crm-dedupe-select', this);
204 toggleDedupeSelect(ele, 0);
205 });
206
207 // when select-all checkbox is checked
208 $('#dupePairs thead tr .crm-dedupe-selection').on('click', function() {
209 var checked = $('.crm-dedupe-select-all').prop('checked');
210 if (checked) {
211 $("#dupePairs tbody tr input[type='checkbox']").prop('checked', true);
212 $("#dupePairs tbody tr").addClass('crm-row-selected');
213 }
214 else{
215 $("#dupePairs tbody tr input[type='checkbox']").prop('checked', false);
216 $("#dupePairs tbody tr").removeClass('crm-row-selected');
217 }
218 var ele = $('#dupePairs tbody tr');
219 toggleDedupeSelect(ele, 1);
220 });
221
222 // inline search boxes placed in tfoot
223 $('#dupePairsColFilters thead th').each( function () {
224 var title = $('#dupePairs thead th').eq($(this).index()).text();
225 if (title.length > 1) {
226 $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
227 }
228 });
229
230 // apply the search
231 $('#searchOptions input').on( 'keyup change', function () {
232 $('table#dupePairs').DataTable()
233 .column($(this).attr('search-column'))
234 .search(this.value)
235 .draw();
236 });
237
238 // show / hide columns
239 $('input.toggle-vis').on('click', function (e) {
240 var column = $('table#dupePairs').DataTable().column( $(this).attr('data-column-main') );
241 column.visible( ! column.visible() );
242
243 // nowrap to conflicts column is applied only during initial rendering
244 // for show / hide clicks we need to set it explicitly
245 var col = CRM.$('table#dupePairs thead th.crm-contact-conflicts').index() + 1;
246 if (col > 0) {
247 CRM.$('table#dupePairs tbody tr td:nth-child(' + col + ')').attr('nowrap','nowrap');
248 }
249
250 if ($(this).attr('data-column-dupe')) {
251 column = $('table#dupePairs').DataTable().column( $(this).attr('data-column-dupe') );
252 column.visible( ! column.visible() );
253 }
254 });
255
256 // keep the conflicts checkbox checked when context is "conflicts"
257 if(context == 'conflicts') {
258 $('#conflicts').attr('checked', true);
259 var column = $('table#dupePairs').DataTable().column( $('#conflicts').attr('data-column-main') );
260 column.visible( ! column.visible() );
261 }
262
263 // on click of flip link of a row
264 $('#dupePairs tbody').on('click', 'tr .crm-dedupe-flip', function(e) {
265 e.stopPropagation();
266 var $el = $(this);
267 var $elTr = $(this).closest('tr');
268 var postUrl = {/literal}"{crmURL p='civicrm/ajax/flipDupePairs' h=0 q='snippet=4'}"{literal};
269 var request = $.post(postUrl, {pnid : $el.data('pnid')});
270 request.done(function(dt) {
271 var mapper = {1:3, 2:4, 5:6, 7:8, 9:10}
272 var idx = $('table#dupePairs').DataTable().row($elTr).index();
273 $.each(mapper, function(key, val) {
274 var v1 = $('table#dupePairs').DataTable().cell(idx, key).data();
275 var v2 = $('table#dupePairs').DataTable().cell(idx, val).data();
276 $('table#dupePairs').DataTable().cell(idx, key).data(v2);
277 $('table#dupePairs').DataTable().cell(idx, val).data(v1);
278 });
279 // keep the checkbox checked if needed
280 $('input.crm-dedupe-select', $elTr).prop('checked', $elTr.hasClass('crm-row-selected'));
281 });
282 });
283
284 $(".crm-dedupe-flip-selections").on('click', function(e) {
285 var ids = [];
286 $('.crm-row-selected').each(function() {
287 var ele = CRM.$('input.crm-dedupe-select', this);
288 ids.push(CRM.$(ele).attr('name').substr(5));
289 });
290 if (ids.length > 0) {
291 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/flipDupePairs' h=0 q='snippet=4'}"{literal};
292 CRM.$.post(dataUrl, {pnid: ids}, function (response) {
293 var mapper = {1:3, 2:4, 5:6, 7:8, 9:10}
294 $('.crm-row-selected').each(function() {
295 var idx = $('table#dupePairs').DataTable().row(this).index();
296 $.each(mapper, function(key, val) {
297 var v1 = $('table#dupePairs').DataTable().cell(idx, key).data();
298 var v2 = $('table#dupePairs').DataTable().cell(idx, val).data();
299 $('table#dupePairs').DataTable().cell(idx, key).data(v2);
300 $('table#dupePairs').DataTable().cell(idx, val).data(v1);
301 });
302 // keep the checkbox checked if needed
303 $('input.crm-dedupe-select', this).prop('checked', $(this).hasClass('crm-row-selected'));
304 });
305 }, 'json');
306 }
307 });
308 });
309 })(CRM.$);
310
311 function toggleDedupeSelect(element, isMultiple) {
312 if (!isMultiple) {
313 var is_selected = CRM.$(element).prop('checked') ? 1: 0;
314 var id = CRM.$(element).prop('name').substr(5);
315 }
316 else {
317 var id = [];
318 CRM.$(element).each(function() {
319 var pnName = CRM.$('input.crm-dedupe-select', this).prop('name');
320 if (pnName !== undefined) {
321 id.push(pnName.substr(5));
322 }
323 });
324 var is_selected = CRM.$('.crm-dedupe-select-all').prop('checked') ? 1 : 0;
325 }
326
327 var criteria = {/literal}'{$criteria|escape}'{literal};
328 criteria = criteria.length > 0 ? criteria : 0;
329
330 var dataUrl = {/literal}"{crmURL p='civicrm/ajax/toggleDedupeSelect' h=0 q='snippet=4'}"{literal};
331 var rgid = {/literal}"{$rgid}"{literal};
332 var gid = {/literal}"{$gid}"{literal};
333
334 rgid = rgid.length > 0 ? rgid : 0;
335 gid = gid.length > 0 ? gid : 0;
336
337 CRM.$.post(dataUrl, {pnid: id, rgid: rgid, gid: gid, is_selected: is_selected, criteria : criteria}, function (data) {
338 // nothing to do for now
339 }, 'json');
340 }
341 </script>
342 {/literal}