Commit | Line | Data |
---|---|---|
c1b06d18 | 1 | // http://civicrm.org/licensing |
c1b06d18 | 2 | |
c1b06d18 CW |
3 | function countSelectedCheckboxes(fldPrefix, form) { |
4 | fieldCount = 0; | |
5 | for (i = 0; i < form.elements.length; i++) { | |
6 | fpLen = fldPrefix.length; | |
7 | if (form.elements[i].type == 'checkbox' && form.elements[i].name.slice(0, fpLen) == fldPrefix && form.elements[i].checked == true) { | |
8 | fieldCount++; | |
9 | } | |
10 | } | |
11 | return fieldCount; | |
12 | } | |
13 | ||
c1b06d18 CW |
14 | /** |
15 | * This function is used to check if any action is selected and also to check if any contacts are checked. | |
16 | * | |
17 | * @access public | |
18 | * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as | |
19 | * belonging to the resultset's checkbox collection | |
20 | * @param form - name of form that checkboxes are part of | |
21 | * Sample usage: onClick="javascript:checkPerformAction('chk_', myForm );" | |
22 | * | |
23 | */ | |
24 | function checkPerformAction(fldPrefix, form, taskButton, selection) { | |
25 | var cnt; | |
26 | var gotTask = 0; | |
27 | ||
28 | // taskButton TRUE means we don't need to check the 'task' field - it's a button-driven task | |
29 | if (taskButton == 1) { | |
30 | gotTask = 1; | |
31 | } | |
32 | else { | |
33 | if (document.forms[form].task.selectedIndex) { | |
34 | //force user to select all search contacts, CRM-3711 | |
35 | if (document.forms[form].task.value == 13 || document.forms[form].task.value == 14) { | |
36 | var toggleSelect = document.getElementsByName('toggleSelect'); | |
37 | if (toggleSelect[0].checked || document.forms[form].radio_ts[0].checked) { | |
38 | return true; | |
39 | } | |
40 | else { | |
41 | alert("Please select all contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button."); | |
42 | return false; | |
43 | } | |
44 | } | |
45 | gotTask = 1; | |
46 | } | |
47 | } | |
48 | ||
49 | if (gotTask == 1) { | |
50 | // If user wants to perform action on ALL records and we have a task, return (no need to check further) | |
51 | if (document.forms[form].radio_ts[0].checked) { | |
52 | return true; | |
53 | } | |
54 | ||
55 | cnt = (selection == 1) ? countSelections() : countSelectedCheckboxes(fldPrefix, document.forms[form]); | |
56 | if (!cnt) { | |
57 | 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."); | |
58 | return false; | |
59 | } | |
60 | } | |
61 | else { | |
62 | alert("Please select an action from the drop-down menu."); | |
63 | return false; | |
64 | } | |
65 | } | |
66 | ||
67 | /** | |
68 | * Function to enable task action select | |
69 | */ | |
70 | function toggleTaskAction(status) { | |
71 | var radio_ts = document.getElementsByName('radio_ts'); | |
72 | if (!radio_ts[1]) { | |
73 | radio_ts[0].checked = true; | |
74 | } | |
75 | if (radio_ts[0].checked || radio_ts[1].checked) { | |
76 | status = true; | |
77 | } | |
78 | ||
79 | var formElements = ['task', 'Go', 'Print']; | |
80 | for (var i = 0; i < formElements.length; i++) { | |
81 | var element = document.getElementById(formElements[i]); | |
82 | if (element) { | |
83 | if (status) { | |
84 | element.disabled = false; | |
85 | } | |
86 | else { | |
87 | element.disabled = true; | |
88 | } | |
89 | } | |
90 | } | |
91 | } |