// Licensed Materials - Property of IBM // // IBM Cognos Products: cogadmin // // (C) Copyright IBM Corp. 2005, 2012 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. // // /** * Attach an event to the given element * capture flag is not specified * @param object * @param eventType * @param func * @return */ function addEventToObject(object, eventType, func){ var isEventAdded = false; if (object && eventType && func) { eventType = eventType.toLowerCase(); if (object.addEventListener){ object.addEventListener(eventType, func, false); isEventAdded = true; } else if (object.attachEvent){ isEventAdded = object.attachEvent("on" + eventType, func); } } return isEventAdded; } /* This class allows a fragment to be embedded in any html document */ /** * Constructor * The parameters are either: * An object with the following attribute: * gateway: path to the gateway [mandatory] * webRoot: path to the webroot [mandatory] * skinRoot: path to the skin root [optional for backward compatibility] * * */ function FragmentEmbedder() { var args = arguments; this._configuration = null; this._frags = []; this._loadedScripts = 0; this._loadedCssStyles = 0; this._retrievedFragments = 0; //for backward compatibility if (args && args.length == 1 && typeof args[0] != 'string') { this._configuration = args[0]; } else if (args && args.length >= 2) { this._configuration = {"gateway":args[0],"webRoot":args[1]}; } var _self = this; FragmentEmbedder.ERROR_UNDEFINED_CONF = "Illegal Argument Exception: No configuration is defined"; FragmentEmbedder.ERROR_UNDEFINED_GATEWAY = "Illegal Argument Exception: No gateway is defined"; FragmentEmbedder.ERROR_UNDEFINED_WEBROOT = "Illegal Argument Exception: No webRoot is defined"; FragmentEmbedder.ERROR_UNDEFINED_FRAGDEF = "Illegal Argument Exception: No fragment definition is defined"; /** * verifies the configuration */ this._verifyConfiguration = function() { if (!_self._configuration || _self._configuration == null) { throw FragmentEmbedder.ERROR_UNDEFINED_CONF; } if (_self._configuration.gateway == null || _self._configuration.gateway == "") { throw FragmentEmbedder.ERROR_UNDEFINED_GATEWAY; } if (_self._configuration.webRoot == null) { throw FragmentEmbedder.ERROR_UNDEFINED_WEBROOT; } } this._verifyConfiguration(); var scripts = [ this._configuration.webRoot+'/dojo16/dojo/dojo.js', this._configuration.webRoot+'/fragments/xdojo/core.js', this._configuration.gateway+'/dashboard/messages/messages/pfmessages?section=JS,GEN', this._configuration.webRoot+'/fragments/fragments.js', this._configuration.webRoot+'/common/framework/validator/CValidator.js', this._configuration.webRoot+'/fragments/uicommon.js' ]; /** * The following stylesheet is required when showing the details of an error. */ var cssStyles = [ this._configuration.skinRoot+'/fragments/portlet.css' ]; /** * This method registers a fragment to be loaded; the parameter is either an object or a sequence of 3 strings: * fragUrl: url for the fragment * fragDivId: id of the fragment div, * retrieveParams: string or function providing the parameters to pass when retrieving the fragment * It is recommended to use the object */ this.embed = function () { var fragDef = null; var args = arguments; if (!args || args.length == 0) { throw FragmentEmbedder.ERROR_UNDEFINED_FRAGDEF; } if (args.length == 1 && typeof args[0] != 'string') { _self._frags[_self._frags.length] = args[0]; } else { fragDef = {}; if (args[0]) { fragDef.fragUrl = args[0]; } else { fragDef.fragUrl = null; } if (args[1]) { fragDef.fragDivId = args[1]; } else { fragDef.fragDivId = null; } if (args[2]) { fragDef.retrieveParams = args[2]; } else { fragDef.retrieveParams = null; } _self._frags[_self._frags.length] = fragDef; } /* * We return the fragDef object, but it should be treated as an opaque object by the client */ return _self._frags[_self._frags.length]; } /** * This methods loads the embedded fragments * the onload parameter is a flag indicating whether or not the load has to happen once the page is loaded */ this.loadFragments = function(onLoad) { if (onLoad) { addEventToObject(window,"load",function() {_self._loadScriptsAndFragments();}); } else { this._loadScriptsAndFragments(); } } /** * This method raised the specified event on the specified embedded fragment */ this.raiseEvent = function(fragDef, eventName, payload, type){ fragDef.raiseEvent(eventName, payload, type); } /** * This method loads the necessary scripts, css stylesheets and then the fragments */ this._loadScriptsAndFragments = function() { if (_self._loadedScripts < scripts.length) { _self._loadScript(scripts[_self._loadedScripts++],_self._loadScriptsAndFragments); } else if (_self._loadedCssStyles < cssStyles.length) { _self._loadCssStyle(cssStyles[_self._loadedCssStyles++],_self._loadScriptsAndFragments); } else { _self._loadFrags(); } } this._canShowErrorDetails = function() { var canShow = false; if (_self._configuration.skinRoot) { canShow = true; } return canShow; } this._loadFrags = function() { if (!window._F_Config) { _F_Config = new Object(); } _F_Config.gateway = _self._configuration.gateway; _F_Config.application = "/cogadmin"; _F_Config.webContent = _self._configuration.webRoot; if (_self._canShowErrorDetails()) { ui_error.prototype.template = '
' + PFM.GEN.IDS_GEN_DETAILS + '
'; } else { ui_error.prototype.template = '
'; } for (var i=0;i<_self._frags.length;i++) { _self._fragInit(_self._frags[i]); } this._retrieveFragment(); } this._isScriptLoaded = function(src) { return this._isFileLoaded("src",src); } this._isCssStyleLoaded = function(src) { return this._isFileLoaded("href",src); } this._isFileLoaded = function(attribute,value) { var head = document.getElementsByTagName("head")[0]; var isLoaded = false; var i=0; while (i