// Licensed Materials - Property of IBM // // IBM Cognos Products: cpscrn // // (C) Copyright IBM Corp. 2005, 2018 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. // // // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated). function getPickerForm(formName) { var forms = document.getElementsByTagName("form"); var currentPicker = null; var i = 0; //while ((currentPicker == null) && (i < forms.length)) while ((i < forms.length)) { if (forms[i].name == formName){ currentPicker = forms[i]; } i++; } return currentPicker; } function recreatePickerForm(formName, action) { var forms = document.getElementsByTagName("form"); var currentPicker = getPickerForm(formName); if (currentPicker != null) { //remove all elements from the form just in case it was used previously currentPicker.parentNode.removeChild(currentPicker); } //recreate the picker form currentPicker = document.createElement("form"); currentPicker.name = formName; currentPicker.action = action; currentPicker.target = "UI_MODAL_DIALOG_IFRAME"; document.body.appendChild(currentPicker); } function createPickerInput(form, id, name, value) { var anInput = document.createElement('input'); anInput.setAttribute("type","hidden"); anInput.setAttribute("name",name); anInput.setAttribute("value",value); anInput.setAttribute("id",id); form.appendChild(anInput); } function isInRemoveLang(locale) { var inputs = document.getElementsByTagName("input"); var removeLangEl = null; var count = 0; while ((removeLangEl == null) && (count < inputs.length)) { var currEl = inputs[count]; if ((currEl.type == "hidden") && (currEl.name == 'removeLang')) { removeLangEl = currEl; } count++; } return (removeLangEl.value.indexOf(locale) != -1) } function getMultiLingualElements(pickParamName, propertyName, form, selector, control) { var currentLocale = selector.options[selector.selectedIndex].value; var inputs = document.getElementsByTagName("input"); var langValueIndex = 1; for (var ind = 0; ind < inputs.length; ind++) { if (inputs[ind].type == "hidden") { if (inputs[ind].name.indexOf(propertyName + "-") == 0) { var indexOfLocale = (propertyName + "-").length; var locale = inputs[ind].name.substr(indexOfLocale); if (!isInRemoveLang(locale)) { if (locale == currentLocale) { inputs[ind].value = control.value; } createPickerInput(form, pickParamName + "-" + locale, pickParamName + "-" + locale, inputs[ind].value); langValueIndex++; } } } } return (langValueIndex > 1); } function getRadiobuttonSelectElements(pickParamName, propertyName, form) { var radiobuttons = document.getElementsByTagName("input"); var radioIndex = 1; var checkedRadioButton = null; var count = 0; while ((checkedRadioButton == null) && (count < radiobuttons.length) ) { var currentEl = radiobuttons[count]; if ((currentEl.type == 'radio') && (currentEl.name == ("p_" + propertyName)) && (currentEl.checked) ) { checkedRadioButton = currentEl; } count++; } if (checkedRadioButton == null) { return false; } else { createPickerInput(form, pickParamName + "_" + radiobuttons, pickParamName, checkedRadioButton.value); return true; } } function getCheckboxSelectElements(pickParamName, propertyName, form) { var checkboxes = document.getElementsByTagName("input"); var checkIndex = 1; for (var ind = 0; ind < checkboxes.length; ind++) { if (checkboxes[ind].type == "checkbox") { if (checkboxes[ind].name.indexOf("p_" + propertyName + "_option") == 0) { if (checkboxes[ind].checked) { createPickerInput(form, pickParamName + "_" + checkIndex, pickParamName + "_" + checkIndex, checkboxes[ind].value); checkIndex++; } } } } return (checkIndex > 1); } function getOptionSelectElements(pickParamName, propertyName, form) { var selections = document.getElementsByTagName("select"); var optionIndex = 1; for (var ind = 0; ind < selections.length; ind++) { if (selections[ind].name == ("p_" + propertyName)) { var theOptions = selections[ind].options; for (var optind=0;optind < theOptions.length;optind++) { if (theOptions[optind].selected) { //if it is a select-one list then treat the result as a //simple element otherwise assume that you will be creating multiple inputs for this //for this property if (selections[ind].type == "select-one") { createPickerInput(form, pickParamName, pickParamName, theOptions[optind].value); } else { createPickerInput(form, pickParamName + "_" + optionIndex, pickParamName + "_" + optionIndex, theOptions[optind].value); } optionIndex++; } } } } return (optionIndex > 1); } function getSelectElements(pickParamName, propertyName, form) { //first see if we have a bunch of check boxes if (getCheckboxSelectElements(pickParamName, propertyName, form)) { return true; } //next see if we have a bunch of option tags if (getOptionSelectElements(pickParamName, propertyName, form)) { return true; } return false; } function getSelect1Elements(pickParamName, propertyName, form) { //first see if we have a bunch of check boxes if (getRadiobuttonSelectElements(pickParamName, propertyName, form)) { return true; } //next see if we have a bunch of option tags if (getOptionSelectElements(pickParamName, propertyName, form)) { return true; } return false; } function getValueFromSimpleElement(element) { if ((element.type == "text") || (element.type == "textarea")) { return element.value; } if ((element.type == "radio") || (element.type == "checkbox")) { return element.checked; } if (element.type == "hidden") { return element.value; } } //****xml functions function XMLBuilderLoadXMLFromString(markup) { var xmlDocument = null; // Try to activeX first. In IE10, if we use the DOMParser, the selectSingleNode will not longer work and IE still does not support the xpath evaluate method try { // If we do not hit an exception while creating ActiveXObject object, it means that we use Internet Explorer browser xmlDocument = new ActiveXObject('Microsoft.XMLDOM'); xmlDocument.loadXML(markup); } catch (e) { // If we get in here, it means that we use other then Internet Explorer browser if (typeof DOMParser != 'undefined') { xmlDocument = new DOMParser().parseFromString(markup, 'application/xml'); } } return xmlDocument; } function xmldecode(text) { var amp_re = /&/g; var lt_re = /</g; var gt_re = />/g; var apos_re = /'/g; // Decode stuff which has been encoded/escaped out. // ORDER IS IMPORTANT - amp_re must be the last value to replace! text = text.replace(lt_re, "<"); text = text.replace(gt_re, ">"); text = text.replace(apos_re, "'"); text = text.replace(amp_re, "&"); return text; }