1 // http://civicrm.org/licensing
2 // Controls search form action links and refreshes
4 $('#crm-main-content-wrapper').crmSnippet();
5 if (CRM
.config
.ajax_popups_enabled
) {
6 $('#crm-main-content-wrapper')
7 // Open action links in a popup
8 .off('click.crmLivePage')
9 .on('click.crmLivePage', 'a.button, a.action-item', function () {
10 var url
= $(this).attr('href');
11 // only follow real links not javascript buttons
12 if (url
=== '#' || $(this).attr('onclick') || $(this).hasClass('no-popup')) {
16 openInline
: 'a:not("[href=#], .no-popup")'
17 }).on('crmFormSuccess', function (e
, data
) {
18 // Refresh page when form completes
19 $('#crm-main-content-wrapper').crmSnippet('refresh');
26 function countSelectedCheckboxes(fldPrefix
, form
) {
28 for (i
= 0; i
< form
.elements
.length
; i
++) {
29 fpLen
= fldPrefix
.length
;
30 if (form
.elements
[i
].type
== 'checkbox' && form
.elements
[i
].name
.slice(0, fpLen
) == fldPrefix
&& form
.elements
[i
].checked
== true) {
38 * This function is used to check if any action is selected and also to check if any contacts are checked.
41 * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as
42 * belonging to the resultset's checkbox collection
43 * @param form - name of form that checkboxes are part of
44 * Sample usage: onClick="javascript:checkPerformAction('chk_', myForm );"
47 function checkPerformAction(fldPrefix
, form
, taskButton
, selection
) {
51 // taskButton TRUE means we don't need to check the 'task' field - it's a button-driven task
52 if (taskButton
== 1) {
56 if (document
.forms
[form
].task
.selectedIndex
) {
57 //force user to select all search contacts, CRM-3711
58 if (document
.forms
[form
].task
.value
== 13 || document
.forms
[form
].task
.value
== 14) {
59 var toggleSelect
= document
.getElementsByName('toggleSelect');
60 if (toggleSelect
[0].checked
|| document
.forms
[form
].radio_ts
[0].checked
) {
64 alert("Please select all contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button.");
73 // If user wants to perform action on ALL records and we have a task, return (no need to check further)
74 if (document
.forms
[form
].radio_ts
[0].checked
) {
78 cnt
= (selection
== 1) ? countSelections() : countSelectedCheckboxes(fldPrefix
, document
.forms
[form
]);
80 alert("Please select one or more contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button.");
85 alert("Please select an action from the drop-down menu.");
91 * Function to enable task action select
93 function toggleTaskAction(status
) {
94 var radio_ts
= document
.getElementsByName('radio_ts');
96 radio_ts
[0].checked
= true;
98 if (radio_ts
[0].checked
|| radio_ts
[1].checked
) {
102 var formElements
= ['task', 'Go', 'Print'];
103 for (var i
= 0; i
< formElements
.length
; i
++) {
104 var element
= document
.getElementById(formElements
[i
]);
107 element
.disabled
= false;
110 element
.disabled
= true;