/* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: Viewer *| (C) Copyright IBM Corp. 2001, 2016 *| *| US Government Users Restricted Rights - Use, duplication or *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *| *+------------------------------------------------------------------------+ */ /** * Implements authored drill through */ function AuthoredDrillAction() { this.m_drillTargetSpecification = ""; } AuthoredDrillAction.prototype = new CognosViewerAction(); AuthoredDrillAction.prototype.setRequestParms = function(drillTargetSpecification) { this.m_drillTargetSpecification = drillTargetSpecification; }; AuthoredDrillAction.prototype.executeDrillTarget = function(drillTargetSpecification) { var drillTargetNode = XMLHelper_GetFirstChildElement( XMLBuilderLoadXMLFromString (drillTargetSpecification) ); var sBookmarkRef = encodeURIComponent(drillTargetNode.getAttribute("bookmarkRef")); var sTargetPath = drillTargetNode.getAttribute("path"); var bShowInNewWindow = this._shouldShowInNewWindow(drillTargetNode); var oCV = this.getCognosViewer(); if((sBookmarkRef !== null && sBookmarkRef !== "") && (sTargetPath === null || sTargetPath === "")) { var sBookmarkPage = drillTargetNode.getAttribute("bookmarkPage"); if (sBookmarkPage && sBookmarkPage !== "") { oCV.executeAction("GotoPage",{ "pageNumber": sBookmarkPage,"anchorName": sBookmarkRef} ); } else { document.location = "#" + sBookmarkRef; } } else { var sTarget = ""; if(bShowInNewWindow) { sTarget = "_blank"; } var aArguments = []; var objPathArguments = []; objPathArguments.push("obj"); objPathArguments.push(sTargetPath); aArguments[aArguments.length] = objPathArguments; var bHasPropertyToPass = false; var drillParameterArguments, drillParameterNode, sValue, sName, sNil; var drillParameterNodes = XMLHelper_FindChildrenByTagName(drillTargetNode, "drillParameter", false); for(var index = 0; index < drillParameterNodes.length; ++index) { drillParameterArguments = []; drillParameterNode = drillParameterNodes[index]; sValue = drillParameterNode.getAttribute("value"); sName = drillParameterNode.getAttribute("name"); if(sValue !== null && sValue !== "") { drillParameterArguments.push("p_" + sName); drillParameterArguments.push(this.buildSelectionChoicesSpecification(drillParameterNode)); } sNil = drillParameterNode.getAttribute("nil"); if(sNil !== null && sNil !== "") { drillParameterArguments.push("p_" + sName); drillParameterArguments.push(this.buildSelectionChoicesNilSpecification()); } if(drillParameterArguments.length > 0) { aArguments[aArguments.length] = drillParameterArguments; } if( !bHasPropertyToPass){ var sPropertyToPass = drillParameterNode.getAttribute( "propertyToPass"); bHasPropertyToPass = ( sPropertyToPass && sPropertyToPass.length > 0 ) ? true : false; } } var sMethod = drillTargetNode.getAttribute("method"); var sOutputFormat = drillTargetNode.getAttribute("outputFormat"); var sOutputLocale = drillTargetNode.getAttribute("outputLocale"); var sPrompt = drillTargetNode.getAttribute("prompt"); var dynamicDrill = drillTargetNode.getAttribute("dynamicDrill"); var sSourceContext = this.getXMLNodeAsString(drillTargetNode, "parameters"); var sObjectPaths = this.getXMLNodeAsString(drillTargetNode, "objectPaths"); var oCVId = oCV.getId(); // if the source and target are the same report, and the prompt attribute in drill definition is not set to true, and we're not opening a new window, then do a forward instead of a drillThrough action var formWarpRequest = document.forms["formWarpRequest" + oCVId]; var callForward = oCV.getAdvancedServerProperty("VIEWER_JS_CALL_FORWARD_DRILLTHROUGH_TO_SELF"); if ( (!callForward || callForward.toLowerCase() !== "false") && sPrompt != "true" && this.isSameReport(formWarpRequest, sTargetPath) && this.isSameReportFormat(sOutputFormat) && !bShowInNewWindow && !bHasPropertyToPass ) { var cognosViewerRequest = new ViewerDispatcherEntry(oCV); cognosViewerRequest.addFormField("ui.action", "forward"); if(oCV !== null && typeof oCV.rvMainWnd != "undefined") { oCV.rvMainWnd.addCurrentReportToReportHistory(); var reportHistorySpecification = oCV.rvMainWnd.saveReportHistoryAsXML(); cognosViewerRequest.addFormField("cv.previousReports", reportHistorySpecification); } // if we're drilling through to ourself we need to send empty parameters for // the parameters that are setup to no send any parameter values for(index = 0; index < drillParameterNodes.length; ++index) { drillParameterArguments = []; drillParameterNode = drillParameterNodes[index]; sValue = drillParameterNode.getAttribute("value"); sName = drillParameterNode.getAttribute("name"); sNil = drillParameterNode.getAttribute("nil"); if((sNil === null || sNil === "") && (sValue === null || sValue === "")) { drillParameterArguments.push("p_" + sName); drillParameterArguments.push(this.buildSelectionChoicesNilSpecification()); } if(drillParameterArguments.length > 0) { aArguments[aArguments.length] = drillParameterArguments; } } for (index=1; index < aArguments.length; index++) { cognosViewerRequest.addFormField(aArguments[index][0], aArguments[index][1]); } cognosViewerRequest.addFormField("_drillThroughToSelf", "true"); // If we're dealing with a tabbed report and drilling to ourselves, then make sure we show the first tab when the report refreshes if (oCV.m_tabsPayload && oCV.m_tabsPayload.tabs) { cognosViewerRequest.addFormField("generic.anyURI.http://developer.cognos.com/ceba/constants/runOptionEnum#pageGroup", oCV.m_tabsPayload.tabs[0].id) } oCV.setUsePageRequest(true); oCV.dispatchRequest(cognosViewerRequest); if (typeof oCV.m_viewerFragment == "undefined") { var objectRef = getCognosViewerObjectRefAsString(oCVId); setTimeout(objectRef+".getRequestIndicator().show()",10); } } else { doSingleDrill(sTarget, aArguments, sMethod, sOutputFormat, sOutputLocale, sBookmarkRef, sSourceContext, sObjectPaths, this.getCognosViewer().getId(), sPrompt, dynamicDrill); } } }; AuthoredDrillAction.prototype._shouldShowInNewWindow = function(drillTargetNode) { return drillTargetNode.getAttribute("showInNewWindow") == "true"; }; AuthoredDrillAction.prototype.isSameReport = function( formWarpRequest, sTargetPath ) { if( formWarpRequest["ui.object"] && sTargetPath == formWarpRequest["ui.object"].value ) { return true; } return false; }; AuthoredDrillAction.prototype.isSameReportFormat = function( drillTargetFormat ) { var drillSourceFormat = this.getCognosViewer().envParams["run.outputFormat"]; if( drillSourceFormat ) { if (drillTargetFormat == drillSourceFormat ) { return true; } //the following case occurs when the target drill-thru definition is set to default format // and the source format is HTML. else if( drillSourceFormat == "HTML" && drillTargetFormat == "HTMLFragment") { return true; } } return false; }; AuthoredDrillAction.prototype.getXMLNodeAsString = function(drillTargetNode, sNodeName) { var sXML = ""; if(drillTargetNode != null) { var node = XMLHelper_FindChildByTagName(drillTargetNode, sNodeName, false); if(node != null) { sXML = XMLBuilderSerializeNode(node); } } return sXML; }; AuthoredDrillAction.prototype.execute = function(rvDrillTargetsSpecification) { if(this.m_drillTargetSpecification != "") { this.executeDrillTarget(this.m_drillTargetSpecification); } else if(typeof rvDrillTargetsSpecification != "undefined") { var drillTargetSpecifications = this.getCognosViewer().getDrillTargets(); var rvDrillTargetsNode = this.getAuthoredDrillThroughContext(rvDrillTargetsSpecification, drillTargetSpecifications); var drillTargets = rvDrillTargetsNode.childNodes; if(drillTargets.length == 1) { this.executeDrillTarget(XMLBuilderSerializeNode(drillTargets[0])); } else { doMultipleDrills(XMLBuilderSerializeNode(rvDrillTargetsNode), this.getCognosViewer().getId()); //Need support from goto page //this.showDrillTargets(drillTargets); } } }; AuthoredDrillAction.prototype.showDrillTargets = function(drillTargets) { var sAuthoredDrillThroughContext = ""; for(var index = 0; index < drillTargets.length; ++index) { var drillTarget = drillTargets[index]; sAuthoredDrillThroughContext += ""; var sName = drillTarget.getAttribute("label"); sAuthoredDrillThroughContext += ""; sAuthoredDrillThroughContext += sXmlEncode(sName); sAuthoredDrillThroughContext += ""; var sDrillThroughSearchPath = drillTarget.getAttribute("path"); sAuthoredDrillThroughContext += ""; sAuthoredDrillThroughContext += sXmlEncode(sDrillThroughSearchPath); sAuthoredDrillThroughContext += ""; var sDrillThroughAction = drillTarget.getAttribute("method"); sAuthoredDrillThroughContext += ""; sAuthoredDrillThroughContext += sXmlEncode(sDrillThroughAction); sAuthoredDrillThroughContext += ""; var sDrillThroughFormat = drillTarget.getAttribute("outputFormat"); sAuthoredDrillThroughContext += ""; sAuthoredDrillThroughContext += sXmlEncode(sDrillThroughFormat); sAuthoredDrillThroughContext += ""; var sData = "parent." + this.getTargetReportRequestString(drillTarget); sAuthoredDrillThroughContext += ""; sAuthoredDrillThroughContext += sXmlEncode(sData); sAuthoredDrillThroughContext += ""; sAuthoredDrillThroughContext += ""; } sAuthoredDrillThroughContext += ""; // need to fix the ui.backURL and errURL since they'll be getting rejected by caf. TODO post BSEINS //cvLoadDialog(this.getCognosViewer(), {"m":"portal/goto.xts","ui.backURL":"javascript:parent.destroyCModal();", "errURL":"javascript:parent.destroyCModal();","authoredDrillthru":sAuthoredDrillThroughContext}, 600, 425); }; AuthoredDrillAction.prototype.populateContextMenu = function(rvDrillTargetsSpecification) { var viewer = this.getCognosViewer(); var toolbarCtrl = viewer.rvMainWnd.getToolbarControl(); var authoredDrillDropDownMenu = null; if (typeof toolbarCtrl != "undefined" && toolbarCtrl != null) { var toolbarButton = toolbarCtrl.getItem("goto"); if (toolbarButton) { authoredDrillDropDownMenu = toolbarButton.getMenu(); } } var cognosViewerContextMenu = viewer.rvMainWnd.getContextMenu(); var authoredDrillContextMenu = null; if (typeof cognosViewerContextMenu != "undefined" && cognosViewerContextMenu != null) { authoredDrillContextMenu = cognosViewerContextMenu.getGoToMenuItem().getMenu(); } if(authoredDrillDropDownMenu != null || authoredDrillContextMenu != null) { var drillTargetSpecifications = this.getCognosViewer().getDrillTargets(); var rvDrillTargetsNode = this.getAuthoredDrillThroughContext(rvDrillTargetsSpecification, drillTargetSpecifications); var drillTargets = rvDrillTargetsNode.childNodes; if(drillTargets.length > 0) { for(var index = 0; index < drillTargets.length; ++index) { var drillTarget = drillTargets[index]; var sRequestString = getCognosViewerObjectRefAsString(this.getCognosViewer().getId()) + ".m_oDrillMgr.executeAuthoredDrill(\"" + encodeURIComponent(XMLBuilderSerializeNode(drillTarget)) + "\");"; var sIconPath = this.getTargetReportIconPath(drillTarget); var sLabel = drillTarget.getAttribute("label"); if(isViewerBidiEnabled()){ var bidi = BidiUtils.getInstance(); sLabel = bidi.btdInjectUCCIntoStr(sLabel, getViewerBaseTextDirection()); } if (authoredDrillDropDownMenu != null) { new CMenuItem(authoredDrillDropDownMenu, sLabel, sRequestString, sIconPath, gMenuItemStyle, viewer.getWebContentRoot(), viewer.getSkin()); } if (authoredDrillContextMenu != null) { new CMenuItem(authoredDrillContextMenu, sLabel, sRequestString, sIconPath, gMenuItemStyle, viewer.getWebContentRoot(), viewer.getSkin()); } } } } }; AuthoredDrillAction.prototype.buildSelectionChoicesNilSpecification = function() { return ""; }; AuthoredDrillAction.prototype.buildSelectionChoicesSpecification = function(drillParameterNode) { var sSelectionChoicesSpecification = ""; var sValue = drillParameterNode.getAttribute("value"); if(sValue != null) { var propToPass = drillParameterNode.getAttribute("propertyToPass"); sSelectionChoicesSpecification += " if(sValue.indexOf("") != -1) { sSelectionChoicesSpecification += sValue.substring(sValue.indexOf("") + 15); } else if(sValue != "") { sSelectionChoicesSpecification += "= drillTargetSpecifications.length) { continue; } var drillTargetRef = drillTargetSpecifications[drillTargetRefIdx]; if(typeof drillTargetRef != "object") { continue; } drillTargetElement.setAttribute("outputFormat", drillTargetRef.getOutputFormat()); drillTargetElement.setAttribute("outputLocale", drillTargetRef.getOutputLocale()); drillTargetElement.setAttribute("prompt", drillTargetRef.getPrompt()); drillTargetElement.setAttribute("dynamicDrill", drillTargetRef.isDynamicDrillThrough() ? "true" : "false"); var useLabel = drillTargets[drillTargetIdx].getAttribute("label"); if(useLabel === null || useLabel === "") { useLabel = drillTargetRef.getLabel(); } drillTargetElement.setAttribute("label", useLabel); drillTargetElement.setAttribute("path", drillTargetRef.getPath()); drillTargetElement.setAttribute("showInNewWindow", drillTargetRef.getShowInNewWindow()); drillTargetElement.setAttribute("method", drillTargetRef.getMethod()); var currentRvDrillTargetNode = rvDrillTargetNodes; var oParameterProperties = ""; var drillTargetParamProps = drillTargetRef.getParameterProperties(); if (typeof drillTargetParamProps != "undefined" && drillTargetParamProps != null && drillTargetParamProps != "") { oParameterProperties = XMLHelper_GetFirstChildElement(XMLBuilderLoadXMLFromString(drillTargetRef.getParameterProperties())); } while(currentRvDrillTargetNode) { var drillParameters = currentRvDrillTargetNode.childNodes[drillTargetIdx].childNodes; for(var drillParamIdx = 0; drillParamIdx < drillParameters.length; ++drillParamIdx) { var drillParameterElement = drillParameters[drillParamIdx].cloneNode(true); if (oParameterProperties) { var propertyToPass = this.getPropertyToPass(drillParameterElement.getAttribute("name"), oParameterProperties); if (propertyToPass != null && propertyToPass != "") { drillParameterElement.setAttribute("propertyToPass", propertyToPass); } } drillTargetElement.appendChild(drillParameterElement); } currentRvDrillTargetNode = currentRvDrillTargetNode.nextSibling; } var rootOpenTag = ''; var rootCloseTag = ''; var drillTargetParametersString = rootOpenTag + drillTargetRef.getParameters() + rootCloseTag; var drillTargetParametersXML = XMLBuilderLoadXMLFromString(drillTargetParametersString); var oChild = XMLHelper_GetFirstChildElement( XMLHelper_GetFirstChildElement( drillTargetParametersXML ) ); if (oChild) { drillTargetElement.appendChild(oChild.cloneNode(true)); } var drillTargetObjectPathsString = rootOpenTag + drillTargetRef.getObjectPaths() + rootCloseTag; var drillTargetObjectPathsXML = XMLBuilderLoadXMLFromString(drillTargetObjectPathsString); oChild = XMLHelper_GetFirstChildElement( XMLHelper_GetFirstChildElement( drillTargetObjectPathsXML ) ); if (oChild) { drillTargetElement.appendChild(oChild.cloneNode(true)); } } return XMLHelper_GetFirstChildElement(rvDrillTargetsElement); };