/* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| *| BI and PM: BUX *| *| (C) Copyright IBM Corp. 2009 *| *| US Government Users Restricted Rights - Use, duplication or *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *| *+------------------------------------------------------------------------+ */ // create script variables used to store TM1 callbacks var COGNOS_TM1_webShtWgtToolbarFuncs; var COGNOS_TM1_webShtWgtFltrFuncs; dojo.require("dojo.string"); dojo.require("dojo._base.array"); dojo.require("bux.i18n"); dojo.require("bux.Helper"); dojo.require("bux.data.UserPreferencesStore"); dojo.provide("tm1ContentWebSheetViewerWidget"); dojo.declare("tm1ContentWebSheetViewerWidget", null, { iframeCtrl: null, _paramgizmo_id: null, returnURL: null, initialHeight: 286, xmlhttp: null, commonDomain: null, bTurnOffCallbacks: false, tm1Toolbar: null, _currentRole: null, // ====== DefaultSize Support - Start ======== _defaultWidth:700, _defaultHeight:400, _firstRender:true, // ====== DefaultSize Support - End ======== _productLocale:null, _tm1messages:null, onLoad: function(evt) { // ====== Multilingual Support - Start ======== // Remember where we were loaded from: this is our path for future AJAX calls and .js loads dojo.registerModulePath("tm1ContentWebSheetViewerWidget",this.iContext.io.rewriteURI("js")); this.setLanguage().then(dojo.hitch(this, "continueOnLoad")); // ====== Multilingual Support - End ======== }, continueOnLoad: function() { this.getRole(); this.createBasicWidgetToolbar(); this.getWidgetAttributes(); if (this.areTM1ParametersValid ()) { this.refreshView(); } // ====== DefaultSize Support - Start ======== //Delay the creation of some dynamic content to allow the widget to render first, //otherwise the dojo controlscannot properly render within its allowed real-estate. setTimeout(dojo.hitch(this,this.postLoadInit),1); // ====== DefaultSize Support - End ======== }, // ====== Multilingual Support - Start ======== updateView: function() { this.setLanguage(); }, setLanguage: function() { // Setup Localization tables - Use the BUX preferences for locale. Use Product locale for loading strings var curProductLocale=bux.Helper.getUserPreference("productLocale"); if (this._productLocale != curProductLocale) { this._productLocale = curProductLocale; var deferred = new dojo.Deferred(); var self = this; dojo.requireLocalization("tm1ContentWebSheetViewerWidget","tm1ContentWebSheetViewerWidget_msg", curProductLocale); dojo.ready(function() { self._tm1messages = dojo.i18n.getLocalization("tm1ContentWebSheetViewerWidget", "tm1ContentWebSheetViewerWidget_msg", curProductLocale); deferred.resolve(); }); return deferred; } }, // ====== Multilingual Support - End ======== // ====== DefaultSize Support - Start ======== postLoadInit: function() { // In this function, create the dynamic contents of the iWidget that are dojo objects based on dynamic HTML // call auto resize if it's the first time and is this widget was never saved. if (this._firstRender == true) { this._firstRender = false; var setDefaultSize = this.iContext.getiWidgetAttributes().getItemValue("setDefaultSize"); if (setDefaultSize == "1") { // Next time the container dashboard loads, the default size must be ignored - as desired this.iContext.getiWidgetAttributes().setItemValue("setDefaultSize", "0"); this.setPreferredSize(); } } }, getChrome: function() { var chromeObjectId = bux.Helper.widgetIdToChromeId(this.iContext.widgetId); var chromeObject = bux.Helper.getChromeById(chromeObjectId); return chromeObject; }, setPreferredSize: function() { var chromeObject = this.getChrome(); var newSize = {h: this._defaultHeight, w : this._defaultWidth}; chromeObject.setPreferredSize(newSize); chromeObject.doChromeAutoResize(); }, // ====== DefaultSize Support - End ======== getRole: function () { if( this.iContext ) { var userProfileItemSet = this.iContext.getItemSet("buxuserprofile", false); if( userProfileItemSet ){ var role = userProfileItemSet.getItemValue("currentUserRole"); if( role && bux.UserRole.isValidRole(role) ) { this._currentRole = role; } } } }, createBasicWidgetToolbar: function () { if (this.bTurnOffCallbacks) { var toolbarItems = [ { _root: [ {separator: true }, {name: "Restart", action: "IDM_RESTART", label: this._tm1messages.MEN.TMX_MEN_BLUEDOT_RESTART, showLabel: false, "iconClass": "tutorial-toolbar-icon-canada"} ] } ]; this.iContext.iEvents.fireEvent("com.ibm.bux.widgetchrome.toolbar.init", null, toolbarItems); } else { var toolbarItems = [ { _root: [ {separator: true }, {name: "Refresh", action: "IDM_RECALCULATE", label: this._tm1messages.MEN.TMX_MEN_BLUEDOT_REFRESH, showLabel: false, "iconClass": "bux-refresh-image"}, {name: "Restart", action: "IDM_RESTART", label: this._tm1messages.MEN.TMX_MEN_BLUEDOT_RESTART, showLabel: false, "iconClass": "tutorial-toolbar-icon-canada"} ] } ]; this.iContext.iEvents.fireEvent("com.ibm.bux.widgetchrome.toolbar.init", null, toolbarItems); } }, createWidgetToolbar: function (inToolbar) { var temptoolbarItems; this.tm1Toolbar = inToolbar; var toolbarItems = [ { _root: [ {separator: true }, {name: "Refresh", action: "IDM_RECALCULATE", label: this._tm1messages.MEN.TMX_MEN_BLUEDOT_REFRESH, showLabel: false, "iconClass": "bux-refresh-image"}, {name: "Restart", action: "IDM_RESTART", label: this._tm1messages.MEN.TMX_MEN_BLUEDOT_RESTART, showLabel: false, "iconClass": "tutorial-toolbar-icon-canada"} ] } ]; toolbarItems = this.addToolbutton(toolbarItems, "IDM_COMMIT"); toolbarItems = this.addToolbutton(toolbarItems, "IDM_SAVEDATACHANGES"); toolbarItems = this.addToolbutton(toolbarItems, "IDM_REVIEWDATACHANGES"); toolbarItems = this.addSeparator(toolbarItems); toolbarItems = this.addToolbuttonWithSubmenu (toolbarItems, "IDM_EXPORT"); toolbarItems = this.addSeparator(toolbarItems); toolbarItems = this.addToolbutton(toolbarItems, "IDM_RECALCULATE"); toolbarItems = this.addToolbutton(toolbarItems, "IDM_REBUILDACTIVEFORMS"); toolbarItems = this.addToolbutton(toolbarItems, "IDM_TOGGLE_AUTOMATICRECALCULATE"); toolbarItems = this.addToolbutton(toolbarItems, "IDM_AUTO_FIT_COL"); toolbarItems = this.addToolbutton(toolbarItems, "IDM_ZOOM_IN"); toolbarItems = this.addToolbutton(toolbarItems, "IDM_ZOOM_OUT"); toolbarItems = this.addToolbutton(toolbarItems, "IDM_ZOOM_NORMAL"); toolbarItems = this.addSeparator(toolbarItems); toolbarItems = this.addToolbutton(toolbarItems, "IDM_RESET_DATA"); toolbarItems = this.addToolbutton(toolbarItems, "IDM_SANDBOX_UNDO"); toolbarItems = this.addToolbutton(toolbarItems, "IDM_SANDBOX_REDO"); toolbarItems = this.addSeparator(toolbarItems); toolbarItems = this.addToolbuttonWithSubmenu (toolbarItems, "IDM_SANDBOX"); toolbarItems = this.addToolbuttonWithSubmenu (toolbarItems, "IDM_SANDBOXITEMS"); this.iContext.iEvents.fireEvent("com.ibm.bux.widgetchrome.toolbar.init", null, toolbarItems); }, addSeparator: function (toolbarItems) { var separator = { "separator": true }; return toolbarItems.concat(separator); }, addToolbutton: function (toolbarItems, toolbarAction) { if (this.isToolbuttonVisible(toolbarAction)) { return toolbarItems.concat(this.createSimpleToolbutton(toolbarAction)); } else { return toolbarItems; } }, addToolbuttonWithSubmenu: function (toolbarItems, toolbarAction) { if (this.isToolbuttonVisible(toolbarAction)) { return toolbarItems.concat(this.createToolbuttonWithSubmenu(toolbarAction)); } else { return toolbarItems; } }, createSimpleToolbutton: function (toolbarAction) { var toolbutton = { "name" : toolbarAction, "action" : toolbarAction, "label": this.getToolbuttonTooltip(toolbarAction), "iconClass": this.getToolbuttonImage(toolbarAction), "disabled": this.isToolbuttonDisabled(toolbarAction) } return toolbutton; }, appendSandboxMenuChoice: function (menuItems, sandboxIndex, sandboxName, activeSandbox) { var toolbarAction = "SANDBOXCHOICE" + sandboxIndex; var toolbutton = { "name" : toolbarAction, "action" : toolbarAction, "label": sandboxName, "iconClass": (activeSandbox == sandboxName ? "tm1-menu-radioselection" : "tm1-menu-empty") } return menuItems.concat(toolbutton); }, createToolbuttonWithSubmenu: function (toolbarAction) { var menuitems = null; if (toolbarAction == "IDM_EXPORT") { var menuItems = []; menuItems = this.addToolbutton(menuItems, "IDM_SLICE_TO_EXCEL"); menuItems = this.addToolbutton(menuItems, "IDM_SNAPSHOT_TO_EXCEL"); menuItems = this.addToolbutton(menuItems, "IDM_EXPORT_TO_PDF"); var toolbutton = { "name" : toolbarAction, "action" : toolbarAction, "label": this.getToolbuttonTooltip(toolbarAction), "iconClass": this.getToolbuttonImage(toolbarAction), "disabled": this.isToolbuttonDisabled(toolbarAction), "items" : menuItems } return toolbutton; } else if (toolbarAction == "IDM_SANDBOX") { var menuItems = []; menuItems = this.addToolbutton(menuItems, "IDM_CREATE_SANDBOX"); menuItems = this.addToolbutton(menuItems, "IDM_DELETE_SANDBOX"); var toolbutton = { "name" : toolbarAction, "action" : toolbarAction, "label": this.getToolbuttonTooltip(toolbarAction), "iconClass": this.getToolbuttonImage(toolbarAction), "disabled": this.isToolbuttonDisabled(toolbarAction), "items" : menuItems } return toolbutton; } else if (toolbarAction == "IDM_SANDBOXITEMS") { var menuItems = []; menuItems = this.appendSandboxMenuChoice(menuItems, 0, "[Base]", this.tm1Toolbar.ToolbarInfo.Sandbox.ActiveSandbox); if (this.tm1Toolbar.ToolbarInfo.Sandbox.SandboxList.length > 0) { for (i=0; i 0) { this.tm1Height = resize.h; this.saveTM1CubeViewerParams(this.iContext); } return; } }, getWidgetAttributes : function (){ this.tm1WebURL = this.iContext.getiWidgetAttributes().getItemValue("tm1WebURL"); this.tm1Host = this.iContext.getiWidgetAttributes().getItemValue("tm1Host"); this.tm1Server = this.iContext.getiWidgetAttributes().getItemValue("tm1Server"); this.tm1CubeView = decodeURIComponent(this.iContext.getiWidgetAttributes().getItemValue("tm1CubeView")); this.tm1UserName = this.iContext.getiWidgetAttributes().getItemValue("tm1UserName"); this.tm1Password = this.iContext.getiWidgetAttributes().getItemValue("tm1Password"); this.tm1InternalToolbar = this.iContext.getiWidgetAttributes().getItemValue("TM1Toolbar"); this.tm1Height = this.iContext.getiWidgetAttributes().getItemValue("tHeight"); if (this.tm1Height == "") { this.tm1Height = this.initialHeight; } }, saveTM1CubeViewerParams: function (inIContext) { inIContext.getiWidgetAttributes().setItemValue("tm1Host", this.tm1Host); inIContext.getiWidgetAttributes().setItemValue("tm1Server", this.tm1Server); inIContext.getiWidgetAttributes().setItemValue("tm1CubeView", encodeURIComponent(this.tm1CubeView)); inIContext.getiWidgetAttributes().setItemValue("tHeight", this.tm1Height); inIContext.getiWidgetAttributes().setItemValue("tm1UserName", this.tm1UserName); inIContext.getiWidgetAttributes().setItemValue("tm1Password", this.tm1Password); inIContext.getiWidgetAttributes().setItemValue("TM1Toolbar", this.tm1InternalToolbar); return; }, initializeiframe : function (url) { this.iframeCtrl = new webSheetViewerIFrame({ url: url, iWidget: this }, this.iContext.getElementById("_" + this.iContext.widgetId + "_" + "tm1CubeViewerWidgetDiv")); if (this.tm1Height <= 0) { this.tm1Height = 402; } this.iframeCtrl.startup(this.tm1Height); // find out our working space var chromeObjectId = bux.Helper.widgetIdToChromeId(this.iContext.widgetId); var chromeObject = bux.Helper.getChromeById(chromeObjectId); var currentSize = chromeObject.getClientBox(); this.iframeCtrl.resize(currentSize); }, onWidgetRefresh: function(evt) // Invoked when User preferences get modified (Including locales) { this.recalcCubeViewer(); return; }, recalcCubeViewer : function () { var url = this.iframeCtrl.getObjectIDURL(); var url2 = url.replace("TM1WebCubeViewer","TM1WebMain"); url2 += "&Action=Recalc"; this.iframeCtrl.setUrl(url2); return; }, restartSession : function () { var url = this.iframeCtrl.getObjectIDURL(); var url2 = url.replace("TM1WebCubeViewer","TM1WebMain"); url2 += "&Action=Reload"; this.iframeCtrl.setUrl(url2); return; }, tm1Close : function () { if (!this.bTurnOffCallbacks) { var url = this.iframeCtrl.getObjectIDURL(); var url2 = url.replace("TM1WebCubeViewer","TM1WebMain"); url2 += "&Action=Close"; this.iframeCtrl.setUrl(url2); } // remove callback functions to prevent memory leaks if (COGNOS_TM1_webShtWgtToolbarFuncs != null) { COGNOS_TM1_webShtWgtToolbarFuncs["_"+this.iContext.widgetId+"_"] = null; delete COGNOS_TM1_webShtWgtToolbarFuncs["_"+this.iContext.widgetId+"_"]; } if (COGNOS_TM1_webShtWgtFltrFuncs != null) { COGNOS_TM1_webShtWgtFltrFuncs["_"+this.iContext.widgetId+"_"] = null; delete COGNOS_TM1_webShtWgtFltrFuncs["_"+this.iContext.widgetId+"_"]; } return; }, fireFilterChanged : function (dimName, subsetName, elemName) { // alert ("in webjsfunction"); var extraParams = "title_"; extraParams += dimName; extraParams += "="; extraParams += encodeURIComponent(elemName); this.iContext.iEvents.fireEvent("Context filter change", null, extraParams); return; }, refreshDataAction : function () { var url = this.tm1WebURL; url += "/TM1WebMain.aspx?action=OpenObject&type=Cubeviewer&HideToolbar=0&HideTabs=1&TitleChangeCallback=JSFunction($dimName$, $subsetName$, $elemName$)&AdminHost=" + this.tm1Host + "&TM1server=" + this.tm1Server + "&value=" + this.tm1Cube + "$$" + this.tm1CubeView; if ((this.tm1UserName != null) && (this.tm1UserName != "")) { url += "&username="; url += this.tm1UserName; url += "&password="; url += this.tm1Password; } var xmlhttp; xmlhttp=new XMLHttpRequest(); var _endRefreshDataAction = function () { xmlhttp.setRequestHeader ("Cookie", ""); xmlhttp.setRequestHeader ("Cookie", ""); xmlhttp.send(null); }; if (xmlhttp!=null) { xmlhttp.open("GET",url,true); //setTimeout((function(obj){obj.xmlhttp.setRequestHeader ("Cookie", ""); //obj.xmlhttp.setRequestHeader ("Cookie", ""); //obj.xmlhttp.send(null);})(this),15000); setTimeout (_endRefreshDataAction, 15000); } return; }, determineCommonDomain: function () { if (this.commonDomain == null) { this.commonDomain = ""; var buxURL = document.URL; var buxDomain = bux.Helper.extractDomain(buxURL); var tm1WebDomain = bux.Helper.extractDomain(this.tm1WebURL); if (buxDomain.toLowerCase() == tm1WebDomain.toLowerCase()) { return; } else { this.bTurnOffCallbacks = true; /* var buxColonIndex = buxDomain.indexOf(":"); if (buxColonIndex >= 0) { buxDomain = buxDomain.substring(0, buxColonIndex); } var tm1WebColonIndex = tm1WebDomain.indexOf(":"); if (tm1WebColonIndex >= 0) { tm1WebDomain = tm1WebDomain.substring(0, tm1WebColonIndex); } var buxDotIndex = buxDomain.indexOf("."); var tm1WebDotIndex = tm1WebDomain.indexOf("."); if (buxDotIndex >= 0 && tm1WebDotIndex >= 0) { var buxDomainSuffix = buxDomain.substring(buxDotIndex + 1); var tm1DomainSuffix = tm1WebDomain.substring(tm1WebDotIndex + 1); if (buxDomainSuffix.toLowerCase() == tm1DomainSuffix.toLowerCase()) { this.commonDomain = buxDomainSuffix; return; } } */ } } return; }, refreshView : function () { // initialize javascript callback functions // callback functions are stored in an array where the array index // is the context widgetId if (COGNOS_TM1_webShtWgtToolbarFuncs == null) COGNOS_TM1_webShtWgtToolbarFuncs = new Array(); if (COGNOS_TM1_webShtWgtFltrFuncs == null) COGNOS_TM1_webShtWgtFltrFuncs = new Array(); if (COGNOS_TM1_webShtWgtToolbarFuncs["_"+this.iContext.widgetId+"_"] == null) { COGNOS_TM1_webShtWgtToolbarFuncs["_"+this.iContext.widgetId+"_"] = dojo.hitch(this, "createWidgetToolbar"); } if (COGNOS_TM1_webShtWgtFltrFuncs["_"+this.iContext.widgetId+"_"] == null) { COGNOS_TM1_webShtWgtFltrFuncs["_"+this.iContext.widgetId+"_"] = dojo.hitch(this, "fireFilterChanged"); } var url = this.tm1WebURL; url += "/TM1WebMain.aspx?action=OpenObject&type=Websheet&HideTabs=1&AdminHost=" + encodeURIComponent(this.tm1Host) + "&TM1server=" + encodeURIComponent(this.tm1Server) + "&value=" + encodeURIComponent(this.tm1CubeView); this.determineCommonDomain(); if (this.bTurnOffCallbacks /* this.commonDomain != null && this.commonDomain.length > 0 */) { this.tm1InternalToolbar = 1; this.createBasicWidgetToolbar(); // document.domain = this.commonDomain; // url += "&CommonDomain="; // url += encodeURIComponent(this.commonDomain); } else { if (this.tm1InternalToolbar == 1) { url += "&HideToolbar=0"; } else { url += "&HideToolbar=1"; } url += "&toolbarCallbackFunc=COGNOS_TM1_webShtWgtToolbarFuncs._"+encodeURIComponent(this.iContext.widgetId)+"_&TitleChangeCallback=COGNOS_TM1_webShtWgtFltrFuncs._"+encodeURIComponent(this.iContext.widgetId)+"_($dimName$, $subsetName$, $elemName$)"; } if ((this.tm1UserName != null) && (this.tm1UserName != "")) { url += "&username="; url += encodeURIComponent(this.tm1UserName); url += "&password="; if ((this.tm1Password != null) && (this.tm1Password != "")) { url += encodeURIComponent(this.tm1Password); } } if (this.iframeCtrl == null) { this.initializeiframe (url); } else { this.iframeCtrl.setUrl(url); } } }); dojo.provide("webSheetViewerIFrame"); dojo.declare("webSheetViewerIFrame", dijit._Widget, { url: null, iWidget: null, resizeZone: null, iframe: null, recalcURL: null, constructor: function(params) { }, getObjectIDURL: function () { this.recalcURL = null; if (this.iframe.contentDocument) { if (this.iframe.contentDocument.URL == "about:blank") { } else { this.recalcURL = this.iframe.contentDocument.URL; } } else if (this.iframe.contentWindow) { this.recalcURL = this.iframe.contentWindow.location.href; } return this.recalcURL; }, setUrl: function(url) { this.url = url; if (this.iframe) { this.iframe.src = url; } }, assignReturnURL: function () { }, startup: function(inHght) { var ref = this; this.inherited(arguments); this.resizeZone = this.domNode.ownerDocument.createElement("div"); this.domNode.appendChild(this.resizeZone); var dn = (this.iframe = dojo.doc.createElement('iframe')); var url = this.url; var widgetParent = this.iWidget; dn.id = this.id + "_iframe"; dn.style.border = "none"; dn.style.width = "100%"; dn.style.height = inHght + "px"; dn.frameBorder = 0; dn.tabIndex = 0; dn.setAttribute('src', url); dn.setAttribute('scrolling', "no"); this.resizeZone.appendChild(dn); if (dojo.isWebKit) { // Safari seems to always append iframe with src=about:blank setTimeout(function() { dn.setAttribute('src', url) }, 0); } }, resize: function(size) { dijit.layout._LayoutWidget.prototype.resize.apply(this, arguments); }, layout: function() { if (this.iframe.parentNode != null) { if (this.iframe.clientHeight > 0) { this.iframe.style.height = this.iframe.parentNode.parentNode.clientHeight + "px"; } } } });