/* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| *| IBM Cognos Products: BUX *| *| (C) Copyright IBM Corp. 2013 *| *| US Government Users Restricted Rights - Use, duplication or *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ if (!window.cwApi) {(function () { function _getCMStr(p){ var sCM = null; if (p.workspaceId) { sCM = "id/" + p.workspaceId; } else if (p.workspacePath) { sCM = "path/" + p.workspacePath; } return sCM; } window.cwApi = function(p, container, fCallback) { var c = document.getElementById(container); if (!c) { return null; } c.innerHTML = ""; // clear everything from the container var nIframe = document.createElement('iframe'); c.appendChild(nIframe); var sUrl = p.baseurl + "?b_action=icd"; var sCM = _getCMStr(p); var temp = null; if(p.baseurl) { temp = p.baseurl; temp = temp.replace(/^[^\/]*(?:\/[^\/]*){2}/, ""); p.rbase = temp; } if (sCM && temp) { sUrl += "&src=" + encodeURIComponent(temp + "/icd/feeds/cm/" + sCM + "?entry="); } else { sUrl += "&ui.action=new"; } if (p.profile) { sUrl += "&profile=" + p.profile; } if (p.remUI) { sUrl += "&remUI=" + p.remUI; } if (p.api) { sUrl += "&api=" + p.api; } if (p.container) { sUrl += "&container=" + p.container; } if( p.debug ) { sUrl += "&debug=true"; } nIframe.setAttribute( "style", typeof p.style == "string" ? p.style : "width:100%;height:100%;border:0" ); // TODO: inline var m = {}; if (p.listenTo) { for (var i=0,handle; handle = p.listenTo[i]; i++) { m[ [handle[0],handle[1]].join() ] = handle[2]; } } nIframe.setAttribute("src", sUrl); var oApi = { config: p, _the_frame: nIframe, listenToMap: m, info: function() { alert("\t\t-- CW API --\n\nload() needs baseurl,(workspace)id|path,profile?,userRole?\nunload - tbd"); }, invoke: function(wcType, action, oParam) { // TODO: make it work with postMessage. //this._the_frame.contentWindow.postMessage(msg, '*'); this._the_frame.contentWindow.buxApi(wcType, action, oParam); }, load: function(oParam) { // TODO: make it work with postMessage. //this._the_frame.contentWindow.postMessage(msg, '*'); if(oParam && this.config.rbase) { var sCM = _getCMStr(oParam); if( sCM ) { var p = { 'sSource': this.config.rbase + "/icd/feeds/cm/" + sCM + "?entry=", 'oParam' : oParam }; this._the_frame.contentWindow.buxApi("workspace", "load", p); } } }, _inspect: function(oParam) { return this._the_frame.contentWindow.buxApi("app","_inspect", oParam); }, unload: function() { this._the_frame.contentWindow.buxApi("workspace", "unload"); } }; window["cwApi_" + p.api] = oApi; if (fCallback) { setTimeout(function(){fCallback(oApi);},1); } return oApi; }; })();}