/******************************************************************************************************************************** * Licensed Materials - Property of IBM * * * * IBM Cognos Products: AGS * * * * (C) Copyright IBM Corp. 2005, 2010 * * * * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * *********************************************************************************************************************************/ //grab all tags from this or subordinate frames FormUtils.prototype.getElementsFromFrameByTagName = function(aFrame, tag){ if(!aFrame.document){ return new Array(); } // find the elements var theTags = getArray(aFrame.document.getElementsByTagName(tag)); // check all the subframes for (var i = 0; i < aFrame.frames.length; ++i) { theTags = theTags.concat(getArray(this.getElementsFromFrameByTagName(aFrame.frames[i], tag))); } return theTags; } //domII implementation returns non Array collections function getArray(aCollection){ var anArray = new Array(); for(var i = 0; i < aCollection.length; i++){ anArray.push(aCollection[i]); } return anArray; } FormUtils.prototype.setVisibilityOnElementsFromFrameByTagName = function(aFrame, tag, bVis){ var selects = agsFormUtils.getElementsFromFrameByTagName(aFrame, tag); for(var i = 0; i < selects.length; i++){ if(!selects[i] || !selects[i].offsetParent){ continue; } selects[i].style.visibility=bVis ? "visible" : "hidden"; } } // handy form manipulation util //usefull function i nicked from ddh... and enhanced? FormUtils.prototype.getElementByIdOrName = function(id){ return this.getElementFromFrame(window, id); } //usefull function i nicked and made recursive FormUtils.prototype.getElementFromFrame = function(aFrame, id){ // find the element ang register all the handlers that we need var srcElem = aFrame.document.getElementById(id); if (srcElem == null) { // try finding it by name var elementNames = aFrame.document.getElementsByName(id); if (elementNames != null && elementNames.length == 1) { srcElem = elementNames[0]; } } if (srcElem == null) { // check all the subframes for (var i = 0; i < aFrame.frames.length && srcElem == null; ++i) { srcElem = this.getElementFromFrame(aFrame.frames[i], id); } } return srcElem; } //retrieve a single frame FormUtils.prototype.getFrame = function(startFrame, targetFrameId){ if(startFrame.name = targetFrameId){ return startFrame; } var foundFrame; // check all the subframes for (var i = 0; i < startFrame.frames.length && !foundFrame; ++i) { foundFrame = this.getFrame(startFrame.frames[i], targetFrameId); } return foundFrame; } /* * Get the event source in a browser agnostic way */ FormUtils.prototype.getEventId = function(event) { var id = null; var srcElem = (cf.browserCheck.isIE5Up() ? event.srcElement : event.currentTarget); while (id == null) { id = srcElem.id; if (id == null || id.length == 0) { id = srcElem.name; } if (id != null && id.length == 0) { id = null; } if (id == null) { srcElem = srcElem.parentNode; } } return id; } function FormUtils(){ } var agsFormUtils = new FormUtils(); // ----------------------------------------------------------------------------- // // --- Data utilities functions --- // // ----------------------------------------------------------------------------- function isNumeric(idx) { return (getDataType(idx) == 0); } function isOldTypeNumeric(idx) { if (!cfgGetAt("IsFakeMeasure", idx)) return false; return (getDataTypeFromArray(idx, "ColOldType") == 0); } function isString(idx) { return (getDataType(idx) == 5); } //returns true for date, time, datetime and timeInterval function isDateTime(idx) { var type = getDataType(idx); return (type > 0 && type < 5); } function isOldTypeDateTime(idx) { if (!cfgGetAt("IsFakeMeasure", idx)) return false; var type = getDataTypeFromArray(idx, "ColOldType"); return (type > 0 && type < 5); } function isDate(idx) { var type = getDataType(idx); return (type == 1); } function isTime(idx) { var type = getDataType(idx); return (type == 2); } function isInterval(idx) { var type = getDataType(idx); return (type == 4); } function isBlob(idx) { return (getDataType(idx) == 6); } function isCalc(idx) { if (cfgGetAt("calcOp", idx) != "") return true; return false; } function getCalcType(idx) { var calcOp = cfgGetAt("calcOp", idx); if (calcOp != "") { switch (calcOp) { //numerical calcs case "sum": case "difference": case "division": case "product": case "average": case "maximum": case "minimum": case "percent": case "percentDifference": case "percentTotal": case "percentile": case "rank": case "quartile": case "quantile": case "number": case "round": case "round down": case "absolute": case "sqrt": case "power": //datetime calcs case "yearDateTime": case "monthYearDateTime": case "hourDateTime": case "minuteDateTime": case "secondDateTime": case "dayWeekDateTime": case "dayMonthDateTime": case "dayYearDateTime": /* case "weekDateTime": not used */ //time calcs case "hourTime": case "minuteTime": case "secondTime": case "yearDate": //date calcs case "monthYearDate": case "dayWeekDate": case "dayMonthDate": case "dayYearDate": //interval calcs case "rankInterval": //currently represented as "rank" since rankInterval cannot be used on the cpp side case "daysInterval": case "daysBetweenDate": case "monthsBetweenDate": case "yearsBetweenDate": case "daysBetweenDateTime": case "monthsBetweenDateTime": case "yearsBetweenDateTime": /* case "weekDate": not used */ return "number"; //custom range calcs case "rangeString": case "rangeNumber": case "rangeDate": case "rangeTime": case "rangeInterval": case "rangeDateTime": return "range"; //custom group calcs case "groupString": case "groupNumber": return "group"; //string calcs case "left": case "right": case "trim": //date calcs case "monthNameDate": case "dayFirstDate": case "dayLastDate": case "dayNameDate": //datetime calcs case "monthNameDateTime": case "dayNameDateTime": case "dayFirstDateTime": case "dayLastDateTime": //concatenation calcs case "concatString": case "concatNumber": case "concatInterval": case "concatDatetime": case "concatDefault": return "string"; //date calcs case "maxDate": case "minDate": return "date"; //time calcs case "maxTime": case "minTime": return "time"; //datetime calcs case "maxDateTime": case "minDateTime": return "datetime"; //interval calcs case "sumInterval": case "differenceDateTime": case "differenceInterval": case "minInterval": case "maxInterval": return "interval"; //model calcs case "model": return "model"; } } return "unknown"; } function getDataType(idx) { return getDataTypeFromArray(idx, "ColType"); } function getDataTypeFromArray(idx, arrayName) { var nDatatype = cfgGetAt(arrayName, idx); if (nDatatype == "reportExpression") return 7; else { switch (parseInt(nDatatype)) { case 2: // dtInt case 3: // dtDouble case 10: // kDataTypeInt16 case 11: // kDataTypeInt32 case 12: // kDataTypeInt64 case 20: // kDataTypeDecimal case 21: // kDataTypeNumeric case 30: // kDataTypeFloat case 31: // kDataTypeFloat32 case 32: // kDataTypeFloat64 case 40: // kDataTypeBinary case 41: // kDataTypeBinaryLength16 return 0; //number case 50: // "kDataTypeDate" return 1; //date case 51: // "kDataTypeTime" return 2; //time case 52: // "kDataTypeDateTime" return 3; //datetime case 53: // "kDataTypeTimeInterval" return 4; //timeinterval case 60: // kDataTypeCharacter case 61: // kDataTypeCharacterLength16 case 62: // kDataTypeCharacterLength32 case 80: // kDataTypeDatabaseKey return 5; //string case 70: // "kDataTypeBlob" case 71: // "kDataTypeTextBlob" case 72: // "kDataTypeBlobArray" case 40: // "kDataTypeBinary" case 41: // "kDataTypeBinaryLength16" return 6; //blob default: break; } } return -1; } function getSelectionsDataType() { var numSel = cfgSize("SelColumns"); if (numSel < 1) return -1; var dataType = getDataType(cfgGetAt("SelColumns", 0)); for (var i = 1; i < numSel; i++) { if (dataType != getDataType(cfgGetAt("SelColumns", i))) return -1; } return dataType; } /* * General DOM utils */ function DOMUtils(){ } var agsDomUtils = new DOMUtils(); /* * cross browser toggle function, to show/hide an element such as a DIV */ DOMUtils.prototype.toggle = function(name){ if(document.getElementById(name).style.display == 'none') { this.show(name); } else { this.hide(name); } } /* * cross browser function to show an element such as a DIV */ DOMUtils.prototype.show = function(name){ document.getElementById(name).style.display=''; } /* * cross browser function to hide an element such as a DIV */ DOMUtils.prototype.hide = function(name){ document.getElementById(name).style.display='none'; } function AgsConditionParameterValue(name, parameterValue){ this.parameterValue = parameterValue; this.name = name; } AgsConditionParameterValue.prototype.getValue = function(){ return this.parameterValue; } AgsConditionParameterValue.prototype.getName = function(){ return this.name; } AgsConditionParameterValue.prototype.getValue = function(){ return this.parameterValue; } AgsConditionParameterValue.prototype.getName = function(){ return this.name; } //////////////////////////////// //read and write px or % numbers //////////////////////////////// function SizeParser(sizeString){ this.isPercent = isPercent; this.leq = leq; this.toString = toString; sizeString = new String(sizeString); var numberMatch = /^([0-9]+)$/ var percentMatch = /^([0-9]+)%$/; var pixelMatch = /^([0-9]+)px$/; //default to px this.unit = "px"; this.number = 0; var aMatch; if(!sizeString){ return; }else if(aMatch = sizeString.match(numberMatch)){ }else if(aMatch = sizeString.match(pixelMatch)){ }else if(aMatch = sizeString.match(percentMatch)){ this.unit = "%" }else{ return; } this.number = aMatch[1] ? aMatch[1] : 0; //does the parsed number represent a percentage or a unit? function isPercent(){ return this.unit == "%"; } //determine if the parsed number is less than or equal to 'num' function leq(num){ return this.number <= num; } function toString(){ return "" + this.number + this.unit; } function equals(anObject){ var isEqual = anObject instanceof SizeParser; return isEqual && (this.unit ==anObject.unit && this.number == anObject.number); } } /* this takes an input object and checks the maxLength attribute and trucs the value of the input if it goes over */ function checkMaxLength(anInput){ var mlength=anInput.getAttribute ? parseInt(anInput.getAttribute("maxlength")) : "" if (anInput.getAttribute && anInput.value.length > mlength){ anInput.value=anInput.value.substring(0, mlength) } } // this is an XML decode function function decode(text) { // seeing as this is come from XML - and it could hold anything - unescape // any dodgy characters var amp_re = /&/g; var lt_re = /</g; var gt_re = />/g; var apos_re = /'/g; var quot_re = /"/g; // Decode stuff which has been encoded/escaped out. text = text.replace(lt_re, "<"); text = text.replace(gt_re, ">"); text = text.replace(apos_re, "'"); text = text.replace(quot_re, "\""); // IMPORTANT - the amp_re has to come last otherwise double encoded values are decoded // as well. If this is at the beginning &lt; -> < in one go which is not good text = text.replace(amp_re, "&"); return text; } /****************************************************************************** * MISC FUNCTIONS ******************************************************************************/ /* * Get the expression locale, if not available then assign the content locale * this function will update the config variable 'expressionLocale' */ function getExpressionLocale() { var el=getConfigFrame().cfgGet("expressionLocale"); var cl = getConfigFrame().cfgGet("contentLocale"); //if we have an expression locale then assign it if (!el || el == '') { el = cl; //update the expression locale getConfigFrame().cfgSet("expressionLocale",el); } return el; } function resetExpressionLocale() { var cl = getConfigFrame().cfgGet("contentLocale"); getConfigFrame().cfgSet("expressionLocale",cl); } function getLocales(contentLocaleKey, productLocaleKey){ var locales = new Object(); // extract contentLocale from the cookie var cookieValues = document.cookie.split(";"); for (var i = 0; i < cookieValues.length; i++) { if (cookieValues[i].match(/^\s*CRN=/i)) { var aLocales = decodeURIComponent(decodeURIComponent(cookieValues[i].split("=")[1])).split("&"); for (var j = 0; j < aLocales.length; j++) { if (aLocales[j].match(/^contentLocale=/i)) locales[contentLocaleKey] = aLocales[j].split("=")[1]; if (aLocales[j].match(/^productLocale=/i)) locales[productLocaleKey] = aLocales[j].split("=")[1]; } } if (locales[contentLocaleKey] && locales[productLocaleKey]) break; } if (locales[contentLocaleKey] == "") locales[contentLocaleKey] = cfgGet("contentLocale"); if (locales[productLocaleKey] == "") locales[productLocaleKey] = cfgGet("productLocale"); return locales; } function DefectMessage(message, severity, location){ this.location = location; this.severity = new Severity(severity); this.message = htmlEncode(message); } DefectMessage.prototype.toString = function(){ return this.message; } function SeverityEnum(){ this.WARN = 3; this.FATAL = 1; this.ERROR = 2; this.INFO = 4; this.severity = new Object(); this.severity["fatal"] = new Array(1, "../ps/portal/images/msg_fatal_16.gif"); this.severity["warn"] = new Array(3, "../ps/portal/images/msg_warning_16.gif"); this.severity["error"] = new Array(2, "../ps/portal/images/msg_error_16.gif"); this.severity["info"] = new Array(4, "../ps/portal/images/msg_information_16.gif"); } var ags_severity_enum = new SeverityEnum(); function Severity(severityText){ var si = ags_severity_enum.severity[severityText]; if(si){ this.level = si[0]; this.img_src = si[1]; }else{ this.level = 5; this.img_src = "../ps/images/space.gif"; } this.text = severityText; } function DefectMessages(messages){ this.messages = new Array(); this.allMessages = new Array(); for(var i = 0; messages && i < messages.length; i++){ this.addMessage(messages[i]); } this.maxSeverity; this.process(); } DefectMessages.prototype.addMessage = function(defectMessage){ if(defectMessage instanceof DefectMessage && defectMessage.message){ this.allMessages.push(defectMessage); } this.process(); } DefectMessages.prototype.addMessages = function(defectMessageArray){ this.allMessages = this.allMessages.concat(defectMessageArray); this.process(); } DefectMessages.prototype.process = function(){ this.messagesBySeverity = new Object(); for(var i = 0; i < this.allMessages.length; i++){ var levelMessages = this.messagesBySeverity[this.allMessages[i].severity.text]; if(!levelMessages){ levelMessages = this.messagesBySeverity[this.allMessages[i].severity.text] = new Array(); } levelMessages.push(this.allMessages[i]); if(this.allMessages[i].severity.level && this.maxSeverity < this.allMessages[i].severity.level){ this.maxSeverity = this.allMessages[i].severity.level; } } } DefectMessages.prototype.isEmpty = function(){ return !this.allMessages || this.allMessages.length == 0; } /* this looks for the validate header messages and emboldens, and removes icons from all the rest CNC-SDS-0400 - CNC-SDS-0401 - CNC-SDS-0403 - */ DefectMessages.prototype.sortMessagesForValidate = function(){ var warnings = this.messagesBySeverity['warn']; for(var i = 0; warnings && i < warnings.length; i++){ if(warnings[i].message.match("CNC-SDS-0401")){ warnings[i].message = "" + warnings[i].message + ""; }else if(i != 0){ //this prevents the icon displaying warnings[i].severity = new Severity("none"); } } var errors = this.messagesBySeverity['error']; for(var i = 0; errors && i < errors.length; i++){ if(errors[i].message.match("CNC-SDS-0400")){ errors[i].message = "" + errors[i].message + ""; }else if(i != 0){ //this prevents the icon displaying errors[i].severity = new Severity("none"); } } var infos = this.messagesBySeverity['info']; for(var i = 0; infos && i < infos.length; i++){ if(infos[i].message.match("CNC-SDS-0403")){ infos[i].message = "" + infos[i].message + ""; }else if(i != 0){ //this prevents the icon displaying infos[i].severity = new Severity("none"); } } } DefectMessages.prototype.getMessagesForSeverity = function(severity){ var messages; if(severity instanceof Severity){ messages = this.messagesBySeverity[severity.text]; }else{ messages = this.messagesBySeverity[severity]; } return messages; } DefectMessages.prototype.getMaximumSeverity = function(){ return this.maxSeverity; } function BrowserCheck() { this.config = new BrowserConfig(); } BrowserCheck.prototype = { isFirefox: function () { return this.config.browser=='firefox'; }, isFF3Up: function () { return this.config.browser=='firefox' && this.config.browserVersion >= 3; } , isIE: function() { return this.config.browser=='explorer' && !this.config.browser!='opera'; }, isIE5Up: function() { return this.config.browser=='explorer' && this.config.browserVersion >= 5; }, isIE5dot5Up: function() { return this.config.browser=='explorer' && this.config.browserVersion >= 5.5; }, isIE5dot5: function() { return this.config.browser=='explorer' && this.config.browserVersion == 5.5; }, /* * This will return non IE browsers. Typically the following: * Firefox, Netscape, Safari, Mozilla, AOL, Konqueror, Chrome */ isNav6Up : function() { return navigator.userAgent.indexOf('Mozilla/5.0') != -1; }, getBrowser: function() { return this.config.browser; }, getBrowserVersion: function() { this.config.browserVersion; } } /** * Browser config */ function BrowserConfig() { this.initialize(); } BrowserConfig.prototype = { browser: "unknown", browserVersion: "unknown", initialize: function() { this.browser = this.lookup(this.browsers).toLowerCase() || "unknown"; this.browserVersion = this.parseVersion(navigator.userAgent) || this.parseVersion(navigator.appVersion) || "unknown"; }, lookup: function(data) { var i, l = data.length; for (i = 0; i < l; i++) { this.versionKey = data[i].partialKey || data[i].identity; var agent = data[i].agent; if (agent) { if (agent.indexOf(data[i].key) != -1) return data[i].identity; } else if (data[i].prop) return data[i].identity; } }, parseVersion: function(s) { var index = s.indexOf(this.versionKey); if (index == -1) return; return parseFloat(s.substring(index + this.versionKey.length + 1)); }, browsers: [ { agent: navigator.userAgent, key: "MSIE", identity: "Explorer", partialKey: "MSIE" }, { agent: navigator.userAgent, key: "Firefox", identity: "Firefox" }, { agent: navigator.userAgent, key: "Chrome", identity: "Chrome" }, { agent: navigator.vendor, key: "Apple", identity: "Safari" }, { agent: navigator.userAgent, key: "Gecko", identity: "Mozilla", partialKey: "rv" }, { agent: navigator.userAgent, key: "Mozilla", identity: "Netscape", partialKey: "Mozilla" }, { agent: navigator.userAgent, key: "Netscape", identity: "Netscape" }, { prop: window.opera, identity: "Opera" } ] }