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');
27 * Function for checking ALL or unchecking ALL check boxes in a resultset page.
30 * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as
31 * belonging to the resultset's checkbox collection
32 * @param object - checkbox
33 * Sample usage: onClick="javascript:changeCheckboxValues('chk_', cj(this) );"
37 function toggleCheckboxVals(fldPrefix
, object
) {
38 var val
= (object
.id
== 'toggleSelect' && cj(object
).is(':checked'));
39 cj('Input[id*="' + fldPrefix
+ '"],Input[id*="toggleSelect"]').prop('checked', val
);
40 // change the class of selected rows
41 on_load_init_checkboxes(object
.form
.name
);
44 function countSelectedCheckboxes(fldPrefix
, form
) {
46 for (i
= 0; i
< form
.elements
.length
; i
++) {
47 fpLen
= fldPrefix
.length
;
48 if (form
.elements
[i
].type
== 'checkbox' && form
.elements
[i
].name
.slice(0, fpLen
) == fldPrefix
&& form
.elements
[i
].checked
== true) {
56 * This function changes the style for a checkbox block when it is selected.
59 * @param chkName - it is name of the checkbox
62 function checkSelectedBox(chkName
) {
63 var checkElement
= cj('#' + chkName
);
64 if (checkElement
.prop('checked')) {
65 cj('input[value=ts_sel]:radio').prop('checked', true);
66 checkElement
.parents('tr').addClass('crm-row-selected');
69 checkElement
.parents('tr').removeClass('crm-row-selected');
74 * This function is to show the row with selected checkbox in different color
75 * @param form - name of form that checkboxes are part of
80 function on_load_init_checkboxes(form
) {
82 var fldPrefix
= 'mark_x';
83 for (i
= 0; i
< document
.forms
[formName
].elements
.length
; i
++) {
84 fpLen
= fldPrefix
.length
;
85 if (document
.forms
[formName
].elements
[i
].type
== 'checkbox' && document
.forms
[formName
].elements
[i
].name
.slice(0, fpLen
) == fldPrefix
) {
86 checkSelectedBox(document
.forms
[formName
].elements
[i
].name
, formName
);
92 * This function is used to check if any action is selected and also to check if any contacts are checked.
95 * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as
96 * belonging to the resultset's checkbox collection
97 * @param form - name of form that checkboxes are part of
98 * Sample usage: onClick="javascript:checkPerformAction('chk_', myForm );"
101 function checkPerformAction(fldPrefix
, form
, taskButton
, selection
) {
105 // taskButton TRUE means we don't need to check the 'task' field - it's a button-driven task
106 if (taskButton
== 1) {
110 if (document
.forms
[form
].task
.selectedIndex
) {
111 //force user to select all search contacts, CRM-3711
112 if (document
.forms
[form
].task
.value
== 13 || document
.forms
[form
].task
.value
== 14) {
113 var toggleSelect
= document
.getElementsByName('toggleSelect');
114 if (toggleSelect
[0].checked
|| document
.forms
[form
].radio_ts
[0].checked
) {
118 alert("Please select all contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button.");
127 // If user wants to perform action on ALL records and we have a task, return (no need to check further)
128 if (document
.forms
[form
].radio_ts
[0].checked
) {
132 cnt
= (selection
== 1) ? countSelections() : countSelectedCheckboxes(fldPrefix
, document
.forms
[form
]);
134 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.");
139 alert("Please select an action from the drop-down menu.");
145 * Function to enable task action select
147 function toggleTaskAction(status
) {
148 var radio_ts
= document
.getElementsByName('radio_ts');
150 radio_ts
[0].checked
= true;
152 if (radio_ts
[0].checked
|| radio_ts
[1].checked
) {
156 var formElements
= ['task', 'Go', 'Print'];
157 for (var i
= 0; i
< formElements
.length
; i
++) {
158 var element
= document
.getElementById(formElements
[i
]);
161 element
.disabled
= false;
164 element
.disabled
= true;