// Licensed Materials - Property of IBM // // IBM Cognos Products: cpscrn // // (C) Copyright IBM Corp. 2005, 2013 // // 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). // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // configuration object window._F_inactiveFragments = {}; window._F_libs = {}; var _F_initQueue = new _F_Queue.RunQueue(); var _F_WSRP = { /* * Object used to track fragments that are affected by the old portlet communication. e.g. universal viewer listening to the navigator session based portlet communication * This is needed so that wsrp portlet like the navigator is able to call the fragment to clear its state when the communicated value is updated */ wsrpP2PC: { }, isTransientUpdate : false, isIsolationMode : "SAP" == window.portalAgent && window.parent !== undefined, baseFragmentConstructor : window.fragment, baseCaptionConstructor : window.caption, baseAJAXRequestConstructor : window._F_Ajax.Request, baseAttach : window._F_attach, baseOnLoad: window._F_onload, baseEventExecute: window._F_Event.execute, unloaded: false, consumerModifyResource: null, unload: function(){ _F_WSRP.unloaded = true; }, buildResourceUrl: function(resourceTemplate, target){ var begin = resourceTemplate.indexOf("_cpsresourceurl"); if (begin != -1){ var endMarker="cpsendmarker_"; var end = resourceTemplate.indexOf(endMarker, begin); if (end != -1){ var marker = resourceTemplate.substring(begin, end + endMarker.length); var decodeCount = 0; var decodedMarker = marker; while(decodedMarker != "_cpsresourceurl:cpsendmarker_" && decodeCount ++ < 10){ decodedMarker = _F_Strings.urlDecode(decodedMarker); } if (decodeCount < 10){ var encodedTarget = _F_Config.expandMacros(target); for (i =0; i < decodeCount ; i++){ encodedTarget = _F_Strings.urlEncode(encodedTarget); } target = resourceTemplate.replace(marker, encodedTarget); } } } return target; }, fixInfoTitle: function(obj){ // This will fix the title in the fragment info to match the real caption title used by ther assembler. if (window.portalAgent == "cognos" && obj.isBaseFragment()) { var caption = $(obj.WSRPRewritePrefix()+"caption"); if (caption != null){ obj.info.title = _F_Strings.normalize(_F_Document.getTextContent(caption)); } } }, handleTitleUpdate: function (evt){ if (evt.source.id == this.id && this.isBaseFragment()) { if (evt.payload != null && evt.payload.newTitle != null) { var newTitle = evt.payload.newTitle; if (newTitle != this.title) { var caption = $(this.WSRPRewritePrefix()+"caption"); if (caption != null) caption.innerHTML = " " + newTitle + " "; } } } }, buildFragmentUri: function (fragment){ var uri = ""; if (fragment != null && fragment.id !== undefined){ uri +="frag-id=" + _F_Strings.urlEncode(fragment.id); if (fragment.state != null){ uri +="&frag-state=" + _F_Strings.urlEncode(fragment.state); } if (fragment.validator != null && fragment.validator.remote){ uri +="&frag-validator=" + _F_Strings.urlEncode(fragment.validator.remote); } if (fragment.windowState != null){ uri +="&frag-windowState=" + _F_Strings.urlEncode(fragment.windowState); } if (fragment.mode != null){ uri +="&frag-mode=" + _F_Strings.urlEncode(fragment.mode); } if (fragment.transientState != null){ for (var prop in fragment.transientState) uri+= "&" + prop + "=" + _F_Strings.urlEncode(fragment.transientState[prop]); } } return uri; }, deepCopy: function(src, target){ for (var prop in src){ if (typeof src[prop] == 'object' ){ if (target[prop] == null) target[prop] = new Object(); _F_WSRP.deepCopy(src[prop], target[prop]); }else { target[prop] = src[prop]; } } }, cleanIsolationModeLocalFragments: function(){ if (_F_WSRP.isIsolationMode) { for (var i=0; i < _F_localFragmentsIds.length; i++) if ( fragments[_F_localFragmentsIds[i]] !== undefined) delete fragments[_F_localFragmentsIds[i]]; } }, addLocalFragment: function(obj){ if (_F_WSRP.isIsolationMode){ _F_localFragmentsIds.push(obj.id); for (var fragid in fragments) if (fragments[fragid].parent != null && fragments[fragid].parent.id == obj.id) fragments[fragid].parent = obj; } }, saveGlobalTransients: function(){ if (_F_WSRP.isTransientUpdate) { var globalTransientValue = ""; for (var prop in fragment.prototype.transientGlobal){ if (globalTransientValue != "") globalTransientValue += "&"; globalTransientValue += prop + "=" + _F_Strings.urlEncode(fragment.prototype.transientGlobal[prop]); } if (globalTransientValue != "") { var url = _F_Config.gateway + _F_Config.application + "?bridge-appTransients=" + _F_Strings.urlEncode(globalTransientValue); var fragRequest = new _F_Ajax.Request(url, { requestHeaders: { "Connection": "keep-alive", "Accept": "text/xml,application/xml" }, asynchronous : false }); } _F_WSRP.isTransientUpdate = false; } }, /*Needed for CQCOGCQ00815120 */ destroyTransientState: function(transientName, channel){ var key = transientName + '['+channel+']'; var fragList = _F_WSRP.wsrpP2PC[key]; if (fragList){ for (var i = 0 ; i < fragList.length; i++){ fragList[i].destroyState(fragList[i].id, true, true); } } }, /*Needed for CQCOGCQ00815120 */ setDestroyStateForTransient: function(fragment, transientName, channel){ var key = transientName + '['+channel+']'; var fragList = _F_WSRP.wsrpP2PC[key]; if (!fragList){ fragList = []; _F_WSRP.wsrpP2PC[key] = fragList; } if (_F_Array.indexOf(fragList, fragment) == -1){ fragList.push(fragment); } } } window.caption = function(fragmentID, layoutID) { var frag = fragments[fragmentID]; var windowState; var mode; if (frag != null){ windowState = frag.windowState; frag.windowState = "normal"; mode = frag.mode; frag.mode = "view"; } var obj = new _F_WSRP.baseCaptionConstructor(fragmentID, layoutID); obj.__proto__ = _F_WSRP.baseCaptionConstructor.prototype; if (frag != null){ if (frag.onloadInitialized){ frag.setMode(mode, "internal"); frag.setWindowState(windowState, "internal"); }else{ _F_initQueue.add(frag, frag.setMode, [mode, "internal"]); _F_initQueue.add(frag, frag.setWindowState, [windowState, "internal"]); } } return obj; } window.caption.prototype = _F_WSRP.baseCaptionConstructor.prototype; window._F_Event.execute = function(frag, listener, evt) { if (evt.name == "fragment.load" && _F_WSRP.unloaded){ return; } _F_WSRP.baseEventExecute(frag, listener, evt); } if (_F_WSRP.isIsolationMode){ if (window.parent._F_isolationMode === undefined){ window.parent._F_isolationMode = { transientGlobal:{}, fragments:{} } } window._F_localFragmentsIds = new Array(); window.fragments = window.parent._F_isolationMode.fragments; _F_Document.addEventListener(window, "beforeunload", _F_WSRP.cleanIsolationModeLocalFragments); } fragment.prototype.showbusy = function(evt) { if (window.portalAgent == "cognos" && this.isBaseFragment()) { var caption = $(this.WSRPRewritePrefix()+"caption_busy"); if (caption != null){ var id = this.WSRPRewritePrefix()+"caption_busyicon"; var busyIcon = $(id); if (busyIcon == null){ busyIcon= document.createElement("IMG"); busyIcon.src = _F_Config.webContent + "/fragments/portlet/images/portlet_action_refresh_ani.gif"; busyIcon.id = id; xAppendChild(caption, busyIcon); } caption.style.display=""; } } } fragment.prototype.hideBusy = function(evt) { if (window.portalAgent == "cognos" && this.isBaseFragment()) { var busyIcon = $(this.WSRPRewritePrefix()+"caption_busy"); if (busyIcon != null){ busyIcon.style.display="none"; } } } window.fragment = function(path, id, div) { var obj = new _F_WSRP.baseFragmentConstructor(path, id, div); obj.__proto__ = _F_WSRP.baseFragmentConstructor.prototype; obj.initialize(); _F_WSRP.addLocalFragment(obj); obj.addEventListener("fragment.destroy", obj.handleDestroyEvent, false); obj.addEventListener("fragment.retrieve.before", obj.showbusy, false); obj.addEventListener("fragment.retrieve.after", obj.hideBusy, false); return obj; } window.fragment.prototype = _F_WSRP.baseFragmentConstructor.prototype; window._F_attach = function(obj) { var frag = _F_WSRP.baseAttach(obj); return frag; } fragment.prototype.initialize = function() { if (window._F_inactiveFragments[this.id] != null) _F_WSRP.deepCopy(window._F_inactiveFragments[this.id], this); } fragment.prototype.initializeBaseFragment = function(obj){ for (var prop in obj) this[prop] = obj[prop]; if ("cognos" == window.portalAgent) this.addEventListener("fragment.title.change", _F_WSRP.handleTitleUpdate, false); } fragment.prototype.isBaseFragment = function() { return this.instanceKeyImpl !== undefined; } fragment.prototype.baseBaseURI = fragment.prototype.baseURI; fragment.prototype.baseURI = function() { var url = this.baseBaseURI.apply(this, arguments); url += (url.indexOf("?") == -1) ? "?" : "&"; url += "bridge-fid=" + this.instanceKey(); url += "&bridge-gatewayURL=" + _F_Strings.urlEncode(window._F_config.WSRPGateway); if (window._F_config.WSRPWebContent != null) { url += "&bridge-webContentURL=" + _F_Strings.urlEncode(window._F_config.WSRPWebContent); } url += "&frag-portalAgent=" + _F_Strings.urlEncode(window.portalAgent); return url; } fragment.prototype.baseProcessError = fragment.prototype.processError; fragment.prototype.processError = function(code, message, details){ if (code == "invalidCredentials" && window.portalAgent != "cognos") { this.performAction(""); return; } return this.baseProcessError.apply(this, arguments); } fragment.prototype.handleDestroyEvent = function(evt){ if (evt.eventPhase == evt.AT_TARGET ){ this.destroyState(this.id); if (_F_inactiveFragments[this.id]){ _F_inactiveFragments[this.id] = null; } } } fragment.prototype.destroyState = function(id, includeChildren, isSynchronous) { var url = _F_Config.gateway + _F_Config.application + "?bridge-destroy=" + _F_Strings.urlEncode(id); if(includeChildren){ var appendDestroyId = function(fragment, url){ var children = fragment.getChildren(); for (var i =0 ; i < children.length; i++){ url += "&bridge-destroy=" + _F_Strings.urlEncode(children[i].id); url = appendDestroyId(children[i], url); } return url ; } url = appendDestroyId(this, url); } url += "&bridge-fid=" + _F_Strings.urlEncode(this.instanceKey()); var fragRequest = new _F_Ajax.Request(url, { requestHeaders: { "Connection": "keep-alive", "Accept": "text/xml,application/xml" }, asynchronous : (isSynchronous ? false: true) }); } window._F_Ajax.Request = function(url, options){ _F_WSRP.unloaded = false; var resourceUrl = url; if ("cognos" != window.portalAgent) resourceUrl = _F_WSRP.buildResourceUrl(window.resourceTemplate,resourceUrl); if(window._F_WSRP.consumerModifyResource != null) { resourceUrl = window._F_WSRP.consumerModifyResource(resourceUrl); } var obj = new _F_WSRP.baseAJAXRequestConstructor(resourceUrl, options); obj.__proto__ = _F_WSRP.baseAJAXRequestConstructor.prototype; return obj; } window._F_Ajax.Request.prototype = _F_WSRP.baseAJAXRequestConstructor.prototype; fragment.prototype.getWSRPInteractionBaseParams = function() { var s = "&frag-mode=" + this.mode; if (this.mode != "view" && _F_Array.indexOf(this.modes, this.mode) == -1) s += "&frag-delegate=" + _F_Strings.urlEncode(this.mode); if (this.view != "") s += "&frag-view=" + _F_Strings.urlEncode(this.view); if (this.windowState != "") s += "&frag-windowState=" + _F_Strings.urlEncode(this.windowState); if (this.validator != null && this.validator.remote) s += "&frag-validator=" + _F_Strings.urlEncode(this.validator.remote); if (_F_config.authToken) s += "&cps-authToken=" + _F_Strings.urlEncode(_F_config.authToken); return s; } fragment.prototype.getBaseFragment = function() { var f = this; while (f != null && !(f.isBaseFragment())) f = f.parent; if (f != null && f.isBaseFragment()) return f; throw "not supported"; } fragment.prototype.WSRPActionUrl = function() { var f = this.getBaseFragment(); if (f.WSRPActionUrlImpl !== undefined) return f.WSRPActionUrlImpl; throw "not supported"; } fragment.prototype.instanceKey = function() { var f = this.getBaseFragment(); if (f.instanceKeyImpl !== undefined) return f.instanceKeyImpl; throw "not supported"; } fragment.prototype.WSRPRewritePrefix = function() { var f = this.getBaseFragment(); if (f.WSRPRewritePrefixImpl !== undefined) return f.WSRPRewritePrefixImpl; throw "not supported"; } fragment.prototype.baseSetMode = fragment.prototype.setMode; fragment.prototype.setMode = function(mode) { if (this.isBaseFragment() && (arguments[1] === undefined || arguments[1] != "internal")){ if (mode != "") this.mode = mode; this.performAction(""); }else{ this.baseSetMode.apply(this, arguments); } } fragment.prototype.baseRetrieve = fragment.prototype.retrieve; fragment.prototype.retrieve = function(sParams, dest, asynchronous){ if (sParams == null) sParams=''; for (var prop in fragments) if (fragments[prop] != null && fragments[prop] != this && fragments[prop].id.indexOf(this.id) == 0){ var fragment = fragments[prop]; if (sParams != '') sParams += '&'; sParams += "frag-sub=" + _F_Strings.urlEncode(_F_WSRP.buildFragmentUri(fragment)); } for (var prop in _F_inactiveFragments) if (fragments[prop] == null && _F_inactiveFragments[prop] != null && _F_inactiveFragments[prop] != this && prop.indexOf(this.id) == 0){ var fragment = _F_inactiveFragments[prop]; if (sParams != '') sParams += '&'; sParams += "frag-sub=" + _F_Strings.urlEncode(_F_WSRP.buildFragmentUri(fragment)); } return this.baseRetrieve(sParams, dest, asynchronous); } fragment.prototype.basePerformAction = fragment.prototype.performAction; fragment.prototype.performAction = function(query) { if (this.isBaseFragment()){ var wsrpActionArray = this.WSRPActionUrl(); var wsrpAction = wsrpActionArray[this.mode]; if (wsrpAction == null){ wsrpAction = wsrpActionArray["_current"]; } var form = new _F_FormWrapper.Form(this.WSRPRewritePrefix(), this.id, "perform$action", wsrpAction); var fullQuery = this.getWSRPInteractionBaseParams(); if (query && query != "") fullQuery += '&' + query; form.setParams(fullQuery.split("&")); form.submit(); }else{ this.basePerformAction(query); } } window._F_onload = function() { if (_F_WSRP.isIsolationMode){ if (window.parent._F_isolationMode !== undefined){ _F_WSRP.deepCopy(fragment.prototype.transientGlobal, window.parent._F_isolationMode.transientGlobal); fragment.prototype.transientGlobal = window.parent._F_isolationMode.transientGlobal; } } for (var id in fragments) _F_WSRP.fixInfoTitle(fragments[id]); _F_WSRP.baseOnLoad(); while(_F_initQueue.queue.hasNext()) _F_initQueue.run(); // Fix for IE to hide unwanted vertical scrollbar. if (xIE4Up && window.portalAgent == "cognos"){ for (var id in fragments){ var frag = fragments[id]; if (frag.isBaseFragment){ frag.addEventListener("fragment.load", _F_fixIEScrollbar, true); frag.addEventListener("fragment.visibility.change", _F_fixIEScrollbar, true); } } } // fire "page.load" event on the top level page var oEvent = new _F_Event.Event(); oEvent.initEvent("page.load", "", null, false, false); for (var id in fragments) { if (fragments[id].parent == null) { oEvent.source = fragments[id]; fragments[id].dispatchEvent(oEvent); } } _F_Document.addEventListener(window, "beforeunload", _F_WSRP.saveGlobalTransients); } function _F_fixIEScrollbar(evt){ if (window._ASM_fixIEScrollbar){ var frag = evt.currentTarget; _ASM_fixIEScrollbar(frag.WSRPRewritePrefix()+"_content"); } } fragment.prototype.baseFragmentTransientUpdate = fragment.prototype.transientUpdate; fragment.prototype.transientUpdate= function(sName, sValue, sScope, sChannel) { _F_WSRP.isTransientUpdate = true; if (arguments.length > 2){ arguments[2] = arguments[2]=="page" ? "application" : arguments[2]; } return this.baseFragmentTransientUpdate.apply(this, arguments); } var _F_FormWrapper = { } _F_FormWrapper.Form = function(wsrpid, id, name, action) { this.wsrpid = wsrpid; this.id = id; this.name = name; this.action = action; } _F_FormWrapper.Form.prototype = { setParams: function(params) { this.params = params; }, submit: function() { var form = this.createForm(); for (var i = 0; i < this.params.length; ++i) { var param = this.params[i]; if (param.length > 0) { var eq_index = param.indexOf("="); var name; var value; if (eq_index != -1) { name = decodeURIComponent(param.substring(0, eq_index)); value = decodeURIComponent(param.substring(eq_index + 1)); } else { name = decodeURIComponent(param); value = ""; } this.addParam(form, name, value); } } if (this.action.indexOf('javascript:') == 0) eval(this.action); else form.submit(); this.detach(form); }, createForm: function() { var form = document.createElement("form"); form.setAttribute("name", this.name); form.setAttribute("method", "POST"); form.action = this.action; document.body.appendChild(form); return form; }, addParam: function(form, name, value) { var param = document.createElement("input"); param.setAttribute("type", "hidden"); param.setAttribute("name", this.buildParamName(name)); param.setAttribute("value", value); form.appendChild(param); }, buildParamName: function(name) { return name; }, detach: function(form) { document.body.removeChild(form); } } if ("SharePoint" == window.portalAgent) { _F_Form.find=function(name) { return document[name]; } _F_Form.lookupAction=function(action) { if (window.wpforms !== undefined) { var i, l = window.wpforms.length; for (i = 0; i < l; i++) if (window.wpforms[i].action.indexOf(action) > -1) return window.wpforms[i]; } document.forms[0]; } _F_Form.getParamName = function(form, name) { if (form._prefix !== undefined && name.indexOf(form._prefix) == 0) { name = name.substring(form._prefix.length); } return name; } _F_FormWrapper.Form.prototype.createForm=function() { var form=document.forms[0]; this.formID=form[this.wsrpid].value + '_'; form[this.wsrpid].value=this.id + this.name; return form; } _F_FormWrapper.Form.prototype.buildParamName=function(name) { if (name.indexOf(this.formID) == 0) name=name.substring(this.formID.length); return this.id + this.name + '_' + name; } _F_FormWrapper.Form.prototype.detach=function() { // do nothing } } _F_Document.addEventListener(window, "beforeunload", _F_WSRP.unload);