dojo.provide("TM1WebWebSheetWidget"); dojo.require("bux.i18n"); dojo.require("bux.Helper"); dojo.require("bux.data.UserPreferencesStore"); dojo.require("bux.iwidget.utilities.UtilityWidgetBase"); //For Bux Action Button issue, can't remove dojo.require("bux.dialogs.WidgetPropertiesFromJSON"); //fix for BUX resource loading dojo.declare("TM1WebWebSheetWidget", null, { iframeCtrl: null, iframeCtrlCantLoadDojo: null, dimensionNames: null, elementNames:null, _exportContainer:null, elementNameCounter: 0, filterElement:null, undoRedoStatus:null, subscriptionHandle:null, cubeViewState:null, app: null, app2: null, inDoMore:false, webUrl: null, cantLoadDojo: false, // ====== Multilingual Support - Start ======== _productLocale:null, _tm1messages:null, // ====== Multilingual Support - End ======== _firstVisible:false, onLoad : function() { // ====== Multilingual Support - Start ======== // Remember where we were loaded from: this is our path for future AJAX calls and .js loads dojo.registerModulePath("TM1WebWebSheetWidget",this.iContext.io.rewriteURI("js")); this.setLanguage().then(dojo.hitch(this, "getWidgetAttributes")); // ====== Multilingual Support - End ======== }, loadWithAttributes: function () { var url = this.tm1WebURL; var lastSlashIndex = url.lastIndexOf("/"); this.webUrl = url.substring(0, lastSlashIndex); url += "/scripts/tm1web"; var url2 = this.tm1WebURL; url2 += "/scripts/com"; dojo.registerModulePath("tm1web", url); dojo.registerModulePath("com", url2); if (this.getCookie("tm1webwremote") != "") { this.cantLoadDojo = true; } else { try { dojo.require("tm1web.websheet.Workbooker"); } catch (err) { this.cantLoadDojo = true; document.cookie = "tm1webwremote=true; path=/"; } } this.app = null; if (this.areTM1ParametersValid ()) { this.refreshView(); } else { this.onGetProperties(null, true); } }, getCookie: function (name) { if ( document.cookie.length <= 0 ) return(""); // no cookies var search = name + "="; var offset = document.cookie.indexOf(search); if ( offset == -1 ) return(""); // cookie does not exist offset += search.length; // set index of beginning of value var end = document.cookie.indexOf(";", offset); // set index of end of cookie value if ( end == -1 ) end = document.cookie.length; return(unescape(document.cookie.substring(offset, end))); }, 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("TM1WebWebSheetWidget","tm1ContentWebSheetViewerWidget_msg", curProductLocale); dojo.ready(function() { self._tm1messages = dojo.i18n.getLocalization("TM1WebWebSheetWidget", "tm1ContentWebSheetViewerWidget_msg", curProductLocale); deferred.resolve(); }); return deferred; } }, createBasicWidgetToolbar: function () { 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); }, createWidgetToolbar: function () { 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_SANDBOX_UNDO"); toolbarItems = this.addToolbutton(toolbarItems, "IDM_SANDBOX_REDO"); 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.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_SUPPRESS_ZEROS") { var menuItems = []; menuItems = this.addToolbutton(menuItems, "IDM_SUPPRESS_ZEROS_ROWS_COLUMNS"); menuItems = this.addToolbutton(menuItems, "IDM_SUPPRESS_ZEROS_ROWS"); menuItems = this.addToolbutton(menuItems, "IDM_SUPPRESS_ZEROS_COLUMNS"); 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_CHART-SELECT") { var menuItems = []; menuItems = this.addToolbuttonWithSubmenu (menuItems, "IDM_CHARTTYPE"); 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_CHARTTYPE") { var menuItems = []; //menuItems = this.addToolbutton(menuItems, "IDM_CHART_POINT"); menuItems = this.addToolbutton(menuItems, "IDM_CHART_BUBBLE"); menuItems = this.addToolbutton(menuItems, "IDM_CHART_LINE"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_SPLINE"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_STEPLINE"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_FASTLINE"); menuItems = this.addToolbutton(menuItems, "IDM_CHART_BAR"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_STACKEDBAR"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_STACKEDBAR100"); menuItems = this.addToolbutton(menuItems, "IDM_CHART_COLUMN"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_STACKEDCOLUMN"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_STACKEDCOLUMN100"); menuItems = this.addToolbutton(menuItems, "IDM_CHART_AREA"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_STACKEDAREA"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_STACKEDAREA100"); menuItems = this.addToolbutton(menuItems, "IDM_CHART_PIE"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_DOUGHNUT"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_STOCK"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_CANDLESTICK"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_RANGE"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_SPLINERANGE"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_GANTT"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_RANGECOLUMN"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_RADAR"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_POLAR"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_BOXPLOT"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_FUNNEL"); //menuItems = this.addToolbutton(menuItems, "IDM_CHART_PYRAMID"); 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 = []; if (this.sandboxNames) { menuItems = this.appendSandboxMenuChoice(menuItems, 0, "[Base]", this.sandboxNames.currentSandbox); if (this.sandboxNames.sandboxes.length > 1) { for (i=1; i 0) { this.tm1Password = cookieValue; } } this.loadWithAttributes(); this._firstVisible = true; }, refreshView : function () { if (this.cantLoadDojo) { if (this.iframeCtrlCantLoadDojo) { this.iframeCtrlCantLoadDojo.setUrl(this.getIFrameUrl()); // } else { var widgetTitle = "widgetTitle"; var domObject = this.iContext.getElementById("_" + this.iContext.widgetId + "_" + "widgetFrame"); this.iframeCtrlCantLoadDojo = new tm1.iwidget.utilities.IFrame({ url: this.getIFrameUrl(), // frameTitle: widgetTitle }, domObject); this.iframeCtrlCantLoadDojo.startup(); } this.createBasicWidgetToolbar(); } else { var identity={host:this.tm1Host,userName:this.tm1UserName,password:this.tm1Password,serverName:this.tm1Server,webSheet:this.tm1CubeView}; if (this._exportContainer == null) { this._exportContainer = new dijit.layout.BorderContainer({ gutters: false }, dojo.byId("_" + this.iContext.widgetId + "_" + "widgetFrame2")); this._exportContainer.download = function (url, frameId) { var webUrl = this.webUrl + "/tm1web/" + url; var hiddenFrame = dojo.byId(frameId); if (hiddenFrame == null) { hiddenFrame = dojo.create("iframe", { id: frameId }); dojo.style(hiddenFrame, { display: "none" }); document.body.appendChild(hiddenFrame); } hiddenFrame.src = webUrl; }; this._exportContainer.webUrl = this.webUrl; dojo.addClass(this._exportContainer.domNode, " downloadParent"); } var createPromise = null; dojo.ready(dojo.hitch(this, function(){ // Workbooker needs to be visible when loading, so load offscreen. var div = dojo.create("div", { style: "width: 750px; height: 750px; top: -1000px; position: absolute" }, document.body); this.app = new Workbooker(div, identity, true); createPromise = this.app.create(); createPromise.then(dojo.hitch(this, function() { document.body.removeChild(div); var style = div.style; style.postition = ""; style.top = ""; style.width = "100%"; style.height = "100%"; dojo.place(div, dojo.byId("_" + this.iContext.widgetId + "_" + "widgetFrame")); this.app.resize(); this.createCompleteCallback(); })); })); } }, refreshMore : function () { if (this.app != null) { if (this.subscribeToActiveSheetChangedNotifications) { this.app.unsubscribeFromActiveSheetChangedNotifications(this.subscribeToActiveSheetChangedNotifications); } if (this.subscriptionHandle) { this.app.unsubscribeFromStateChangeUpdates(this.subscriptionHandle); } this.app.dispose(); this.app = null; } if (this.iframeCtrl ) { this.iframeCtrl.setUrl( this.getIFrameUrl());// + "&ObjectId=" + this.widg1.getObjectId()); } else { var widgetTitle = "widgetTitle"; this.iframeCtrl = new tm1.iwidget.utilities.IFrame({ url: this.getIFrameUrl(),// + "&ObjectId=" + this.widg1.getObjectId(), frameTitle: widgetTitle }, this.iContext.getElementById("_" + this.iContext.widgetId + "_" + "widgetFrameA")); this.iframeCtrl.startup(); } }, getIFrameUrl: function () { return this.tm1WebURL + "/TM1WebWebSheeter.jsp?WebSheet=" + this.tm1CubeView + "&ServerName=" + this.tm1Server + "&HostName=" + this.tm1Host + "&UserName=" + this.tm1UserName + "&Password=" + ((this.tm1Password == null) ? "" : this.tm1Password) + "&AccessType=" + this.tm1AccessType; }, createCompleteCallback: function (value) { if (!this.inDoMore) { //this.app.toggleDimensionBar(true); this.createWidgetToolbar(); } if (this.subscribeToActiveSheetChangedNotifications) { try { this.app.unsubscribeFromActiveSheetChangedNotifications(this.subscribeToActiveSheetChangedNotifications); } catch (error) {} } try { this.subscribeToActiveSheetChangedNotifications = this.app.subscribeToActiveSheetChangedNotifications(dojo.hitch(this, this.getActiveSheetChangesCallback)); } catch (error) { this.subscribeToActiveSheetChangedNotifications = null; } this.getActiveSheetChangesCallback(""); // may not be needed if (this.subscriptionHandle) { try { this.app.unsubscribeFromStateChangeUpdates(this.subscriptionHandle); } catch (error) {} } try { this.subscriptionHandle = this.app.subscribeToStateChangeUpdates(dojo.hitch(this, this.getCubeViewStateCallback)); } catch (error) { this.subscriptionHandle = null;; } }, getActiveSheetChangesCallback: function (value) { var dimensionNamePromise = this.app.getDimensionNames(); dimensionNamePromise.promise.then(dojo.hitch(this, function (inDimensionNames) { this.dimensionNames=inDimensionNames; this.elementNameCounter = 0; this.elementNames = []; if (inDimensionNames != null && inDimensionNames.length > 0) { var elementsPromise = this.app.getElementNames(this.dimensionNames[0]); elementsPromise.promise.then( dojo.hitch(this, this.getElementNamesCallback)); } })); }, onView: function(iEvent) { if (this.inDoMore) { this.inDoMore = false; this.refreshView(); } }, onEdit: function(iEvent) { this.refreshView(); // example of a toolbar for edit mode this.iContext.iEvents.fireEvent("com.ibm.bux.widgetchrome.toolbar.init", null, [{ label: "Edit action", iconClass: "bux-toolbar-button-edit", action: "action.edit" }]); }, onMore: function(iEvent) { if (!this.inDoMore) { this.inDoMore = true; this.refreshMore(); } // example of a toolbar for more mode (not supported by BUX right now) // this.iContext.iEvents.fireEvent("com.ibm.bux.widgetchrome.toolbar.init", null, [{ // label: "More action", // iconClass: "bux-toolbar-button-more", // action: "action.more" // }]); }, // ui actions doMode: function(mode) { // switch back to view mode this.iContext.iEvents.fireEvent("onModeChanged", null, { newMode: mode }); }, onModeChanged: function (mode) { }, onToolbarAction: function(evt) { if (evt.payload == "IDM_RESTART") { if (this.app != null) { if (this.subscribeToActiveSheetChangedNotifications) { this.app.unsubscribeFromActiveSheetChangedNotifications(this.subscribeToActiveSheetChangedNotifications); } if (this.subscriptionHandle) { this.app.unsubscribeFromStateChangeUpdates(this.subscriptionHandle); } this.app.dispose(); this.app = null; } this.refreshView(); } else if (this.app == null) { return; } else if (evt.payload == "IDM_RESET") { this.app.resetView (); } else if (evt.payload == "IDM_COMMIT") { this.app.commitSandbox(); } else if (evt.payload == "IDM_SAVEVIEW") { alert ("not implemented yet"); } else if (evt.payload == "IDM_SAVEAS") { alert ("not implemented yet"); } else if (evt.payload == "IDM_SAVEDATACHANGES") { this.app.saveData(); } else if (evt.payload == "IDM_REVIEWDATACHANGES") { alert ("not implemented yet"); } else if (evt.payload == "IDM_RECALCULATE") { this.app.recalculate(); } else if (evt.payload == "IDM_REBUILDACTIVEFORMS") { this.app.rebuildActiveForms(); } else if (evt.payload == "IDM_AUTO_FIT_COL") { this.app.autoFitSelectedColumns(); } else if (evt.payload == "IDM_SLICE_TO_EXCEL") { this.app.displayExportOptions("SLICE"); } else if (evt.payload == "IDM_SNAPSHOT_TO_EXCEL") { this.app.displayExportOptions("SNAPSHOT"); } else if (evt.payload == "IDM_EXPORT_TO_PDF") { this.app.displayExportOptions("PRINTTOPDF"); } else if (evt.payload == "IDM_SUPPRESS_ZEROS_ROWS_COLUMNS") { this.app.SuppressZerosBoth(); this.createWidgetToolbar(); } else if (evt.payload == "IDM_SUPPRESS_ZEROS_ROWS") { this.app.SuppressZerosRows(); this.createWidgetToolbar(); } else if (evt.payload == "IDM_SUPPRESS_ZEROS_COLUMNS") { this.app.SuppressZerosCols(); this.createWidgetToolbar(); } else if (evt.payload == "IDM_CHART") { this.app.ChangeDisplayMode("Chart"); } else if (evt.payload == "IDM_CHARTANDGRID") { this.app.ChangeDisplayMode("GridAndChart"); } else if (evt.payload == "IDM_GRID") { this.app.ChangeDisplayMode("Grid"); } else if (evt.payload == "IDM_CHART_POINT") { this.app.ChartTypeChanged(0); } else if (evt.payload == "IDM_CHART_BUBBLE") { this.app.ChartTypeChanged(1); } else if (evt.payload == "IDM_CHART_LINE") { this.app.ChartTypeChanged(2); } else if (evt.payload == "IDM_CHART_SPLINE") { this.app.ChartTypeChanged(3); } else if (evt.payload == "IDM_CHART_STEPLINE") { this.app.ChartTypeChanged(4); } else if (evt.payload == "IDM_CHART_FASTLINE") { this.app.ChartTypeChanged(5); } else if (evt.payload == "IDM_CHART_BAR") { this.app.ChartTypeChanged(6); } else if (evt.payload == "IDM_CHART_STACKEDBAR") { this.app.ChartTypeChanged(7); } else if (evt.payload == "IDM_CHART_STACKEDBAR100") { this.app.ChartTypeChanged(8); } else if (evt.payload == "IDM_CHART_COLUMN") { this.app.ChartTypeChanged(9); } else if (evt.payload == "IDM_CHART_STACKEDCOLUMN") { this.app.ChartTypeChanged(10); } else if (evt.payload == "IDM_CHART_STACKEDCOLUMN100") { this.app.ChartTypeChanged(11); } else if (evt.payload == "IDM_CHART_AREA") { this.app.ChartTypeChanged(12); } else if (evt.payload == "IDM_CHART_SPLINEAREA") { this.app.ChartTypeChanged(13); } else if (evt.payload == "IDM_CHART_STACKEDAREA") { this.app.ChartTypeChanged(14); } else if (evt.payload == "IDM_CHART_STACKEDAREA100") { this.app.ChartTypeChanged(15); } else if (evt.payload == "IDM_CHART_PIE") { this.app.ChartTypeChanged(16); } else if (evt.payload == "IDM_CHART_DOUGHNUT") { this.app.ChartTypeChanged(17); } else if (evt.payload == "IDM_CHART_STOCK") { this.app.ChartTypeChanged(18); } else if (evt.payload == "IDM_CHART_CANDLESTICK") { this.app.ChartTypeChanged(19); } else if (evt.payload == "IDM_CHART_RANGE") { this.app.ChartTypeChanged(20); } else if (evt.payload == "IDM_CHART_SPLINERANGE") { this.app.ChartTypeChanged(21); } else if (evt.payload == "IDM_CHART_GANTT") { this.app.ChartTypeChanged(22); } else if (evt.payload == "IDM_CHART_RANGECOLUMN") { this.app.ChartTypeChanged(23); } else if (evt.payload == "IDM_CHART_RADAR") { this.app.ChartTypeChanged(24); } else if (evt.payload == "IDM_CHART_POLAR") { this.app.ChartTypeChanged(25); } else if (evt.payload == "IDM_CHART_BOXPLOT") { this.app.ChartTypeChanged(26); } else if (evt.payload == "IDM_CHART_FUNNEL") { this.app.ChartTypeChanged(27); } else if (evt.payload == "IDM_CHART_PYRAMID") { this.app.ChartTypeChanged(28); } else if (evt.payload == "IDM_RESET_DATA") { this.app.resetData(); } else if (evt.payload == "IDM_SANDBOX_UNDO") { this.app.undo(); } else if (evt.payload == "IDM_SANDBOX_REDO") { this.app.redo(); } else if (evt.payload == "IDM_CREATE_SANDBOX") { this.app.createSandbox(); } else if (evt.payload == "IDM_DELETE_SANDBOX") { this.app.deleteSandboxes(); } else if (evt.payload.substring(0, 13) == "SANDBOXCHOICE") { var sandBoxId = evt.payload.substring(13, evt.payload.length); if (sandBoxId == 0) { this.app.setActiveSandbox("[Base]"); } else { this.app.setActiveSandbox(this.sandboxNames.sandboxes[sandBoxId].name); } } }, getCubeViewStateCallback: function ( inCubeViewState) { this.cubeViewState = inCubeViewState; var sandboxPromise = this.app.getSandboxes(); sandboxPromise.then(dojo.hitch(this, this.getSandboxNamesCallback)); }, getSandboxNamesCallback: function( inSandboxNames ) { this.sandboxNames = inSandboxNames; this.createWidgetToolbar(); }, getElementNamesCallback: function( elements ) { this.elementNames[this.elementNameCounter++] = elements; if (this.elementNameCounter < this.dimensionNames.length) { var elementsPromise = this.app.getElementNames(this.dimensionNames[this.elementNameCounter]); elementsPromise.promise.then( dojo.hitch(this, this.getElementNamesCallback ) ); } else { this.setExistingFilters(); } }, setExistingFilters: function () { if (this.tm1FiltersToSetPayload != null) { for (var filters = 0; filters < this.tm1FiltersToSetPayload.length; filters++) { try { var filterPayload = this.tm1FiltersToSetPayload[filters]; var selectValueControl = this.tm1FiltersToSetPayload[filters]["com.ibm.widget.context.bux.selectValueControl"].selectValueControl; var itemSpecification = "/content/package[@name='" + this.filterPackages + "']"; var itemSpec2 = this.tm1FiltersToSetPayload[filters]["com.ibm.widget.context.bux.selectValueControl"].selectValueControl.itemSpecification[itemSpecification]; var correctDimName = null; for (var i = 0; i < this.dimensionNames.length; i++) { correctDimName = itemSpec2[this.dimensionNames[i]]; if (correctDimName != null) { break; } } if (correctDimName != null) { var itemSpec3 = correctDimName.values[0].mun; this.app.filterElement(itemSpec3); } } catch (err) { } } // this.filtersToSetPayload = null; } }, onGetCanvasContextDone: function (evt) { if (evt != null && typeof evt != "undefined" && evt.payload && evt.payload.length != 0) { this.tm1FiltersToSetPayload = evt.payload; var filterPayload = (evt.type == "string" ? evt.payload : dojo.toJson(evt.payload)); this.iContext.getiWidgetAttributes().setItemValue("filtersToSetPayload", filterPayload); } }, getElementNameFromMUN: function(mun) { var positionInMUN = ".["; var indexInMUN = mun.lastIndexOf(positionInMUN); var elementName = mun.substring(indexInMUN + positionInMUN.length); elementName = elementName.substring(0, elementName.indexOf("]")); return elementName; }, getMUN: function(dimensionName, elementName) { // { caption: "Europe", mun: "[plan_BudgetPlan].[plan_business_unit].[plan_business_unit]->:[TM].[plan_business_unit].[plan_business_unit].[@Member].[Europe]" }, var mun = "["; mun += this.iContext.getiWidgetAttributes().getItemValue("tm1CubeView"); mun += "].["; mun += dimensionName; mun += "].["; mun += dimensionName; mun += "]->:[TM].["; mun += dimensionName; mun += "].["; mun += dimensionName; mun += "].[@MEMBER].["; mun += elementName; mun += "]"; return mun; }, createMunFromFacet: function(facetMun) { // { caption: "Europe", mun: "[plan_BudgetPlan].[plan_business_unit].[plan_business_unit]->:[TM].[plan_business_unit].[plan_business_unit].[@Member].[Europe]" }, var lastOpenBracketIndex = facetMun.lastIndexOf("["); var elementName = facetMun.substring(lastOpenBracketIndex); elementName = elementName.substring(1, elementName.length - 1); var dimensionName = facetMun.substring(1, lastOpenBracketIndex - 2); var mun = "["; mun += this.iContext.getiWidgetAttributes().getItemValue("tm1CubeView"); mun += "].["; mun += dimensionName; mun += "].["; mun += dimensionName; mun += "]->:[TM].["; mun += dimensionName; mun += "].["; mun += dimensionName; mun += "].[@MEMBER].["; mun += elementName; mun += "]"; return mun; }, onFilter: function(evt) { if( evt != null && typeof evt != "undefined" && this.app != null) { var parms = eval("(" + evt.payload + ")"); this.app.filterElement(parms.values[0].values[0].mun); } }, onGenericSelectValueControl: function(evt) { if( evt != null && typeof evt != "undefined" && this.app != null) { try { var filterPayload = (evt.type=="string" ? evt.payload : dojo.toJson(evt.payload)); var selectValueControl = evt.payload["com.ibm.widget.context.bux.selectValueControl"].selectValueControl; var itemSpecification = "/content/package[@name='" + this.filterPackages + "']"; var itemSpec2 = evt.payload["com.ibm.widget.context.bux.selectValueControl"].selectValueControl.itemSpecification[itemSpecification]; var correctDimName = null; for (var i = 0; i < this.dimensionNames.length; i++) { correctDimName = itemSpec2[this.dimensionNames[i]]; if (correctDimName != null) { break; } } var itemSpec3 = correctDimName.values[0].mun; this.app.filterElement(itemSpec3); } catch (err) {} } }, onGetFilterableItems: function( evt ) { var payload = { "invisible": {}, "visible": {}}; if (this.dimensionNames != null && this.elementNames != null && this.elementNames[0] != null) { var visibleDimensions = []; for (var i=0;i:[TM].[plan_chart_of_accounts].[plan_chart_of_accounts].[@MEMBER].[Revenue] var filterDimension = evt.payload.payload.name; var pathInfo = "/content/package[@name='" + this.filterPackages + "']"; var payload = { name: filterDimension, modelInfo: { path: pathInfo }, values: [] }; var dimensionIndex = this.getDimensionIndex (filterDimension); if (dimensionIndex > -1) { for (var i=0; i < this.elementNames[dimensionIndex].length; i++) { payload.values[i] = { caption: this.elementNames[dimensionIndex][i].alias, modelInfo: { path: pathInfo}, mun: this.getMUN(filterDimension,this.elementNames[dimensionIndex][i].name) }; } } this.iContext.iEvents.fireEvent("com.ibm.bux.filter.values.get.done", null, payload); }, onUnload: function (evt) { if(this.recalPromise) { this.recalPromise.then(dojo.hitch(this, this.doOnUnload)); } else { this.doOnUnload(); } this.unloaded = true; }, doOnUnload: function() { if (this.app) { if (this.subscribeToActiveSheetChangedNotifications) { this.app.unsubscribeFromActiveSheetChangedNotifications(this.subscribeToActiveSheetChangedNotifications); } if (this.subscriptionHandle) { this.app.unsubscribeFromStateChangeUpdates(this.subscriptionHandle); } this.app.dispose(); } if (this.iframeCtrl != null) { this.iframeCtrl.destroy(); } if (this.iframeCtrlCantLoadDojo != null) { this.iframeCtrlCantLoadDojo.destroy(); } }, onSetVisible: function(evt) { if(!this.unloaded) { if (evt.payload.isVisible) { if (this.app != null) { this.recalPromise = this.app.recalculate(); } } } }, onWidgetRefresh: function(evt) // Invoked when User preferences get modified (Including locales) { if (this.app != null) { this.app.recalculate(); } return; }, onWidgetSave: function() { var saveDonePayload = {'status':true}; this.iContext.iEvents.fireEvent("com.ibm.bux.widget.save.done", null, saveDonePayload); }, onWidgetResize: function(e) { if (this.inDoMore) { var newWidth = e.payload.resize.w; var newHeight = e.payload.resize.h; this.iframeCtrl.resize({ w: newWidth, h: newHeight - 40 }); } else if (this.cantLoadDojo) { var newWidth = e.payload.resize.w; var newHeight = e.payload.resize.h; this.iframeCtrlCantLoadDojo.resize({ w: newWidth, h: newHeight }); } else { if (!this._preferredSizeSet) { if(!this._firstVisible) { setTimeout(dojo.hitch(this, this.onWidgetResize, e), 10); return; } var attributes = this.iContext.getiWidgetAttributes(); var width = parseInt(((this.tm1Width != null) && (this.tm1Width > 0)) ? this.tm1Width : attributes.getItemValue("viewWidth")); var height = parseInt(((this.tm1Height != null) && (this.tm1Height > 0)) ? this.tm1Height : attributes.getItemValue("viewHeight")); var chromeObjectId = bux.Helper.widgetIdToChromeId(this.iContext.widgetId); var chromeObject = bux.Helper.getChromeById(chromeObjectId); chromeObject.setPreferredSize({w: width, h: height}); this._preferredSizeSet = true; chromeObject.doChromeAutoResize(); } if (this.app != null) { this.app.resize(); this.tm1Height = e.payload.resize.h; this.tm1Width = e.payload.resize.w; this.iContext.getiWidgetAttributes().setItemValue("tHeight", this.tm1Height); this.iContext.getiWidgetAttributes().setItemValue("tWidth", this.tm1Width); } } }, onGetProperties: function (evt, init) { /* var attributes = this.iContext.getiWidgetAttributes(); var _properties = { 'label': this.iContext.getiWidgetAttributes().getItemValue("tm1Host"), 'serverLabel': this.iContext.getiWidgetAttributes().getItemValue("tm1Server"), 'cubeLabel': this.iContext.getiWidgetAttributes().getItemValue("tm1Cube"), 'cubeViewLabel': this.iContext.getiWidgetAttributes().getItemValue("tm1CubeView"), 'userNameLabel': this.iContext.getiWidgetAttributes().getItemValue("tm1UserName"), 'passwordLabel': this.iContext.getiWidgetAttributes().getItemValue("tm1Password") }; var propertiesDialog = new CubeViewPropertiesPane({ properties: _properties, title: dojo.string.substitute(BUXMSG.WDG.IDS_WDG_PROPERTIES_DIALOG_TITLE, [attributes.getItemValue("widgetTitle")]), sourceWidget: this, cancelPropertiesCallback: (init) ? dojo.hitch(this, this._onCancelProperties) : null }); this._propertiesDialog = propertiesDialog; var _payload = {properties: _properties, propertiesDialogSpec:null, propertiesDialogTab: propertiesDialog}; this.iContext.iEvents.fireEvent("com.ibm.bux.widget.properties.get.done", null, _payload); */ }, _onCancelProperties: function() { if (this._firstRender == true) { var chromeObjectId = bux.Helper.widgetIdToChromeId(this.iContext.widgetId); var chromeObject = bux.Helper.getChromeById(chromeObjectId); chromeObject.widgetRemoveConfirmed(); } }, onSetProperties: function(evt) { if (evt.payload.properties) { var attributes = this.iContext.getiWidgetAttributes(); var host = this._propertiesDialog.labelInput.value; var server = this._propertiesDialog.serverLabelInput.value; var cube = this._propertiesDialog.cubeLabelInput.value; var cubeView = this._propertiesDialog.cubeViewLabelInput.value; var userName = this._propertiesDialog.userNameLabelInput.value; var password = this._propertiesDialog.passwordLabelInput.value; if (host != attributes.getItemValue("tm1Host") || server != attributes.getItemValue("tm1Server") || cube != attributes.getItemValue("tm1Cube") || cubeView != attributes.getItemValue("tm1CubeView") || userName != attributes.getItemValue("tm1UserName") || password != attributes.getItemValue("tm1Password")) { this.tm1Host = host; this.tm1Server = server; this.tm1Cube = cube; this.tm1CubeView = cubeView; this.tm1UserName = userName; this.tm1Password = password; // attributes.save(); this.refreshView(); } return; } }, _onCancelProperties: function () { if (this._firstRender == true) { this.removeWidget(); } }, removeWidget: function () { var chromeObjectId = bux.Helper.widgetIdToChromeId(this.iContext.widgetId); var chromeObject = bux.Helper.getChromeById(chromeObjectId); chromeObject.widgetRemoveConfirmed(); }, _excludeList: ["copyright", "version"], _getProps: function(asDialog) { console.log ("_getProps"); var results = {}; var names = this.iContext.getiWidgetAttributes().getAllNames(); for (var i = 0, l = names.length; i < l; i++) { var name = names[i]; if (-1 != dojo.indexOf(this._excludeList, name)) { // skip read-only attributes // BUG: can't use enabler's isReadOnly() fails with a bizare javascript error. continue; } var value = this.iContext.getiWidgetAttributes().getItemValue(name); results[name] = (asDialog) ? { value: value } : value; } return results; } }); dojo.provide("tm1.iwidget.utilities.IFrame"); dojo.declare("tm1.iwidget.utilities.IFrame", dijit._Widget, { url: null, frameTitle: null, resizeZone: null, iframe: null, constructor: function(params) { }, setUrl: function(url) { this.url = url; if (this.iframe) { this.iframe.src = this.prepareUrl(url); } }, prepareUrl: function(url) { if (url === null || url === "") { return url; } url = bux.Helper.normalizeURL(url); return url; }, setFrameTitle: function(title) { this.frameTitle = title; if (this.iframe) { this.iframe.title = bux.Encodings.htmlencode(title); } }, startup: function() { this.inherited(arguments); var dn = this.domNode; this.resizeZone = dn.ownerDocument.createElement("div"); dn.appendChild(this.resizeZone); dn = (this.iframe = dojo.doc.createElement('iframe')); var url = this.url; dn.id = this.id + "_iframe"; dn.style.border = "none"; dn.style.width = "100%"; dn.frameBorder = 0; dn.tabIndex = 0; dn.title = this.frameTitle; dn.setAttribute('src', this.prepareUrl(url)); this.resizeZone.appendChild(dn); if (dojo.isWebKit) { setTimeout(function() { dn.setAttribute('src', this.prepareUrl(url)); }, 0); } }, resize: function(size) { dijit.layout._LayoutWidget.prototype.resize.apply(this, arguments); if (dojo.isWebKit) { this.domNode.style.display = "none"; setTimeout(dojo.hitch(this, function(){ this.domNode.style.display = ""; }), 1); } }, layout: function() { this.resizeZone.style.height = this._contentBox.h + "px"; if (this.iframe) { this.iframe.style.height = "100%"; } } });