1 // http://civicrm.org/licensing
2 // Controls search form action links and refreshes
4 $('#crm-main-content-wrapper')
5 // Widgetize the content area
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');
25 function countSelectedCheckboxes(fldPrefix
, form
) {
27 for (i
= 0; i
< form
.elements
.length
; i
++) {
28 fpLen
= fldPrefix
.length
;
29 if (form
.elements
[i
].type
== 'checkbox' && form
.elements
[i
].name
.slice(0, fpLen
) == fldPrefix
&& form
.elements
[i
].checked
== true) {
37 * This function is used to check if any action is selected and also to check if any contacts are checked.
40 * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as
41 * belonging to the resultset's checkbox collection
42 * @param form - name of form that checkboxes are part of
43 * Sample usage: onClick="javascript:checkPerformAction('chk_', myForm );"
46 function checkPerformAction(fldPrefix
, form
, taskButton
, selection
) {
50 // taskButton TRUE means we don't need to check the 'task' field - it's a button-driven task
51 if (taskButton
== 1) {
55 if (document
.forms
[form
].task
.selectedIndex
) {
56 //force user to select all search contacts, CRM-3711
57 if (document
.forms
[form
].task
.value
== 13 || document
.forms
[form
].task
.value
== 14) {
58 var toggleSelect
= document
.getElementsByName('toggleSelect');
59 if (toggleSelect
[0].checked
|| document
.forms
[form
].radio_ts
[0].checked
) {
63 alert("Please select all contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button.");
72 // If user wants to perform action on ALL records and we have a task, return (no need to check further)
73 if (document
.forms
[form
].radio_ts
[0].checked
) {
77 cnt
= (selection
== 1) ? countSelections() : countSelectedCheckboxes(fldPrefix
, document
.forms
[form
]);
79 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.");
84 alert("Please select an action from the drop-down menu.");
90 * Function to enable task action select
92 function toggleTaskAction(status
) {
93 var radio_ts
= document
.getElementsByName('radio_ts');
95 radio_ts
[0].checked
= true;
97 if (radio_ts
[0].checked
|| radio_ts
[1].checked
) {
101 var formElements
= ['task', 'Go', 'Print'];
102 for (var i
= 0; i
< formElements
.length
; i
++) {
103 var element
= document
.getElementById(formElements
[i
]);
106 element
.disabled
= false;
109 element
.disabled
= true;