// Licensed Materials - Property of IBM // // IBM Cognos Products: cogadmin // // (C) Copyright IBM Corp. 2005, 2015 // // 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). //---------------------------------------------------------- /* * namespace for cogadmin local javascript library. */ if (!window.CognosObjectFactory) { window.CognosObjectFactory = function() { throw 'RuntimeException: CognosObjectFactory is a static class and may not be instantiated'; } CognosObjectFactory.init = function(objName) { var namespace = objName.split("."); var obj=window; for (var i=0; i < namespace.length;i++) { if (!obj[namespace[i]]) { obj = obj[namespace[i]] = {}; } else { obj = obj[namespace[i]]; if (typeof(obj) != "object") throw new Error(objName + " already exists and is not an object"); } } return obj; } } //returns either val or the result of evaluating val function evalParm(val) { var ret = window[val]; return ret ? ret : val; } // table actions: expand/collapse, select row, ... function toggleGroupVisibility(imgID, rowID) { var row = document.getElementById(rowID); if (!row) { return; } var sibling = getNextSibling(row); var collapsing = true; // get all the siblings until we hit the next group TR while (sibling.id == '') { if (sibling.style.display == '') { sibling.style.display = 'none'; collapsing = false; } else { sibling.style.display = ''; } sibling = getNextSibling(sibling); if (!sibling) { break; } } // change the image var image = document.getElementById(imgID); if (!image) { return; } if (collapsing) { image.src = image.src.substring(0, image.src.indexOf('expand.gif')) + 'collapse.gif'; } else { image.src = image.src.substring(0, image.src.indexOf('collapse.gif')) + 'expand.gif'; } } //getNextSibling // We need to do this to workaround a firefox issue since firefox treats // linebreaks as nodes. function getNextSibling(startNode){ endNode=startNode.nextSibling; while(endNode.nodeType!=1){ endNode = endNode.nextSibling; } return endNode; } // selectTableRow // @rowPrefix: the ID prefix used to loop through all the selectable rows in the // table // @rowID: the ID for the row that will get selected // @skipColumns: the number of columns that should get skipped when selecting a // row function selectTableRow(rowPrefix, rowID, skipColumns) { var row = document.getElementById(rowID); if (!row) { return; } // get the parent of the TR var parent = row.parentNode; if (!parent) { return; } // need to clear all the other selections and select only the one row for (rowIndex=0; rowIndex < parent.childNodes.length; rowIndex++) { var row = parent.childNodes[rowIndex]; // we found a selectable row if (row.nodeName == 'TR' && row.id.indexOf(rowPrefix) == 0) { var skippedCols = 0; // loop through the TD's of the TR for (colIndex=0; colIndex < row.childNodes.length; colIndex++) { var col = row.childNodes[colIndex]; if (col.nodeName == 'TD') { // is this the row that should be selected? if (row.id == rowID) { if (skippedCols >= skipColumns) { col.style.background = '#DEE7EF'; } else { skippedCols++; } } else { // TODO; this doesn't work in firefox // TODO: fix alternating backgrouns // if (rowIndex%2) { // col.style.background = '#f3f3f3'; // } // else { col.style.background = '#ffffff'; // } } } } } } } // @fragID: The ID for the fragment that will get created // @divID: The ID of the div that will get updated by the fragment // @xtsTargetURL: parameters that will get added to the URL. Should NOT start // with & function createFragment(fragID, divID, xtsTargetURL) { var frag = new fragment("/xts"+encodeURI(xtsTargetURL), fragID, divID); if (frag.parent && !document.getElementById(divID)) { var div = document.createElement('div'); div.id = divID; document.getElementById(frag.parent.div).appendChild(div); } return frag; } // @id; div id for the modal dialog content function showModalDialog(style, id, title, height, width,fragment) { if (id) { var div = document.getElementById(id); if (div) { div.style.display=""; if (!width) { width=xWidth(div); } if (!height) { height=xHeight(div); } var left = ((document.body.clientWidth - width) / 2); if (left < 0) { left = document.body.scrollLeft; } var top = ((document.body.clientHeight - height) / 2); if (top < 0) { top = document.body.scrollTop; } var uiDialog = new ui_dialog(id, title, style, left, top, width, height); if (fragment) { uiDialog.fragment = fragment; } uiDialog.setContent(div.innerHTML); div.parentNode.removeChild(div); uiDialog.show(); return uiDialog; } } } // @id; div id for the modal dialog // @iframeId: iframe id function showModalDialogWithIFrame(id, height, width) { showModalDialogWithIFrame.triggerElement = document.activeElement; var div = $(id); if (div) { div.style.display = ""; var locker = ui_locker.get(); locker.show(); if (height) { div.style.height = height + 'px'; } if (width) { div.style.width = width + 'px'; } var left = ((document.body.clientWidth - div.clientWidth) / 2) + document.body.scrollLeft - 170; if (left < 0) { left = document.body.scrollLeft; } div.style.left = left + 'px'; var top = ((document.body.clientHeight - div.clientHeight) / 2) + document.body.scrollTop - 45; if (top < 0) { top = document.body.scrollTop; } div.style.top = top + 'px'; div.style.visibility = 'visible'; ui_setFocus(div); } } function hideModalDialog(id) { div = document.getElementById(id); if (div) { div.style.display = 'none'; } var locker = ui_locker.get(); while (locker.count > 0){ locker.hide(); locker = ui_locker.get(); } setTimeout(function(){var triggerEle=showModalDialogWithIFrame.triggerElement;if(triggerEle){triggerEle.focus()}},500); } // @event - the event that has taken place (mouseclick, mouseover, ...) function cancelBubble(event) { event.cancelBubble = true; if (event.stopPropagation) { event.stopPropagation(); } } //highlight row function toggleHighlight(fragmentName, object, alternate){ cleanWhitespace(fragmentName + "tbodyElement"); var group = document.getElementById(fragmentName + "tbodyElement"); if (group.hasChildNodes()) { var children = group.childNodes; for (var i = 0; children.length > i; i++) { if (children[i].id != fragmentName + "footer") { if (alternate == true) { if (i%2 == 0) { children[i].className = "cogstyle-table-row-alternate"; } else { children[i].className = "cogstyle-table-row-default"; } } else { children[i].className = "cogstyle-table-row-default"; } } } object.className = "cogstyle-table-row-selected"; } } function cleanWhitespace (element) { var element = document.getElementById(element); for (var i = 0; i < element.childNodes.length; i++) { var node = element.childNodes[i]; if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) { node.parentNode.removeChild(node); } } } function toggleAllGroups(fragmentName) { var i=0; var toggle = null; var hasNext = true; while(hasNext) { var tg = new toggleGroup(fragmentName,i++,toggle); hasNext = tg.hasNext; toggle = tg.toggle; } } //expand/collapse group function toggleGroup(fragmentName, group_number, toggle){ var element = null; var display = false; var image=null; // get the next available group var next_available_group=0; for (var i=group_number; i < group_number+20; i++){ image = document.getElementById(fragmentName + "group_image_" + i); if (image) { break; } } next_available_group = i; if (image && group_number==next_available_group) { if ((toggle == 'expand') || (!toggle && image.src.indexOf("collapse.gif") >= 0)) { image.src = image.src.replace(/collapse/, "expand"); display = false if (!toggle) { toggle = 'expand'; } } else { image.src = image.src.replace(/expand/, "collapse"); display = true; if (!toggle) { toggle = 'collapse'; } } image.setAttribute("aria-expanded",toggle != 'expand') var summary = document.getElementById(fragmentName + "group_summary_" + group_number); if (summary != null) { summary.style.display=display ? 'none' : ''; } var i = 1; while (i == 1 || element) { element = document.getElementById(fragmentName + "group_" + group_number + "_" + (i++)); if (element) { element.style.display = display ? '' : 'none'; } } } this.hasNext = image != null; this.toggle = toggle; } //selects all the input checkboxes from a form function toggleCheckboxes(source_checkbox, parent_id) { var arrayCheckbox = getChildInputs(parent_id, 'checkbox'); for (var i=0; i= 0){ if (elements[i].checked == true) { var checkboxArray = new Array(); checkboxArray[0] = checkboxNumber; checkboxArray[1] = elements[i].id; checkboxArray[2] = elements[i].value; checkboxes[checkboxes.length++] = checkboxArray; } checkboxNumber++; } } } return checkboxes; } // returns a string with a key/value pair where the key is the id of the // checkbox function getCheckboxUrlParams(table_name) { return getCheckboxParams(table_name, false, null, true); } // returns a string with a key/value pair where the key name is checkbox_1, // checkbox_2... function getCheckboxCheckParams(table_name, valueFunc) { return getCheckboxParams(table_name, true, "checkbox", true, valueFunc); } //returns a string with a key/value pair (key=value) function getCheckboxParams(table_name, use_parameter_name, parameter_name, use_parameter_index, valueFunc) { var array = getCheckboxArray(table_name); var params = ""; var last = array.length - 1; for (var i=0; i 0) { params+=" or "; } var tenantId = decodeURIComponent(tenantIds[i]); params+="@tenantID='" + encodeURIComponent(tenantId.replace(/'/g,"''")) + "'"; } params+="]"; fragment.retrieve(params); } function doCreateContentUtilizationInfo(table_name, mPath, backURL) { var checkboxes = getCheckboxParams(table_name, true, "selectedTenants", false); createContentUtilizationInfoImpl(checkboxes, mPath, backURL); } function createContentUtilizationInfoImpl(checkboxes, mPath, backURL) { var urlParams = "?b_action=xts.run"; urlParams += "&m_path="; urlParams += mPath; urlParams += "&m=portal/new_general.xts"; urlParams += "&from_tool=true"; urlParams += "&m_class=contentTask"; urlParams += "&m_new_class=contentTask"; urlParams += "&backURL="; urlParams += backURL; urlParams += "&contentTaskType=createContentUtilizationInfo"; if (checkboxes) { urlParams += "&" + checkboxes; } ui_modal_dialog.open(urlParams, false, true, true); } function doActionCancelInteractive(fragment, tableName, arguments, isGroupAction) { var params = ''; if (arguments) { params = arguments; } if (isGroupAction) { var checkedPramsArray = getCheckboxArray(tableName); if (checkedPramsArray.length == 0) { alert(action_no_selection_msg); return; } for (var i=0; i // minHeight. Otherwise, use minHeight function setRelativeHeight(targetId, fragment, minHeight, offset) { var parent = fragment.parent; var iHeight = minHeight; while (parent) { if (parent.div) { var _height = parseInt($(parent.div).style.height); if (_height) { if (offset) { _height = (_height * offset.percentage) + offset.pixels; } if (_height > minHeight) { iHeight = _height; } break; } } parent = parent.parent; } var target = $(targetId); if (target) { $(targetId).style.height = iHeight + "px"; } } function floatMath (operand1,operand2,operator) { var f1 = getFixedDecimal(operand1); var f2 = getFixedDecimal(operand2); var fixedDecimal = ((f1 - f2)>0) ? f1 : f2; var result; switch (operator) { case '-': result = operand1 - operand2; break; case '*': result = operand1 * operand2; fixedDecimal = f1 + f2; break; default: result = operand1 + operand2; } return result.toFixed(fixedDecimal); function getFixedDecimal (number) { var pre = number.toString().indexOf("."); if (pre == -1) return 0; else return fixedDecimal = number.toString().length - 1 - pre; } } function getExpandedTableGroups(table) { var expandedGroupKeys = new Array(); var trs = table.getElementsByTagName('tr'); for (var tr in trs) { var row = trs[tr]; if (includeClass(row,"cogstyle-table-group")) { var img = row.getElementsByTagName("img")[0]; // the // expand/collapse // icon if (img.src.indexOf("collapse") >=0) { //the group is expanded expandedGroupKeys[expandedGroupKeys.length] = row .getAttribute("key"); } } } return expandedGroupKeys; } function generateQueryString(currentString, newName, newValue, ignoreEmptyValues) { if (!currentString) { currentString=""; } if (newName) { if (ignoreEmptyValues && (!newValue || newValue.length == 0)) { return currentString; } if (currentString.length > 0) { currentString+="&"; } return currentString+newName+"="+newValue; } return currentString; } function importUserInterfaceProfiles(parentFrag, msg) { if (confirm(msg)) { var fragUrl='/cogadmin/controls/importUserInterfaceProfiles.xts'; var frag = createFragment(parentFrag.id+'importUIProfiles', parentFrag.id+'importUIProfiles_div', fragUrl); frag.retrieve(); } }