2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.2 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2012 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2012
36 * This function can be used to clear default 'suggestive text' from an input field
37 * When the cursor is moved into the field.
39 * It is generally invoked by the input field's onFocus event. Use the reserved
40 * word 'this' to pass this object. EX: onFocus="clearFldVal(this);"
43 * @param fld The form field object whose value is to be cleared
44 * @param hideBlocks Array of element Id's to be hidden
47 function clearFldVal(fld
) {
48 if (fld
.value
== fld
.defaultValue
) {
54 * This function is called by default at the bottom of template files which have forms that have
55 * conditionally displayed/hidden sections and elements. The PHP is responsible for generating
56 * a list of 'blocks to show' and 'blocks to hide' and the template passes these parameters to
60 * @param showBlocks Array of element Id's to be displayed
61 * @param hideBlocks Array of element Id's to be hidden
62 * @param elementType Value to set display style to for showBlocks (e.g. 'block' or 'table-row' or ...)
65 function on_load_init_blocks(showBlocks
, hideBlocks
, elementType
)
67 if ( elementType
== null ) {
68 var elementType
= 'block';
71 /* This loop is used to display the blocks whose IDs are present within the showBlocks array */
72 for ( var i
= 0; i
< showBlocks
.length
; i
++ ) {
73 var myElement
= document
.getElementById(showBlocks
[i
]);
74 /* getElementById returns null if element id doesn't exist in the document */
75 if (myElement
!= null) {
76 myElement
.style
.display
= elementType
;
78 alert('showBlocks array item not in .tpl = ' + showBlocks
[i
]);
82 /* This loop is used to hide the blocks whose IDs are present within the hideBlocks array */
83 for ( var i
= 0; i
< hideBlocks
.length
; i
++ ) {
84 var myElement
= document
.getElementById(hideBlocks
[i
]);
85 /* getElementById returns null if element id doesn't exist in the document */
86 if (myElement
!= null) {
87 myElement
.style
.display
= 'none';
89 alert('showBlocks array item not in .tpl = ' + hideBlocks
[i
]);
95 * This function is called when we need to show or hide a related form element (target_element)
96 * based on the value (trigger_value) of another form field (trigger_field).
99 * @param trigger_field_id HTML id of field whose onchange is the trigger
100 * @param trigger_value List of integers - option value(s) which trigger show-element action for target_field
101 * @param target_element_id HTML id of element to be shown or hidden
102 * @param target_element_type Type of element to be shown or hidden ('block' or 'table-row')
103 * @param field_type Type of element radio/select
104 * @param invert Boolean - if true, we HIDE target on value match; if false, we SHOW target on value match
107 function showHideByValue(trigger_field_id
, trigger_value
, target_element_id
, target_element_type
, field_type
, invert
) {
108 if ( target_element_type
== null ) {
109 var target_element_type
= 'block';
110 } else if ( target_element_type
== 'table-row' ) {
111 var target_element_type
= '';
114 if (field_type
== 'select') {
115 var trigger
= trigger_value
.split("|");
116 var selectedOptionValue
= document
.getElementById(trigger_field_id
).options
[document
.getElementById(trigger_field_id
).selectedIndex
].value
;
118 var target
= target_element_id
.split("|");
119 for(var j
= 0; j
< target
.length
; j
++) {
121 show(target
[j
], target_element_type
);
123 hide(target
[j
],target_element_type
);
125 for(var i
= 0; i
< trigger
.length
; i
++) {
126 if (selectedOptionValue
== trigger
[i
]) {
128 hide(target
[j
],target_element_type
);
130 show(target
[j
],target_element_type
);
136 } else if (field_type
== 'radio') {
137 var target
= target_element_id
.split("|");
138 for(var j
= 0; j
< target
.length
; j
++) {
139 if (document
.getElementsByName(trigger_field_id
)[0].checked
) {
141 hide(target
[j
], target_element_type
);
143 show(target
[j
], target_element_type
);
147 show(target
[j
], target_element_type
);
149 hide(target
[j
], target_element_type
);
157 * This function is used to display a page element (e.g. block or table row or...).
159 * This function is called by various links which handle requests to display the hidden blocks.
160 * An example is the <code>[+] another phone</code> link which expands an additional phone block.
161 * The parameter block_id must have the id of the block which has to be displayed.
165 * @param block_id Id value of the block (or row) to be displayed.
166 * @param elementType Value to set display style to when showing the element (e.g. 'block' or 'table-row' or ...)
169 function show(block_id
,elementType
)
171 if ( elementType
== null ) {
172 var elementType
= 'block';
173 } else if ( elementType
== "table-row" && navigator
.appName
== 'Microsoft Internet Explorer' ) {
174 var elementType
= "block";
176 var myElement
= document
.getElementById(block_id
);
177 if (myElement
!= null) {
178 myElement
.style
.display
= elementType
;
180 alert('Request to show() function failed. Element id undefined = '+ block_id
);
185 * This function is used to hide a block.
187 * This function is called by various links which handle requests to hide the visible blocks.
188 * An example is the <code>[-] hide phone</code> link which hides the phone block.
189 * The parameter block_id must have the id of the block which has to be hidden.
192 * @param block_id Id value of the block to be hidden.
195 function hide(block_id
)
197 var myElement
= document
.getElementById(block_id
);
198 if (myElement
!= null) {
199 myElement
.style
.display
= 'none';
201 alert('Request to hide() function failed. Element id undefined = ' + block_id
);
207 * Function for checking ALL or unchecking ALL check boxes in a resultset page.
210 * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as
211 * belonging to the resultset's checkbox collection
212 * @param action - 'select' = set all to checked; 'deselect' = set all to unchecked
213 * @param form - name of form that checkboxes are part of
214 * Sample usage: onClick="javascript:changeCheckboxValues('chk_', 'select', myForm );"
218 function toggleCheckboxVals(fldPrefix
,object
) {
219 if ( object
.id
== 'toggleSelect' && cj(object
).is(':checked') ) {
220 cj( 'Input[id*="' + fldPrefix
+ '"],Input[id*="toggleSelect"]').attr('checked', true);
222 cj( 'Input[id*="' + fldPrefix
+ '"],Input[id*="toggleSelect"]').attr('checked', false);
224 /* function called to change the color of selected rows */
225 on_load_init_checkboxes(object
.form
.name
);
228 function countSelectedCheckboxes(fldPrefix
, form
) {
230 for( i
=0; i
< form
.elements
.length
; i
++) {
231 fpLen
= fldPrefix
.length
;
232 if (form
.elements
[i
].type
== 'checkbox' && form
.elements
[i
].name
.slice(0,fpLen
) == fldPrefix
&& form
.elements
[i
].checked
== true) {
240 * Function to enable task action select
242 function toggleTaskAction( status
) {
243 var radio_ts
= document
.getElementsByName('radio_ts');
245 radio_ts
[0].checked
= true;
247 if ( radio_ts
[0].checked
|| radio_ts
[1].checked
) {
251 var formElements
= ['task', 'Go', 'Print'];
252 for(var i
=0; i
<formElements
.length
; i
++ ) {
253 var element
= document
.getElementById( formElements
[i
] );
256 element
.disabled
= false;
258 element
.disabled
= true;
265 * This function is used to check if any actio is selected and also to check if any contacts are checked.
268 * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as
269 * belonging to the resultset's checkbox collection
270 * @param form - name of form that checkboxes are part of
271 * Sample usage: onClick="javascript:checkPerformAction('chk_', myForm );"
274 function checkPerformAction (fldPrefix
, form
, taskButton
, selection
) {
278 // taskButton TRUE means we don't need to check the 'task' field - it's a button-driven task
279 if (taskButton
== 1) {
281 } else if (document
.forms
[form
].task
.selectedIndex
) {
282 //force user to select all search contacts, CRM-3711
283 if ( document
.forms
[form
].task
.value
== 13 || document
.forms
[form
].task
.value
== 14 ) {
284 var toggleSelect
= document
.getElementsByName('toggleSelect');
285 if ( toggleSelect
[0].checked
|| document
.forms
[form
].radio_ts
[0].checked
) {
288 alert( "Please select all contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button." );
296 // If user wants to perform action on ALL records and we have a task, return (no need to check further)
297 if (document
.forms
[form
].radio_ts
[0].checked
) {
301 cnt
= (selection
== 1) ? countSelections() : countSelectedCheckboxes(fldPrefix
, document
.forms
[form
]);
303 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.");
307 alert ("Please select an action from the drop-down menu.");
313 * This function changes the style for a checkbox block when it is selected.
316 * @param chkName - it is name of the checkbox
319 function checkSelectedBox( chkName
) {
320 var checkElement
= cj('#' + chkName
);
321 if ( checkElement
.attr('checked') ) {
322 cj('input[value=ts_sel]:radio').attr('checked',true );
323 checkElement
.parents('tr').addClass('crm-row-selected');
325 checkElement
.parents('tr').removeClass('crm-row-selected');
330 * This function is to show the row with selected checkbox in different color
331 * @param form - name of form that checkboxes are part of
336 function on_load_init_checkboxes(form
)
339 var fldPrefix
= 'mark_x';
340 for( i
=0; i
< document
.forms
[formName
].elements
.length
; i
++) {
341 fpLen
= fldPrefix
.length
;
342 if (document
.forms
[formName
].elements
[i
].type
== 'checkbox' && document
.forms
[formName
].elements
[i
].name
.slice(0,fpLen
) == fldPrefix
) {
343 checkSelectedBox (document
.forms
[formName
].elements
[i
].name
, formName
);
349 * Function to change the color of the class
351 * @param form - name of the form
352 * @param rowid - id of the <tr>, <div> you want to change
357 function changeRowColor (rowid
, form
) {
358 switch (document
.getElementById(rowid
).className
) {
359 case 'even-row' : document
.getElementById(rowid
).className
= 'selected even-row';
361 case 'odd-row' : document
.getElementById(rowid
).className
= 'selected odd-row';
363 case 'selected even-row' : document
.getElementById(rowid
).className
= 'even-row';
365 case 'selected odd-row' : document
.getElementById(rowid
).className
= 'odd-row';
367 case 'form-item' : document
.getElementById(rowid
).className
= 'selected';
369 case 'selected' : document
.getElementById(rowid
).className
= 'form-item';
374 * This function is to show the row with selected checkbox in different color
375 * @param form - name of form that checkboxes are part of
380 function on_load_init_check(form
)
382 for( i
=0; i
< document
.forms
[form
].elements
.length
; i
++) {
383 if ( ( document
.forms
[form
].elements
[i
].type
== 'checkbox'
384 && document
.forms
[form
].elements
[i
].checked
== true )
385 || ( document
.forms
[form
].elements
[i
].type
== 'hidden'
386 && document
.forms
[form
].elements
[i
].value
== 1 ) ) {
387 var ss
= document
.forms
[form
].elements
[i
].id
;
388 var row
= 'rowid' + ss
;
389 changeRowColor(row
, form
);
395 * reset all the radio buttons with a given name
397 * @param string fieldName
401 function unselectRadio(fieldName
, form
) {
402 for( i
=0; i
< document
.forms
[form
].elements
.length
; i
++) {
403 if (document
.forms
[form
].elements
[i
].name
== fieldName
) {
404 document
.forms
[form
].elements
[i
].checked
= false;
411 * Function to change button text and disable one it is clicked
413 * @param obj object - the button clicked
414 * @param formID string - the id of the form being submitted
415 * @param string procText - button text after user clicks it
419 /* Changes button label on submit, and disables button after submit for newer browsers.
420 Puts up alert for older browsers. */
421 function submitOnce(obj
,formId
,procText
) {
422 // if named button clicked, change text
423 if (obj
.value
!= null) {
424 obj
.value
= procText
+ " ...";
426 if (document
.getElementById
) { // disable submit button for newer browsers
428 document
.getElementById(formId
).submit();
430 } else { // for older browsers
431 if (submitcount
== 0) {
435 alert("Your request is currently being processed ... Please wait.");
442 * Function submits referenced form on click of wizard nav link.
443 * Populates targetPage hidden field prior to POST.
445 * @param formID string - the id of the form being submitted
446 * @param targetPage - identifier of wizard section target
449 function submitCurrentForm(formId
,targetPage
) {
450 alert(formId
+ ' ' + targetPage
);
451 document
.getElementById(formId
).targetPage
.value
= targetPage
;
452 document
.getElementById(formId
).submit();
456 * Function counts and controls maximum word count for textareas.
458 * @param essay_id string - the id of the essay (textarea) field
459 * @param wc - int - number of words allowed
462 function countit(essay_id
,wc
){
463 var text_area
= document
.getElementById("essay_" + essay_id
);
464 var count_element
= document
.getElementById("word_count_" + essay_id
);
466 var text_area_value
= text_area
.value
;
468 var essay
= text_area_value
.replace(regex
," ");
469 var words
= essay
.split(' ');
471 for (z
=0; z
<words
.length
; z
++){
472 if (words
[z
].length
>0){
477 count_element
.value
= count
;
479 /*text_area.value = essay;*/
482 for (z
=0; z
<wc
; z
++){
483 if (words
[z
].length
>0) {
484 dataString
= dataString
+ words
[z
] + ' ';
488 text_area
.value
= dataString
;
491 count_element
.value
= count
;
492 alert("You have reached the "+ wc
+" word limit.");
496 function popUp(URL
) {
499 eval("page" + id
+ " = window.open(URL, '" + id
+ "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=420,left = 202,top = 184');");
502 function imagePopUp ( path
) {
503 window
.open(path
,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,screenX=150,screenY=150,top=150,left=150');
507 * Function to show / hide the row in optionFields
509 * @param element name index, that whose innerHTML is to hide else will show the hidden row.
511 function showHideRow( index
) {
513 cj( 'tr#optionField_' + index
).hide( );
514 if( cj( 'table#optionField tr:hidden:first' ).length
) cj( 'div#optionFieldLink' ).show( );
516 cj( 'table#optionField tr:hidden:first' ).show( );
517 if( ! cj( 'table#optionField tr:hidden:last' ).length
) cj( 'div#optionFieldLink' ).hide( );
523 * Function to check activity status in relavent to activity date
525 * @param element message JSON object.
527 function activityStatus( message
) {
528 var d
= new Date(), time
= [], i
;
529 var currentDateTime
= d
.getTime()
530 var activityTime
= cj("input#activity_date_time_time").val().replace(":", "");
532 //chunk the time in bunch of 2 (hours,minutes,ampm)
533 for(i
=0; i
<activityTime
.length
; i
+=2 ) {
534 time
.push( activityTime
.slice( i
, i
+2 ) );
536 var activityDate
= new Date( cj("input#activity_date_time_hidden").val() );
538 d
.setFullYear(activityDate
.getFullYear());
539 d
.setMonth(activityDate
.getMonth());
540 d
.setDate(activityDate
.getDate());
541 var hours
= time
['0'];
542 var ampm
= time
['2'];
544 if (ampm
== "PM" && hours
!= 0 && hours
!= 12) {
545 // force arithmetic instead of string concatenation
546 hours
= hours
*1 + 12;
547 } else if (ampm
== "AM" && hours
== 12) {
551 d
.setMinutes(time
['1']);
553 var activity_date_time
= d
.getTime();
555 var activityStatusId
= cj('#status_id').val();
557 if ( activityStatusId
== 2 && currentDateTime
< activity_date_time
) {
558 if (! confirm( message
.completed
)) {
561 } else if ( activity_date_time
&& activityStatusId
== 1 && currentDateTime
>= activity_date_time
) {
562 if (! confirm( message
.scheduled
)) {
569 * Function to make multiselect boxes behave as fields in small screens
572 function advmultiselectResize() {
573 var amswidth
= cj("#crm-container form:has(table.advmultiselect)").width();
574 if (amswidth
< 700) {
575 cj("form table.advmultiselect td").each( function() {
576 cj(this).css('display', 'block');
579 cj("form table.advmultiselect td").each( function() {
580 cj(this).css('display', 'table-cell');
583 var contactwidth
= cj('#crm-container #mainTabContainer').width();
584 if (contactwidth
< 600) {
585 cj('#crm-container #mainTabContainer').addClass('narrowpage');
586 cj('#crm-container #mainTabContainer').addClass('narrowpage');
587 cj('#crm-container #mainTabContainer.narrowpage #contactTopBar td').each( function(index
) {
590 cj(this).parent().after('<tr class="narrowadded"></tr>');
593 cj(this).parent().next().append(item
);
597 cj('#crm-container #mainTabContainer.narrowpage').removeClass('narrowpage');
598 cj('#crm-container #mainTabContainer #contactTopBar tr.narrowadded td').each( function() {
599 var nitem
= cj(this);
600 var parent
= cj(this).parent();
601 cj(this).parent().prev().append(nitem
);
602 if ( parent
.children().size() == 0 ) {
606 cj('#crm-container #mainTabContainer.narrowpage #contactTopBar tr.added').detach();
608 var cformwidth
= cj('#crm-container #Contact .contact_basic_information-section').width();
610 if (cformwidth
< 720) {
611 cj('#crm-container .contact_basic_information-section').addClass('narrowform');
612 cj('#crm-container .contact_basic_information-section table.form-layout-compressed td .helpicon').parent().addClass('hashelpicon');
613 if (cformwidth
< 480) {
614 cj('#crm-container .contact_basic_information-section').addClass('xnarrowform');
616 cj('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform');
619 cj('#crm-container .contact_basic_information-section.narrowform').removeClass('narrowform');
620 cj('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform');