X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2FCommon.js;h=8f5294ef60db3c13e12c62db59dc18e291cfe68b;hb=27e0bdba223bf18398c1229f3994fa77fc58f66e;hp=bf4273c74e0c1af82131c6b2ae151f0378416a92;hpb=fb4aea019afef361e7673ebac69d5d5a74144a96;p=civicrm-core.git diff --git a/js/Common.js b/js/Common.js index bf4273c74e..8f5294ef60 100644 --- a/js/Common.js +++ b/js/Common.js @@ -22,7 +22,7 @@ | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ -*/ + */ /** * @file: global functions for CiviCRM @@ -44,10 +44,12 @@ var cj = jQuery; function ts(text, params) { "use strict"; text = CRM.strings[text] || text; - if (params && typeof(params) === 'object') { + if (typeof(params) === 'object') { for (var i in params) { - // sprintf emulation: escape % characters in the replacements to avoid conflicts - text = text.replace(new RegExp('%'+i, 'g'), params[i].replace(/%/g, '%-crmescaped-')); + if (typeof(params[i]) === 'string' || typeof(params[i]) === 'number') { + // sprintf emulation: escape % characters in the replacements to avoid conflicts + text = text.replace(new RegExp('%' + i, 'g'), String(params[i]).replace(/%/g, '%-crmescaped-')); + } } return text.replace(/%-crmescaped-/g, '%'); } @@ -66,33 +68,34 @@ function ts(text, params) { * @param elementType Value to set display style to for showBlocks (e.g. 'block' or 'table-row' or ...) * @return none */ -function on_load_init_blocks(showBlocks, hideBlocks, elementType) -{ - if ( elementType == null ) { - var elementType = 'block'; - } - - /* This loop is used to display the blocks whose IDs are present within the showBlocks array */ - for ( var i = 0; i < showBlocks.length; i++ ) { - var myElement = document.getElementById(showBlocks[i]); - /* getElementById returns null if element id doesn't exist in the document */ - if (myElement != null) { - myElement.style.display = elementType; - } else { - alert('showBlocks array item not in .tpl = ' + showBlocks[i]); - } +function on_load_init_blocks(showBlocks, hideBlocks, elementType) { + if (elementType == null) { + var elementType = 'block'; + } + + /* This loop is used to display the blocks whose IDs are present within the showBlocks array */ + for (var i = 0; i < showBlocks.length; i++) { + var myElement = document.getElementById(showBlocks[i]); + /* getElementById returns null if element id doesn't exist in the document */ + if (myElement != null) { + myElement.style.display = elementType; + } + else { + alert('showBlocks array item not in .tpl = ' + showBlocks[i]); } + } - /* This loop is used to hide the blocks whose IDs are present within the hideBlocks array */ - for ( var i = 0; i < hideBlocks.length; i++ ) { - var myElement = document.getElementById(hideBlocks[i]); - /* getElementById returns null if element id doesn't exist in the document */ - if (myElement != null) { - myElement.style.display = 'none'; - } else { - alert('showBlocks array item not in .tpl = ' + hideBlocks[i]); - } + /* This loop is used to hide the blocks whose IDs are present within the hideBlocks array */ + for (var i = 0; i < hideBlocks.length; i++) { + var myElement = document.getElementById(hideBlocks[i]); + /* getElementById returns null if element id doesn't exist in the document */ + if (myElement != null) { + myElement.style.display = 'none'; + } + else { + alert('showBlocks array item not in .tpl = ' + hideBlocks[i]); } + } } /** @@ -107,54 +110,65 @@ function on_load_init_blocks(showBlocks, hideBlocks, elementType) * @param field_type Type of element radio/select * @param invert Boolean - if true, we HIDE target on value match; if false, we SHOW target on value match * @return none -*/ -function showHideByValue(trigger_field_id, trigger_value, target_element_id, target_element_type, field_type, invert ) { - if ( target_element_type == null ) { - var target_element_type = 'block'; - } else if ( target_element_type == 'table-row' ) { - var target_element_type = ''; - } - - if (field_type == 'select') { - var trigger = trigger_value.split("|"); - var selectedOptionValue = document.getElementById(trigger_field_id).options[document.getElementById(trigger_field_id).selectedIndex].value; - - var target = target_element_id.split("|"); - for(var j = 0; j < target.length; j++) { - if ( invert ) { - cj('#' + target[j]).show(); - } else { - cj('#' + target[j]).hide(); - } - for(var i = 0; i < trigger.length; i++) { - if (selectedOptionValue == trigger[i]) { - if ( invert ) { - cj('#' + target[j]).hide(); - } else { - cj('#' + target[j]).show(); - } - } - } + */ +function showHideByValue(trigger_field_id, trigger_value, target_element_id, target_element_type, field_type, invert) { + if (target_element_type == null) { + var target_element_type = 'block'; + } + else { + if (target_element_type == 'table-row') { + var target_element_type = ''; + } + } + + if (field_type == 'select') { + var trigger = trigger_value.split("|"); + var selectedOptionValue = document.getElementById(trigger_field_id).options[document.getElementById(trigger_field_id).selectedIndex].value; + + var target = target_element_id.split("|"); + for (var j = 0; j < target.length; j++) { + if (invert) { + cj('#' + target[j]).show(); + } + else { + cj('#' + target[j]).hide(); + } + for (var i = 0; i < trigger.length; i++) { + if (selectedOptionValue == trigger[i]) { + if (invert) { + cj('#' + target[j]).hide(); + } + else { + cj('#' + target[j]).show(); + } } + } + } - } else if (field_type == 'radio') { - var target = target_element_id.split("|"); - for(var j = 0; j < target.length; j++) { - if (document.getElementsByName(trigger_field_id)[0].checked) { - if ( invert ) { - cj('#' + target[j]).hide(); - } else { - cj('#' + target[j]).show(); - } - } else { - if ( invert ) { - cj('#' + target[j]).show(); - } else { - cj('#' + target[j]).hide(); - } - } + } + else { + if (field_type == 'radio') { + var target = target_element_id.split("|"); + for (var j = 0; j < target.length; j++) { + if (document.getElementsByName(trigger_field_id)[0].checked) { + if (invert) { + cj('#' + target[j]).hide(); + } + else { + cj('#' + target[j]).show(); + } } + else { + if (invert) { + cj('#' + target[j]).show(); + } + else { + cj('#' + target[j]).hide(); + } + } + } } + } } /** @@ -170,49 +184,51 @@ function showHideByValue(trigger_field_id, trigger_value, target_element_id, tar * @return */ function toggleCheckboxVals(fldPrefix, object) { - if ( object.id == 'toggleSelect' && cj(object).is(':checked') ) { - cj( 'Input[id*="' + fldPrefix + '"],Input[id*="toggleSelect"]').attr('checked', true); - } else { - cj( 'Input[id*="' + fldPrefix + '"],Input[id*="toggleSelect"]').attr('checked', false); - } - // change the class of selected rows - on_load_init_checkboxes(object.form.name); + if (object.id == 'toggleSelect' && cj(object).is(':checked')) { + cj('Input[id*="' + fldPrefix + '"],Input[id*="toggleSelect"]').attr('checked', true); + } + else { + cj('Input[id*="' + fldPrefix + '"],Input[id*="toggleSelect"]').attr('checked', false); + } + // change the class of selected rows + on_load_init_checkboxes(object.form.name); } function countSelectedCheckboxes(fldPrefix, form) { - fieldCount = 0; - for( i=0; i < form.elements.length; i++) { - fpLen = fldPrefix.length; - if (form.elements[i].type == 'checkbox' && form.elements[i].name.slice(0,fpLen) == fldPrefix && form.elements[i].checked == true) { - fieldCount++; - } + fieldCount = 0; + for (i = 0; i < form.elements.length; i++) { + fpLen = fldPrefix.length; + if (form.elements[i].type == 'checkbox' && form.elements[i].name.slice(0, fpLen) == fldPrefix && form.elements[i].checked == true) { + fieldCount++; } - return fieldCount; + } + return fieldCount; } /** * Function to enable task action select */ -function toggleTaskAction( status ) { - var radio_ts = document.getElementsByName('radio_ts'); - if (!radio_ts[1]) { - radio_ts[0].checked = true; - } - if ( radio_ts[0].checked || radio_ts[1].checked ) { - status = true; - } - - var formElements = ['task', 'Go', 'Print']; - for(var i=0; i