2 +--------------------------------------------------------------------+
3 | CiviCRM version 4.4 |
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
28 * @file: global functions for CiviCRM
29 * FIXME: We are moving away from using global functions. DO NOT ADD MORE.
30 * @see CRM object - the better alternative to adding global functions
37 * Short-named function for string translation, defined in global scope so it's available everywhere.
39 * @param $text string string for translating
40 * @param $params object key:value of additional parameters
42 * @return string the translated string
44 function ts(text
, params
) {
46 text
= CRM
.strings
[text
] || text
;
47 if (typeof(params
) === 'object') {
48 for (var i
in params
) {
49 if (typeof(params
[i
]) === 'string' || typeof(params
[i
]) === 'number') {
50 // sprintf emulation: escape % characters in the replacements to avoid conflicts
51 text
= text
.replace(new RegExp('%' + i
, 'g'), String(params
[i
]).replace(/%/g
, '%-crmescaped-'));
54 return text
.replace(/%-crmescaped-/g, '%');
60 * This function is called by default at the bottom of template files which have forms that have
61 * conditionally displayed/hidden sections and elements. The PHP is responsible for generating
62 * a list of 'blocks to show' and 'blocks to hide' and the template passes these parameters to
66 * @param showBlocks Array of element Id's to be displayed
67 * @param hideBlocks Array of element Id's to be hidden
68 * @param elementType Value to set display style to for showBlocks (e.g. 'block' or 'table-row' or ...)
71 function on_load_init_blocks(showBlocks
, hideBlocks
, elementType
) {
72 if (elementType
== null) {
73 var elementType
= 'block';
76 /* This loop is used to display the blocks whose IDs are present within the showBlocks array */
77 for (var i
= 0; i
< showBlocks
.length
; i
++) {
78 var myElement
= document
.getElementById(showBlocks
[i
]);
79 /* getElementById returns null if element id doesn't exist in the document */
80 if (myElement
!= null) {
81 myElement
.style
.display
= elementType
;
84 alert('showBlocks array item not in .tpl = ' + showBlocks
[i
]);
88 /* This loop is used to hide the blocks whose IDs are present within the hideBlocks array */
89 for (var i
= 0; i
< hideBlocks
.length
; i
++) {
90 var myElement
= document
.getElementById(hideBlocks
[i
]);
91 /* getElementById returns null if element id doesn't exist in the document */
92 if (myElement
!= null) {
93 myElement
.style
.display
= 'none';
96 alert('showBlocks array item not in .tpl = ' + hideBlocks
[i
]);
102 * This function is called when we need to show or hide a related form element (target_element)
103 * based on the value (trigger_value) of another form field (trigger_field).
106 * @param trigger_field_id HTML id of field whose onchange is the trigger
107 * @param trigger_value List of integers - option value(s) which trigger show-element action for target_field
108 * @param target_element_id HTML id of element to be shown or hidden
109 * @param target_element_type Type of element to be shown or hidden ('block' or 'table-row')
110 * @param field_type Type of element radio/select
111 * @param invert Boolean - if true, we HIDE target on value match; if false, we SHOW target on value match
114 function showHideByValue(trigger_field_id
, trigger_value
, target_element_id
, target_element_type
, field_type
, invert
) {
115 if (target_element_type
== null) {
116 var target_element_type
= 'block';
119 if (target_element_type
== 'table-row') {
120 var target_element_type
= '';
124 if (field_type
== 'select') {
125 var trigger
= trigger_value
.split("|");
126 var selectedOptionValue
= document
.getElementById(trigger_field_id
).options
[document
.getElementById(trigger_field_id
).selectedIndex
].value
;
128 var target
= target_element_id
.split("|");
129 for (var j
= 0; j
< target
.length
; j
++) {
131 cj('#' + target
[j
]).show();
134 cj('#' + target
[j
]).hide();
136 for (var i
= 0; i
< trigger
.length
; i
++) {
137 if (selectedOptionValue
== trigger
[i
]) {
139 cj('#' + target
[j
]).hide();
142 cj('#' + target
[j
]).show();
150 if (field_type
== 'radio') {
151 var target
= target_element_id
.split("|");
152 for (var j
= 0; j
< target
.length
; j
++) {
153 if (document
.getElementsByName(trigger_field_id
)[0].checked
) {
155 cj('#' + target
[j
]).hide();
158 cj('#' + target
[j
]).show();
163 cj('#' + target
[j
]).show();
166 cj('#' + target
[j
]).hide();
176 * Function for checking ALL or unchecking ALL check boxes in a resultset page.
179 * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as
180 * belonging to the resultset's checkbox collection
181 * @param object - checkbox
182 * Sample usage: onClick="javascript:changeCheckboxValues('chk_', cj(this) );"
186 function toggleCheckboxVals(fldPrefix
, object
) {
187 if (object
.id
== 'toggleSelect' && cj(object
).is(':checked')) {
188 cj('Input[id*="' + fldPrefix
+ '"],Input[id*="toggleSelect"]').attr('checked', true);
191 cj('Input[id*="' + fldPrefix
+ '"],Input[id*="toggleSelect"]').attr('checked', false);
193 // change the class of selected rows
194 on_load_init_checkboxes(object
.form
.name
);
197 function countSelectedCheckboxes(fldPrefix
, form
) {
199 for (i
= 0; i
< form
.elements
.length
; i
++) {
200 fpLen
= fldPrefix
.length
;
201 if (form
.elements
[i
].type
== 'checkbox' && form
.elements
[i
].name
.slice(0, fpLen
) == fldPrefix
&& form
.elements
[i
].checked
== true) {
209 * Function to enable task action select
211 function toggleTaskAction(status
) {
212 var radio_ts
= document
.getElementsByName('radio_ts');
214 radio_ts
[0].checked
= true;
216 if (radio_ts
[0].checked
|| radio_ts
[1].checked
) {
220 var formElements
= ['task', 'Go', 'Print'];
221 for (var i
= 0; i
< formElements
.length
; i
++) {
222 var element
= document
.getElementById(formElements
[i
]);
225 element
.disabled
= false;
228 element
.disabled
= true;
235 * This function is used to check if any actio is selected and also to check if any contacts are checked.
238 * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as
239 * belonging to the resultset's checkbox collection
240 * @param form - name of form that checkboxes are part of
241 * Sample usage: onClick="javascript:checkPerformAction('chk_', myForm );"
244 function checkPerformAction(fldPrefix
, form
, taskButton
, selection
) {
248 // taskButton TRUE means we don't need to check the 'task' field - it's a button-driven task
249 if (taskButton
== 1) {
253 if (document
.forms
[form
].task
.selectedIndex
) {
254 //force user to select all search contacts, CRM-3711
255 if (document
.forms
[form
].task
.value
== 13 || document
.forms
[form
].task
.value
== 14) {
256 var toggleSelect
= document
.getElementsByName('toggleSelect');
257 if (toggleSelect
[0].checked
|| document
.forms
[form
].radio_ts
[0].checked
) {
261 alert("Please select all contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button.");
270 // If user wants to perform action on ALL records and we have a task, return (no need to check further)
271 if (document
.forms
[form
].radio_ts
[0].checked
) {
275 cnt
= (selection
== 1) ? countSelections() : countSelectedCheckboxes(fldPrefix
, document
.forms
[form
]);
277 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.");
282 alert("Please select an action from the drop-down menu.");
288 * This function changes the style for a checkbox block when it is selected.
291 * @param chkName - it is name of the checkbox
294 function checkSelectedBox(chkName
) {
295 var checkElement
= cj('#' + chkName
);
296 if (checkElement
.attr('checked')) {
297 cj('input[value=ts_sel]:radio').attr('checked', true);
298 checkElement
.parents('tr').addClass('crm-row-selected');
301 checkElement
.parents('tr').removeClass('crm-row-selected');
306 * This function is to show the row with selected checkbox in different color
307 * @param form - name of form that checkboxes are part of
312 function on_load_init_checkboxes(form
) {
314 var fldPrefix
= 'mark_x';
315 for (i
= 0; i
< document
.forms
[formName
].elements
.length
; i
++) {
316 fpLen
= fldPrefix
.length
;
317 if (document
.forms
[formName
].elements
[i
].type
== 'checkbox' && document
.forms
[formName
].elements
[i
].name
.slice(0, fpLen
) == fldPrefix
) {
318 checkSelectedBox(document
.forms
[formName
].elements
[i
].name
, formName
);
324 * Function to change the color of the class
326 * @param form - name of the form
327 * @param rowid - id of the <tr>, <div> you want to change
332 function changeRowColor(rowid
, form
) {
333 switch (document
.getElementById(rowid
).className
) {
335 document
.getElementById(rowid
).className
= 'selected even-row';
338 document
.getElementById(rowid
).className
= 'selected odd-row';
340 case 'selected even-row' :
341 document
.getElementById(rowid
).className
= 'even-row';
343 case 'selected odd-row' :
344 document
.getElementById(rowid
).className
= 'odd-row';
347 document
.getElementById(rowid
).className
= 'selected';
350 document
.getElementById(rowid
).className
= 'form-item';
355 * This function is to show the row with selected checkbox in different color
356 * @param form - name of form that checkboxes are part of
361 function on_load_init_check(form
) {
362 for (i
= 0; i
< document
.forms
[form
].elements
.length
; i
++) {
363 if (( document
.forms
[form
].elements
[i
].type
== 'checkbox'
364 && document
.forms
[form
].elements
[i
].checked
== true )
365 || ( document
.forms
[form
].elements
[i
].type
== 'hidden'
366 && document
.forms
[form
].elements
[i
].value
== 1 )) {
367 var ss
= document
.forms
[form
].elements
[i
].id
;
368 var row
= 'rowid' + ss
;
369 changeRowColor(row
, form
);
375 * reset all the radio buttons with a given name
377 * @param string fieldName
381 function unselectRadio(fieldName
, form
) {
382 for (i
= 0; i
< document
.forms
[form
].elements
.length
; i
++) {
383 if (document
.forms
[form
].elements
[i
].name
== fieldName
) {
384 document
.forms
[form
].elements
[i
].checked
= false;
391 * Function to change button text and disable one it is clicked
393 * @param obj object - the button clicked
394 * @param formID string - the id of the form being submitted
395 * @param string procText - button text after user clicks it
401 * Changes button label on submit, and disables button after submit for newer browsers.
402 * Puts up alert for older browsers.
403 * @todo CRM-13397 replaces this with an alternate (jquery) mechanism - to use the jquery mechanism add
404 * parent::buildQuickForm to make buttons 'protected'
406 function submitOnce(obj
, formId
, procText
) {
407 // if named button clicked, change text
408 if (obj
.value
!= null) {
409 obj
.value
= procText
+ " ...";
411 if (document
.getElementById
) { // disable submit button for newer browsers
413 document
.getElementById(formId
).submit();
416 else { // for older browsers
417 if (submitcount
== 0) {
422 alert("Your request is currently being processed ... Please wait.");
428 function popUp(URL
) {
431 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');");
435 * Function to show / hide the row in optionFields
437 * @param element name index, that whose innerHTML is to hide else will show the hidden row.
439 function showHideRow(index
) {
441 cj('tr#optionField_' + index
).hide();
442 if (cj('table#optionField tr:hidden:first').length
) {
443 cj('div#optionFieldLink').show();
447 cj('table#optionField tr:hidden:first').show();
448 if (!cj('table#optionField tr:hidden:last').length
) {
449 cj('div#optionFieldLink').hide();
456 * Function to check activity status in relavent to activity date
458 * @param element message JSON object.
460 function activityStatus(message
) {
461 var d
= new Date(), time
= [], i
;
462 var currentDateTime
= d
.getTime()
463 var activityTime
= cj("input#activity_date_time_time").val().replace(":", "");
465 //chunk the time in bunch of 2 (hours,minutes,ampm)
466 for (i
= 0; i
< activityTime
.length
; i
+= 2) {
467 time
.push(activityTime
.slice(i
, i
+ 2));
469 var activityDate
= new Date(cj("input#activity_date_time_hidden").val());
471 d
.setFullYear(activityDate
.getFullYear());
472 d
.setMonth(activityDate
.getMonth());
473 d
.setDate(activityDate
.getDate());
474 var hours
= time
['0'];
475 var ampm
= time
['2'];
477 if (ampm
== "PM" && hours
!= 0 && hours
!= 12) {
478 // force arithmetic instead of string concatenation
479 hours
= hours
* 1 + 12;
482 if (ampm
== "AM" && hours
== 12) {
487 d
.setMinutes(time
['1']);
489 var activity_date_time
= d
.getTime();
491 var activityStatusId
= cj('#status_id').val();
493 if (activityStatusId
== 2 && currentDateTime
< activity_date_time
) {
494 if (!confirm(message
.completed
)) {
499 if (activity_date_time
&& activityStatusId
== 1 && currentDateTime
>= activity_date_time
) {
500 if (!confirm(message
.scheduled
)) {
507 CRM
.strings
= CRM
.strings
|| {};
508 CRM
.validate
= CRM
.validate
|| {
513 (function ($, undefined) {
515 $(document
).ready(function () {
517 $('.crm-container table.row-highlight').on('change', 'input.select-row, input.select-rows', function () {
518 var target
, table
= $(this).closest('table');
519 if ($(this).hasClass('select-rows')) {
520 target
= $('tbody tr', table
);
521 $('input.select-row', table
).prop('checked', $(this).prop('checked'));
524 target
= $(this).closest('tr');
525 $('input.select-rows', table
).prop('checked', $(".select-row:not(':checked')", table
).length
< 1);
527 target
.toggleClass('crm-row-selected', $(this).is(':checked'));
529 $('#crm-container').live('click', function (event
) {
530 if ($(event
.target
).is('.btn-slide')) {
531 var currentActive
= $('#crm-container .btn-slide-active');
532 currentActive
.children().hide();
533 currentActive
.removeClass('btn-slide-active');
534 $(event
.target
).children().show();
535 $(event
.target
).addClass('btn-slide-active');
538 $('.btn-slide .panel').hide();
539 $('.btn-slide-active').removeClass('btn-slide-active');
545 * Function to make multiselect boxes behave as fields in small screens
547 function advmultiselectResize() {
548 var amswidth
= $("#crm-container form:has(table.advmultiselect)").width();
549 if (amswidth
< 700) {
550 $("form table.advmultiselect td").css('display', 'block');
553 $("form table.advmultiselect td").css('display', 'table-cell');
555 var contactwidth
= $('#crm-container #mainTabContainer').width();
556 if (contactwidth
< 600) {
557 $('#crm-container #mainTabContainer').addClass('narrowpage');
558 $('#crm-container #mainTabContainer.narrowpage #contactTopBar td').each(function (index
) {
560 if (index
% 2 == 0) {
561 $(this).parent().after('<tr class="narrowadded"></tr>');
564 $(this).parent().next().append(item
);
569 $('#crm-container #mainTabContainer.narrowpage').removeClass('narrowpage');
570 $('#crm-container #mainTabContainer #contactTopBar tr.narrowadded td').each(function () {
572 var parent
= $(this).parent();
573 $(this).parent().prev().append(nitem
);
574 if (parent
.children().size() == 0) {
578 $('#crm-container #mainTabContainer.narrowpage #contactTopBar tr.added').detach();
580 var cformwidth
= $('#crm-container #Contact .contact_basic_information-section').width();
582 if (cformwidth
< 720) {
583 $('#crm-container .contact_basic_information-section').addClass('narrowform');
584 $('#crm-container .contact_basic_information-section table.form-layout-compressed td .helpicon').parent().addClass('hashelpicon');
585 if (cformwidth
< 480) {
586 $('#crm-container .contact_basic_information-section').addClass('xnarrowform');
589 $('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform');
593 $('#crm-container .contact_basic_information-section.narrowform').removeClass('narrowform');
594 $('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform');
598 advmultiselectResize();
599 $(window
).resize(function () {
600 advmultiselectResize();
603 $.fn
.crmtooltip = function () {
605 .on('mouseover', 'a.crm-summary-link:not(.crm-processed)', function (e
) {
606 $(this).addClass('crm-processed');
607 $(this).addClass('crm-tooltip-active');
608 var topDistance
= e
.pageY
- $(window
).scrollTop();
609 if (topDistance
< 300 | topDistance
< $(this).children('.crm-tooltip-wrapper').height()) {
610 $(this).addClass('crm-tooltip-down');
612 if (!$(this).children('.crm-tooltip-wrapper').length
) {
613 $(this).append('<div class="crm-tooltip-wrapper"><div class="crm-tooltip"></div></div>');
614 $(this).children().children('.crm-tooltip')
615 .html('<div class="crm-loading-element"></div>')
619 .on('mouseout', 'a.crm-summary-link', function () {
620 $(this).removeClass('crm-processed');
621 $(this).removeClass('crm-tooltip-active crm-tooltip-down');
623 .on('click', 'a.crm-summary-link', false);
627 CRM
.help = function (title
, params
, url
) {
628 h
&& h
.close
&& h
.close();
632 h
= CRM
.alert('...', title
, 'crm-help crm-msg-loading', options
);
633 params
.class_name
= 'CRM_Core_Page_Inline_Help';
634 params
.type
= 'page';
635 $.ajax(url
|| CRM
.url('civicrm/ajax/inline'),
639 success: function (data
) {
640 $('#crm-notification-container .crm-help .notify-content:last').html(data
);
641 $('#crm-notification-container .crm-help').removeClass('crm-msg-loading').addClass('info');
644 $('#crm-notification-container .crm-help .notify-content:last').html('Unable to load help file.');
645 $('#crm-notification-container .crm-help').removeClass('crm-msg-loading').addClass('error');
652 * @param string text Displayable message
653 * @param string title Displayable title
654 * @param string type 'alert'|'info'|'success'|'error' (default: 'alert')
655 * @param {object} options
657 * @see http://wiki.civicrm.org/confluence/display/CRM/Notifications+in+CiviCRM
659 CRM
.alert = function (text
, title
, type
, options
) {
660 type
= type
|| 'alert';
662 options
= options
|| {};
663 if ($('#crm-notification-container').length
) {
669 // By default, don't expire errors and messages containing links
671 expires
: (type
== 'error' || text
.indexOf('<a ') > -1) ? 0 : (text
? 10000 : 5000),
674 options
= $.extend(extra
, options
);
675 options
.expires
= options
.expires
=== false ? 0 : parseInt(options
.expires
, 10);
676 if (options
.unique
&& options
.unique
!== '0') {
677 $('#crm-notification-container .ui-notify-message').each(function () {
678 if (title
=== $('h1', this).html() && text
=== $('.notify-content', this).html()) {
679 $('.icon.ui-notify-close', this).click();
683 return $('#crm-notification-container').notify('create', params
, options
);
687 text
= title
+ "\n" + text
;
695 * Close whichever alert contains the given node
699 CRM
.closeAlertByChild = function (node
) {
700 $(node
).closest('.ui-notify-message').find('.icon.ui-notify-close').click();
704 * Prompt the user for confirmation.
706 * @param buttons {object|function} key|value pairs where key == button label and value == callback function
707 * passing in a function instead of an object is a shortcut for a sinlgle button labeled "Continue"
708 * @param options {object|void} Override defaults, keys include 'title', 'message',
709 * see jQuery.dialog for full list of available params
711 CRM
.confirm = function (buttons
, options
, cancelLabel
) {
712 var dialog
, callbacks
= {};
713 cancelLabel
= cancelLabel
|| ts('Cancel');
715 title
: ts('Confirm Action'),
716 message
: ts('Are you sure you want to continue?'),
726 settings
.buttons
[cancelLabel
] = function () {
727 dialog
.dialog('close');
729 options
= options
|| {};
730 $.extend(settings
, options
);
731 if (typeof(buttons
) === 'function') {
732 callbacks
[ts('Continue')] = buttons
;
737 $.each(callbacks
, function (label
, callback
) {
738 settings
.buttons
[label
] = function () {
739 callback
.call(dialog
);
740 dialog
.dialog('close');
743 dialog
= $('<div class="crm-container crm-confirm-dialog"></div>')
744 .html(options
.message
)
751 * Sets an error message
752 * If called for a form item, title and removal condition will be handled automatically
754 $.fn
.crmError = function (text
, title
, options
) {
757 options
= options
|| {};
762 if ($(this).length
) {
764 var label
= $('label[for="' + $(this).attr('name') + '"], label[for="' + $(this).attr('id') + '"]').not('[generated=true]');
766 label
.addClass('crm-error');
767 var $label
= label
.clone();
768 if (text
== '' && $('.crm-marker', $label
).length
> 0) {
769 text
= $('.crm-marker', $label
).attr('title');
771 $('.crm-marker', $label
).remove();
772 title
= $label
.text();
775 $(this).addClass('error');
777 var msg
= CRM
.alert(text
, title
, 'error', $.extend(extra
, options
));
778 if ($(this).length
) {
780 setTimeout(function () {
781 ele
.one('change', function () {
782 msg
&& msg
.close
&& msg
.close();
783 ele
.removeClass('error');
784 label
.removeClass('crm-error');
791 // Display system alerts through js notifications
792 function messagesFromMarkup() {
793 $('div.messages:visible', this).not('.help').not('.no-popup').each(function () {
794 var text
, title
= '';
795 $(this).removeClass('status messages');
796 var type
= $(this).attr('class').split(' ')[0] || 'alert';
797 type
= type
.replace('crm-', '');
798 $('.icon', this).remove();
799 if ($('.msg-text', this).length
> 0) {
800 text
= $('.msg-text', this).html();
801 title
= $('.msg-title', this).html();
804 text
= $(this).html();
806 var options
= $(this).data('options') || {};
808 // Duplicates were already removed server-side
809 options
.unique
= false;
810 CRM
.alert(text
, title
, type
, options
);
812 // Handle qf form errors
813 $('form :input.error', this).one('blur', function() {
814 // ignore autocomplete fields
815 if ($(this).is('.ac_input')) {
819 $('.ui-notify-message.error a.ui-notify-close').click();
820 $(this).removeClass('error');
821 $(this).next('span.crm-error').remove();
822 $('label[for="' + $(this).attr('name') + '"], label[for="' + $(this).attr('id') + '"]')
823 .removeClass('crm-error')
824 .find('.crm-error').removeClass('crm-error');
829 if ($('#crm-notification-container').length
) {
830 // Initialize notifications
831 $('#crm-notification-container').notify();
832 messagesFromMarkup
.call($('#crm-container'));
833 $('#crm-container').on('crmFormLoad', '*', messagesFromMarkup
);
836 // bind the event for image popup
837 $('body').on('click', 'a.crm-image-popup', function() {
838 var o
= $('<div class="crm-container crm-custom-image-popup"><img src=' + $(this).attr('href') + '></div>');
842 title
: ts('Preview'),
851 $.fn
.crmAccordions = function (speed
) {
852 var container
= $('#crm-container');
853 if (speed
=== undefined) {
856 if ($(this).length
> 0) {
859 if (container
.length
> 0 && !container
.hasClass('crm-accordion-processed')) {
860 // Allow normal clicking of links
861 container
.on('click', 'div.crm-accordion-header a', function (e
) {
862 e
.stopPropagation
&& e
.stopPropagation();
864 container
.on('click', '.crm-accordion-header, .crm-collapsible .collapsible-title', function () {
865 if ($(this).parent().hasClass('collapsed')) {
866 $(this).next().css('display', 'none').slideDown(speed
);
869 $(this).next().css('display', 'block').slideUp(speed
);
871 $(this).parent().toggleClass('collapsed');
874 container
.addClass('crm-accordion-processed');
877 $.fn
.crmAccordionToggle = function (speed
) {
878 $(this).each(function () {
879 if ($(this).hasClass('collapsed')) {
880 $('.crm-accordion-body', this).first().css('display', 'none').slideDown(speed
);
883 $('.crm-accordion-body', this).first().css('display', 'block').slideUp(speed
);
885 $(this).toggleClass('collapsed');
890 * Clientside currency formatting
895 var currencyTemplate
;
896 CRM
.formatMoney = function(value
, format
) {
897 var decimal, separator
, sign
, i
, j
, result
;
898 if (value
=== 'init' && format
) {
899 currencyTemplate
= format
;
902 format
= format
|| currencyTemplate
;
903 result
= /1(.?)234(.?)56/.exec(format
);
904 if (result
=== null) {
905 return 'Invalid format passed to CRM.formatMoney';
907 separator
= result
[1];
909 sign
= (value
< 0) ? '-' : '';
910 //extracting the absolute value of the integer part of the number and converting to string
911 i
= parseInt(value
= Math
.abs(value
).toFixed(2)) + '';
913 j
= ((j
= i
.length
) > 3) ? j
% 3 : 0;
914 result
= sign
+ (j
? i
.substr(0, j
) + separator
: '') + i
.substr(j
).replace(/(\d{3})(?=\d)/g, "$1" + separator
) + (2 ? decimal + Math
.abs(value
- i
).toFixed(2).slice(2) : '');
915 return format
.replace(/1.*234.*56/, result
);