123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Viewer
- *| (C) Copyright IBM Corp. 2001, 2013
- *|
- *| US Government Users Restricted Rights - Use, duplication or
- *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *|
- *+------------------------------------------------------------------------+
- */
- /**
- * CognosViewerAction constructor (base class for all cognos viewer action
- * @constructor
- */
- function CognosViewerAction()
- {
- this.m_oCV = null;
- }
- CognosViewerAction.prototype.setRequestParms = function( parms ){};
- CognosViewerAction.prototype.onMouseOver = function(evt) { return false; };
- CognosViewerAction.prototype.onMouseOut = function(evt) { return false; };
- CognosViewerAction.prototype.onMouseDown = function(evt) { return false; };
- CognosViewerAction.prototype.onClick = function(evt) { return false; };
- CognosViewerAction.prototype.onDoubleClick = function(evt) { return false; };
- CognosViewerAction.prototype.updateMenu = function(jsonSpec) { return jsonSpec; };
- CognosViewerAction.prototype.addAdditionalOptions = function(request) {};
- CognosViewerAction.prototype.genSelectionContextWithUniqueCTXIDs = function() { return false; };
- CognosViewerAction.prototype.doUndo = function() {if(typeof console != "undefined") { console.log("Required method doUndo not implemented.");}};
- CognosViewerAction.prototype.doRedo = function() {if(typeof console != "undefined") { console.log("Required method doRedo not implemented.");}};
- CognosViewerAction.prototype.forceRunSpecRequest = function() {return false;};
- /**
- * Method that gets called before the action context gets built. If
- * there's anything special that the action needs to do, they should
- * override this method.
- */
- CognosViewerAction.prototype.preProcess = function() {};
- /**
- * Sets the cognos viewer object (called by the action factory
- * @param CCognosViewer object
- * @private
- */
- CognosViewerAction.prototype.setCognosViewer = function(oCV)
- {
- this.m_oCV = oCV;
- };
- /**
- * Returns an instance to the cognos viewer object
- * @return CCognosViewer object
- */
- CognosViewerAction.prototype.getCognosViewer = function()
- {
- return this.m_oCV;
- };
- CognosViewerAction.prototype.getUndoRedoQueue = function()
- {
- if (this.getCognosViewer().getViewerWidget()) {
- return this.getCognosViewer().getViewerWidget().getUndoRedoQueue();
- }
- return null;
- };
- CognosViewerAction.prototype.getViewerWidget = function()
- {
- return this.m_oCV.getViewerWidget();
- };
- /**
- * Returns the object display name (custom name/report name/report part name)
- */
- CognosViewerAction.prototype.getObjectDisplayName = function()
- {
- var displayName = "";
- if(this.m_oCV != null)
- {
- if(typeof this.m_oCV.envParams["reportpart_id"] != "undefined")
- {
- displayName = this.m_oCV.envParams["reportpart_id"];
- }
- else if(typeof this.m_oCV.envParams["ui.name"] != "undefined")
- {
- displayName = this.m_oCV.envParams["ui.name"];
- }
- }
- return displayName;
- };
- /**
- * Gets the container Id
- */
- CognosViewerAction.prototype.getContainerId = function(selectionController) {
- var container = "";
- if (selectionController && selectionController.getAllSelectedObjects) {
- var allSel = selectionController.getAllSelectedObjects();
- if (allSel) {
- var selection = allSel[0];
- if (selection && selection.getLayoutElementId) {
- container = this.removeNamespace(selection.getLayoutElementId());
- }
- }
- }
- return container;
- };
- CognosViewerAction.prototype.removeNamespace = function(value)
- {
- var originalValue = value;
- try
- {
- if(value != "")
- {
- var idIndex = value.indexOf(this.m_oCV.getId());
- if(idIndex != -1)
- {
- value = value.replace(this.m_oCV.getId(), "");
- }
- }
- return value;
- }
- catch(e)
- {
- return originalValue;
- }
- };
- CognosViewerAction.prototype.doAddActionContext = function()
- {
- return true;
- };
- CognosViewerAction.prototype.getSelectionContext = function()
- {
- return getViewerSelectionContext(this.m_oCV.getSelectionController(), new CSelectionContext(this.m_oCV.envParams["ui.object"]), this.genSelectionContextWithUniqueCTXIDs());
- };
- CognosViewerAction.prototype.getNumberOfSelections = function()
- {
- var numberOfSelections = -1;
- if(this.m_oCV != null && this.m_oCV.getSelectionController() != null)
- {
- numberOfSelections = this.m_oCV.getSelectionController().getSelections().length;
- }
- return numberOfSelections;
- };
- CognosViewerAction.prototype.buildDynamicMenuItem = function(jsonSpec, actionClass)
- {
- jsonSpec.action = {name: "LoadMenu", payload: {action:actionClass}};
- jsonSpec.items = [{ "name": "loading",
- "label" : RV_RES.GOTO_LOADING,
- iconClass: "loading"}];
- return jsonSpec;
- };
- /**
- * TODO - dispatcherEntry cleanup
- * @param {Object} requestType
- */
- CognosViewerAction.prototype.createCognosViewerDispatcherEntry = function( requestType )
- {
- var oReq = new ViewerDispatcherEntry(this.getCognosViewer());
- oReq.addFormField("ui.action", requestType);
- this.preProcess();
- if( this.doAddActionContext() === true )
- {
- var actionContext = this.addActionContext();
- oReq.addFormField("cv.actionContext", actionContext);
- if (window.gViewerLogger)
- {
- window.gViewerLogger.log('Action context', actionContext, "xml");
- }
- }
- oReq.addFormField("ui.object", this.m_oCV.envParams["ui.object"]);
- if(typeof this.m_oCV.envParams["ui.spec"] != "undefined")
- {
- oReq.addFormField("ui.spec", this.m_oCV.envParams["ui.spec"]);
- }
- if(this.m_oCV.getModelPath() !== "")
- {
- oReq.addFormField("modelPath", this.m_oCV.getModelPath());
- }
- if(typeof this.m_oCV.envParams["packageBase"] != "undefined")
- {
- oReq.addFormField("packageBase", this.m_oCV.envParams["packageBase"]);
- }
- if (typeof this.m_oCV.envParams["rap.state"] != "undefined")
- {
- oReq.addFormField("rap.state", this.m_oCV.envParams["rap.state"]);
- }
- if (typeof this.m_oCV.envParams["rapReportInfo"] != "undefined")
- {
- oReq.addFormField("rap.reportInfo", this.m_oCV.envParams["rapReportInfo"]);
- }
- this.addAdditionalOptions(oReq);
- return oReq;
- };
- CognosViewerAction.prototype.fireModifiedReportEvent = function()
- {
- try
- {
- var viewerWidget = this.getCognosViewer().getViewerWidget();
- if (viewerWidget) {
- var payload = {'modified':true};
- viewerWidget.fireEvent("com.ibm.bux.widget.modified", null, payload);
- }
- } catch(e) {}
- };
- CognosViewerAction.prototype.showCustomCursor = function(evt, id, imageRef)
- {
- var customCursor = document.getElementById(id);
- if(customCursor == null)
- {
- customCursor = document.createElement("span");
- customCursor.className = "customCursor";
- customCursor.setAttribute("id", id);
- document.body.appendChild(customCursor);
- }
- var imageSrcHtml = "<img src=\"" + this.getCognosViewer().getWebContentRoot() + imageRef + "\"/>";
- customCursor.innerHTML = imageSrcHtml;
- customCursor.style.position = "absolute";
- customCursor.style.left = (evt.clientX + 15) + "px";
- customCursor.style.top = (evt.clientY + 15) + "px";
- customCursor.style.display = "inline";
- };
- CognosViewerAction.prototype.hideCustomCursor = function(id)
- {
- var customCursor = document.getElementById(id);
- if(customCursor != null)
- {
- customCursor.style.display = "none";
- }
- };
- CognosViewerAction.prototype.selectionHasContext = function()
- {
- var selections = this.getCognosViewer().getSelectionController().getAllSelectedObjects();
- var bContext = false;
- if(selections != null && selections.length > 0)
- {
- for (var i=0; i < selections.length; i++)
- {
- if (selections[i].hasContextInformation())
- {
- bContext = true;
- break;
- }
- }
- }
- return bContext;
- };
- CognosViewerAction.prototype.isInteractiveDataContainer = function(displayTypeId)
- {
- var result = false;
- if (typeof displayTypeId != "undefined" && displayTypeId != null) {
- var id = displayTypeId.toLowerCase();
- result = id == 'crosstab' || id == 'list' || this.getCognosViewer().getRAPReportInfo().isChart(id);
- }
- return result;
- };
- CognosViewerAction.prototype.getSelectedContainerId = function() {
- var viewer = this.getCognosViewer();
- var selectionController = viewer.getSelectionController();
- var containerId = null;
- if( selectionController != null && typeof selectionController != "undefined") {
- containerId = this.getContainerId( selectionController );
- }
- return containerId;
- };
- CognosViewerAction.prototype.getSelectedReportInfo = function() {
- var viewer = this.getCognosViewer();
- var containerId = this.getSelectedContainerId();
- var selectedObject = this.getReportInfo(containerId);
- if( selectedObject == null )
- {
- //if there is more than one object, we'll return null
- var oRAPReportInfo = viewer.getRAPReportInfo();
- if(oRAPReportInfo.getContainerCount() == 1)
- {
- selectedObject = oRAPReportInfo.getContainerFromPos(0);
- }
- }
- return selectedObject;
- };
- CognosViewerAction.prototype.getReportInfo = function(containerId) {
- var selectedObject = null;
- if( containerId != null && containerId.length > 0 )
- {
- var viewer = this.getCognosViewer();
- var oRAPReportInfo = viewer.getRAPReportInfo();
- selectedObject = oRAPReportInfo.getContainer(containerId);
- }
- return selectedObject;
- };
- CognosViewerAction.prototype.isSelectionOnChart = function() {
- var viewer = this.getCognosViewer();
- if (viewer.getSelectionController().hasSelectedChartNodes())
- {
- return true;
- }
- var containerId = this.getContainerId( viewer.getSelectionController());
- if (typeof containerId != "undefined")
- {
- var reportInfo = this.getReportInfo(containerId);
- if (reportInfo != null && reportInfo.displayTypeId)
- {
- var displayTypeId = reportInfo.displayTypeId.toLowerCase();
- return viewer.getRAPReportInfo().isChart(displayTypeId);
- }
- }
- return false;
- };
- CognosViewerAction.prototype.ifContainsInteractiveDataContainer = function()
- {
- var oRAPReportInfo = this.getCognosViewer().getRAPReportInfo();
- if (oRAPReportInfo) {
- return oRAPReportInfo.containsInteractiveDataContainer();
- }
- return false;
- };
- /**
- * Detect from report Info if the widget is a prompt control or a prompt page and only one container (the global one)
- *
- */
- CognosViewerAction.prototype.isPromptWidget = function()
- {
- var oCV = this.getCognosViewer();
- if (oCV.getRAPReportInfo() && oCV.getRAPReportInfo().isPromptPart()) {
- return true;
- }
- return false;
- };
- CognosViewerAction.prototype.getLayoutComponents = function()
- {
- var layoutComponents = [];
- var reportTable = document.getElementById("rt" + this.m_oCV.getId());
- if(reportTable != null)
- {
- layoutComponents = getElementsByAttribute(reportTable, "*", "lid");
- }
- return layoutComponents;
- };
- //For applicable RAP actions, add a subset of the context/metadata table as action arguments....
- CognosViewerAction.prototype.addClientContextData = function(maxValuesPerRDI)
- {
- var selectionController = this.m_oCV.getSelectionController();
- if (typeof selectionController!="undefined" && selectionController!=null &&
- typeof selectionController.getCCDManager!="undefined" && selectionController.getCCDManager()!=null) {
- var oCCDManager = selectionController.getCCDManager();
- return ("<md>" + xml_encode(oCCDManager.MetadataToJSON()) + "</md>" +
- "<cd>" + xml_encode(oCCDManager.ContextDataSubsetToJSON(maxValuesPerRDI)) + "</cd>");
- }
- return "";
- };
- //For applicable RAP actions, add a Map of dataItem names and a count of
- CognosViewerAction.prototype.getDataItemInfoMap = function()
- {
- var selectionController = this.m_oCV.getSelectionController();
- if (typeof selectionController!="undefined" && selectionController!=null &&
- typeof selectionController.getCCDManager!="undefined" && selectionController.getCCDManager()!=null) {
- var oCCDManager = selectionController.getCCDManager();
- return ("<di>" + xml_encode(oCCDManager.DataItemInfoToJSON()) + "</di>" );
- }
- return "";
- };
- CognosViewerAction.prototype.getRAPLayoutTag = function(cellRef)
- {
- var tagValue = null;
- if (typeof cellRef == "object" && cellRef != null ) {
- tagValue = cellRef.getAttribute("rap_layout_tag");
- }
- return tagValue;
- };
- /**
- * Helper method to add the correct properties to a menuItem so it shows up 'checked'
- * @param {Object} bChecked - boolean if the menuItem should be checked
- * @param {Object} oMenuItem - the menuItem object
- * @param {Object} sUncheckedIconClass - optional css class to use if the menuItem is unchecked
- */
- CognosViewerAction.prototype.addMenuItemChecked = function(bChecked, oMenuItem, sUncheckedIconClass) {
- if (bChecked) {
- if (this.getCognosViewer().isHighContrast()) {
- oMenuItem["class"] = "menuItemSelected";
- }
- oMenuItem.iconClass = "menuItemChecked";
- }
- else if (sUncheckedIconClass && sUncheckedIconClass.length > 0) {
- oMenuItem.iconClass = sUncheckedIconClass;
- }
- };
- CognosViewerAction.prototype.gatherFilterInfoBeforeAction = function(action) {
- var widget = this.getCognosViewer().getViewerWidget();
- widget.filterRequiredAction = action;
- widget.clearRAPCache();
- widget.fireEvent("com.ibm.bux.widget.action", null, { action: 'canvas.filters' } );
- };
- CognosViewerAction.prototype.addClientSideUndo = function(action, aParams) {
- var undoCallback = GUtil.generateCallback(action.doUndo, aParams, action);
- var redoCallback = GUtil.generateCallback(action.doRedo, aParams, action);
- this.getUndoRedoQueue().addClientSideUndo({"tooltip" : action.getUndoHint(), "undoCallback" : undoCallback, "redoCallback" : redoCallback});
- this.getCognosViewer().getViewerWidget().updateToolbar();
- };
- /*
- * It is client side menu item checking depending upon two things
- * - area: global area or regular tab
- * - report type: whether it is prompt part or not
- *
- * Default:
- * - not valid in gloabl area
- * - not valid on prompt part in regular tab
- * - valid on regular report in regular tab
- *
- * @override
- */
- CognosViewerAction.prototype.isValidMenuItem = function()
- {
- var viewer = this.getCognosViewer();
- var widget = viewer.getViewerWidget();
- if (this.isPromptWidget()) {
- return false; //not valid on prompt part
- }
- return true;
- };
- CognosViewerAction.prototype.isPositiveInt = function(value) {
- if (typeof value === "undefined" || value === null) {
- return false;
- }
- var paresedValue = parseInt(value, 10);
- return value && paresedValue === +value && paresedValue > 0 && value.indexOf('.') == -1;
- };
- /**
- * Builds a PUBLIC object to return error information from an action.
- * DO NOT CHANGE THIS API
- */
- CognosViewerAction.prototype.buildActionResponseObject = function(status, code, msg) {
- return {
- "status" : status,
- "message" : msg ? msg : null,
- "code" : code ? code : null,
- getStatus : function() { return this.status; },
- getMessage : function() { return this.message; },
- getCode : function() { return this.code; }
- };
- };
- /**
- * LineageAction - implements lineage in cognos viewer
- */
- function LineageAction(){}
- LineageAction.prototype = new CognosViewerAction();
- LineageAction.prototype.getCommonOptions = function(request)
- {
- request.addFormField("cv.responseFormat", "asynchDetailMIMEAttachment");
- request.addFormField("bux", this.m_oCV.getViewerWidget() ? "true" : "false");
- request.addFormField("cv.id", this.m_oCV.envParams["cv.id"]);
- };
- LineageAction.prototype.getSelectionOptions = function(request)
- {
- var selectionController = this.m_oCV.getSelectionController();
- var contextIds = getSelectionContextIds(selectionController);
- request.addFormField("context.format", "initializer");
- request.addFormField("context.type", "reportService");
- request.addFormField("context.selection", "metadata," + contextIds.toString());
- };
- LineageAction.prototype.getPrimaryRequestOptions = function(request)
- {
- request.addFormField("specificationType", "metadataServiceLineageSpecification");
- request.addFormField("ui.action", "runLineageSpecification");
- request.addFormField("ui.object", this.m_oCV.envParams["ui.object"]);
- };
- LineageAction.prototype.getSecondaryRequestOptions = function(request)
- {
- request.addFormField("ui.conversation", this.m_oCV.getConversation());
- request.addFormField("m_tracking", this.m_oCV.getTracking());
- request.addFormField("ui.action", "lineage");
- };
- LineageAction.prototype.updateMenu = function(jsonSpec)
- {
- if (!this.getCognosViewer().bCanUseLineage) {
- return "";
- }
- jsonSpec.disabled = !this.selectionHasContext();
- return jsonSpec;
- };
- /**
- * Execute the lineage request
- */
- LineageAction.prototype.execute = function()
- {
- var oCV = this.getCognosViewer();
- var request = new AsynchDataDispatcherEntry(oCV);
- this.getCommonOptions(request);
- this.getSelectionOptions(request);
- if(oCV.getConversation() == "")
- {
- this.getPrimaryRequestOptions(request);
- }
- else
- {
- this.getSecondaryRequestOptions(request);
- }
- request.setCallbacks({"complete":{"object":this, "method":this.handleLineageResponse}});
- if (!oCV.m_viewerFragment) {
- request.setRequestIndicator(oCV.getRequestIndicator());
- var workingDialog = new WorkingDialog(oCV);
- workingDialog.setSimpleWorkingDialogFlag(true);
- request.setWorkingDialog(workingDialog);
- }
- oCV.dispatchRequest(request);
- };
- LineageAction.prototype.handleLineageResponse = function(oResponse) {
- var oCV = this.getCognosViewer();
- oCV.loadExtra();
- // Need to up the asynch info in the Viewer object
- oCV.setStatus(oResponse.getAsynchStatus());
- oCV.setConversation(oResponse.getConversation());
- oCV.setTracking(oResponse.getTracking());
- var config = null;
- if(typeof MDSRV_CognosConfiguration != "undefined")
- {
- config = new MDSRV_CognosConfiguration();
- var lineageURI = "";
- if(this.m_oCV.envParams["metadataInformationURI"])
- {
- lineageURI = this.m_oCV.envParams["metadataInformationURI"];
- }
- config.addProperty("lineageURI", lineageURI);
- config.addProperty("gatewayURI", this.m_oCV.getGateway());
- }
- var searchPath = this.m_oCV.envParams["ui.object"];
- var sSelectionContext = getViewerSelectionContext(this.m_oCV.getSelectionController(), new CSelectionContext(searchPath));
- var lineageHelper = new MDSRV_LineageFragmentContext(config, sSelectionContext);
- lineageHelper.setExecutionParameters(this.m_oCV.getExecutionParameters());
- if (typeof searchPath == "string")
- {
- lineageHelper.setReportPath( searchPath );
- }
- lineageHelper.setReportLineage(oResponse.getResult());
- lineageHelper.open();
- };
|