cvactions.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2013
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. /**
  13. * CognosViewerAction constructor (base class for all cognos viewer action
  14. * @constructor
  15. */
  16. function CognosViewerAction()
  17. {
  18. this.m_oCV = null;
  19. }
  20. CognosViewerAction.prototype.setRequestParms = function( parms ){};
  21. CognosViewerAction.prototype.onMouseOver = function(evt) { return false; };
  22. CognosViewerAction.prototype.onMouseOut = function(evt) { return false; };
  23. CognosViewerAction.prototype.onMouseDown = function(evt) { return false; };
  24. CognosViewerAction.prototype.onClick = function(evt) { return false; };
  25. CognosViewerAction.prototype.onDoubleClick = function(evt) { return false; };
  26. CognosViewerAction.prototype.updateMenu = function(jsonSpec) { return jsonSpec; };
  27. CognosViewerAction.prototype.addAdditionalOptions = function(request) {};
  28. CognosViewerAction.prototype.genSelectionContextWithUniqueCTXIDs = function() { return false; };
  29. CognosViewerAction.prototype.doUndo = function() {if(typeof console != "undefined") { console.log("Required method doUndo not implemented.");}};
  30. CognosViewerAction.prototype.doRedo = function() {if(typeof console != "undefined") { console.log("Required method doRedo not implemented.");}};
  31. CognosViewerAction.prototype.forceRunSpecRequest = function() {return false;};
  32. /**
  33. * Method that gets called before the action context gets built. If
  34. * there's anything special that the action needs to do, they should
  35. * override this method.
  36. */
  37. CognosViewerAction.prototype.preProcess = function() {};
  38. /**
  39. * Sets the cognos viewer object (called by the action factory
  40. * @param CCognosViewer object
  41. * @private
  42. */
  43. CognosViewerAction.prototype.setCognosViewer = function(oCV)
  44. {
  45. this.m_oCV = oCV;
  46. };
  47. /**
  48. * Returns an instance to the cognos viewer object
  49. * @return CCognosViewer object
  50. */
  51. CognosViewerAction.prototype.getCognosViewer = function()
  52. {
  53. return this.m_oCV;
  54. };
  55. CognosViewerAction.prototype.getUndoRedoQueue = function()
  56. {
  57. if (this.getCognosViewer().getViewerWidget()) {
  58. return this.getCognosViewer().getViewerWidget().getUndoRedoQueue();
  59. }
  60. return null;
  61. };
  62. CognosViewerAction.prototype.getViewerWidget = function()
  63. {
  64. return this.m_oCV.getViewerWidget();
  65. };
  66. /**
  67. * Returns the object display name (custom name/report name/report part name)
  68. */
  69. CognosViewerAction.prototype.getObjectDisplayName = function()
  70. {
  71. var displayName = "";
  72. if(this.m_oCV != null)
  73. {
  74. if(typeof this.m_oCV.envParams["reportpart_id"] != "undefined")
  75. {
  76. displayName = this.m_oCV.envParams["reportpart_id"];
  77. }
  78. else if(typeof this.m_oCV.envParams["ui.name"] != "undefined")
  79. {
  80. displayName = this.m_oCV.envParams["ui.name"];
  81. }
  82. }
  83. return displayName;
  84. };
  85. /**
  86. * Gets the container Id
  87. */
  88. CognosViewerAction.prototype.getContainerId = function(selectionController) {
  89. var container = "";
  90. if (selectionController && selectionController.getAllSelectedObjects) {
  91. var allSel = selectionController.getAllSelectedObjects();
  92. if (allSel) {
  93. var selection = allSel[0];
  94. if (selection && selection.getLayoutElementId) {
  95. container = this.removeNamespace(selection.getLayoutElementId());
  96. }
  97. }
  98. }
  99. return container;
  100. };
  101. CognosViewerAction.prototype.removeNamespace = function(value)
  102. {
  103. var originalValue = value;
  104. try
  105. {
  106. if(value != "")
  107. {
  108. var idIndex = value.indexOf(this.m_oCV.getId());
  109. if(idIndex != -1)
  110. {
  111. value = value.replace(this.m_oCV.getId(), "");
  112. }
  113. }
  114. return value;
  115. }
  116. catch(e)
  117. {
  118. return originalValue;
  119. }
  120. };
  121. CognosViewerAction.prototype.doAddActionContext = function()
  122. {
  123. return true;
  124. };
  125. CognosViewerAction.prototype.getSelectionContext = function()
  126. {
  127. return getViewerSelectionContext(this.m_oCV.getSelectionController(), new CSelectionContext(this.m_oCV.envParams["ui.object"]), this.genSelectionContextWithUniqueCTXIDs());
  128. };
  129. CognosViewerAction.prototype.getNumberOfSelections = function()
  130. {
  131. var numberOfSelections = -1;
  132. if(this.m_oCV != null && this.m_oCV.getSelectionController() != null)
  133. {
  134. numberOfSelections = this.m_oCV.getSelectionController().getSelections().length;
  135. }
  136. return numberOfSelections;
  137. };
  138. CognosViewerAction.prototype.buildDynamicMenuItem = function(jsonSpec, actionClass)
  139. {
  140. jsonSpec.action = {name: "LoadMenu", payload: {action:actionClass}};
  141. jsonSpec.items = [{ "name": "loading",
  142. "label" : RV_RES.GOTO_LOADING,
  143. iconClass: "loading"}];
  144. return jsonSpec;
  145. };
  146. /**
  147. * TODO - dispatcherEntry cleanup
  148. * @param {Object} requestType
  149. */
  150. CognosViewerAction.prototype.createCognosViewerDispatcherEntry = function( requestType )
  151. {
  152. var oReq = new ViewerDispatcherEntry(this.getCognosViewer());
  153. oReq.addFormField("ui.action", requestType);
  154. this.preProcess();
  155. if( this.doAddActionContext() === true )
  156. {
  157. var actionContext = this.addActionContext();
  158. oReq.addFormField("cv.actionContext", actionContext);
  159. if (window.gViewerLogger)
  160. {
  161. window.gViewerLogger.log('Action context', actionContext, "xml");
  162. }
  163. }
  164. oReq.addFormField("ui.object", this.m_oCV.envParams["ui.object"]);
  165. if(typeof this.m_oCV.envParams["ui.spec"] != "undefined")
  166. {
  167. oReq.addFormField("ui.spec", this.m_oCV.envParams["ui.spec"]);
  168. }
  169. if(this.m_oCV.getModelPath() !== "")
  170. {
  171. oReq.addFormField("modelPath", this.m_oCV.getModelPath());
  172. }
  173. if(typeof this.m_oCV.envParams["packageBase"] != "undefined")
  174. {
  175. oReq.addFormField("packageBase", this.m_oCV.envParams["packageBase"]);
  176. }
  177. if (typeof this.m_oCV.envParams["rap.state"] != "undefined")
  178. {
  179. oReq.addFormField("rap.state", this.m_oCV.envParams["rap.state"]);
  180. }
  181. if (typeof this.m_oCV.envParams["rapReportInfo"] != "undefined")
  182. {
  183. oReq.addFormField("rap.reportInfo", this.m_oCV.envParams["rapReportInfo"]);
  184. }
  185. this.addAdditionalOptions(oReq);
  186. return oReq;
  187. };
  188. CognosViewerAction.prototype.fireModifiedReportEvent = function()
  189. {
  190. try
  191. {
  192. var viewerWidget = this.getCognosViewer().getViewerWidget();
  193. if (viewerWidget) {
  194. var payload = {'modified':true};
  195. viewerWidget.fireEvent("com.ibm.bux.widget.modified", null, payload);
  196. }
  197. } catch(e) {}
  198. };
  199. CognosViewerAction.prototype.showCustomCursor = function(evt, id, imageRef)
  200. {
  201. var customCursor = document.getElementById(id);
  202. if(customCursor == null)
  203. {
  204. customCursor = document.createElement("span");
  205. customCursor.className = "customCursor";
  206. customCursor.setAttribute("id", id);
  207. document.body.appendChild(customCursor);
  208. }
  209. var imageSrcHtml = "<img src=\"" + this.getCognosViewer().getWebContentRoot() + imageRef + "\"/>";
  210. customCursor.innerHTML = imageSrcHtml;
  211. customCursor.style.position = "absolute";
  212. customCursor.style.left = (evt.clientX + 15) + "px";
  213. customCursor.style.top = (evt.clientY + 15) + "px";
  214. customCursor.style.display = "inline";
  215. };
  216. CognosViewerAction.prototype.hideCustomCursor = function(id)
  217. {
  218. var customCursor = document.getElementById(id);
  219. if(customCursor != null)
  220. {
  221. customCursor.style.display = "none";
  222. }
  223. };
  224. CognosViewerAction.prototype.selectionHasContext = function()
  225. {
  226. var selections = this.getCognosViewer().getSelectionController().getAllSelectedObjects();
  227. var bContext = false;
  228. if(selections != null && selections.length > 0)
  229. {
  230. for (var i=0; i < selections.length; i++)
  231. {
  232. if (selections[i].hasContextInformation())
  233. {
  234. bContext = true;
  235. break;
  236. }
  237. }
  238. }
  239. return bContext;
  240. };
  241. CognosViewerAction.prototype.isInteractiveDataContainer = function(displayTypeId)
  242. {
  243. var result = false;
  244. if (typeof displayTypeId != "undefined" && displayTypeId != null) {
  245. var id = displayTypeId.toLowerCase();
  246. result = id == 'crosstab' || id == 'list' || this.getCognosViewer().getRAPReportInfo().isChart(id);
  247. }
  248. return result;
  249. };
  250. CognosViewerAction.prototype.getSelectedContainerId = function() {
  251. var viewer = this.getCognosViewer();
  252. var selectionController = viewer.getSelectionController();
  253. var containerId = null;
  254. if( selectionController != null && typeof selectionController != "undefined") {
  255. containerId = this.getContainerId( selectionController );
  256. }
  257. return containerId;
  258. };
  259. CognosViewerAction.prototype.getSelectedReportInfo = function() {
  260. var viewer = this.getCognosViewer();
  261. var containerId = this.getSelectedContainerId();
  262. var selectedObject = this.getReportInfo(containerId);
  263. if( selectedObject == null )
  264. {
  265. //if there is more than one object, we'll return null
  266. var oRAPReportInfo = viewer.getRAPReportInfo();
  267. if(oRAPReportInfo.getContainerCount() == 1)
  268. {
  269. selectedObject = oRAPReportInfo.getContainerFromPos(0);
  270. }
  271. }
  272. return selectedObject;
  273. };
  274. CognosViewerAction.prototype.getReportInfo = function(containerId) {
  275. var selectedObject = null;
  276. if( containerId != null && containerId.length > 0 )
  277. {
  278. var viewer = this.getCognosViewer();
  279. var oRAPReportInfo = viewer.getRAPReportInfo();
  280. selectedObject = oRAPReportInfo.getContainer(containerId);
  281. }
  282. return selectedObject;
  283. };
  284. CognosViewerAction.prototype.isSelectionOnChart = function() {
  285. var viewer = this.getCognosViewer();
  286. if (viewer.getSelectionController().hasSelectedChartNodes())
  287. {
  288. return true;
  289. }
  290. var containerId = this.getContainerId( viewer.getSelectionController());
  291. if (typeof containerId != "undefined")
  292. {
  293. var reportInfo = this.getReportInfo(containerId);
  294. if (reportInfo != null && reportInfo.displayTypeId)
  295. {
  296. var displayTypeId = reportInfo.displayTypeId.toLowerCase();
  297. return viewer.getRAPReportInfo().isChart(displayTypeId);
  298. }
  299. }
  300. return false;
  301. };
  302. CognosViewerAction.prototype.ifContainsInteractiveDataContainer = function()
  303. {
  304. var oRAPReportInfo = this.getCognosViewer().getRAPReportInfo();
  305. if (oRAPReportInfo) {
  306. return oRAPReportInfo.containsInteractiveDataContainer();
  307. }
  308. return false;
  309. };
  310. /**
  311. * Detect from report Info if the widget is a prompt control or a prompt page and only one container (the global one)
  312. *
  313. */
  314. CognosViewerAction.prototype.isPromptWidget = function()
  315. {
  316. var oCV = this.getCognosViewer();
  317. if (oCV.getRAPReportInfo() && oCV.getRAPReportInfo().isPromptPart()) {
  318. return true;
  319. }
  320. return false;
  321. };
  322. CognosViewerAction.prototype.getLayoutComponents = function()
  323. {
  324. var layoutComponents = [];
  325. var reportTable = document.getElementById("rt" + this.m_oCV.getId());
  326. if(reportTable != null)
  327. {
  328. layoutComponents = getElementsByAttribute(reportTable, "*", "lid");
  329. }
  330. return layoutComponents;
  331. };
  332. //For applicable RAP actions, add a subset of the context/metadata table as action arguments....
  333. CognosViewerAction.prototype.addClientContextData = function(maxValuesPerRDI)
  334. {
  335. var selectionController = this.m_oCV.getSelectionController();
  336. if (typeof selectionController!="undefined" && selectionController!=null &&
  337. typeof selectionController.getCCDManager!="undefined" && selectionController.getCCDManager()!=null) {
  338. var oCCDManager = selectionController.getCCDManager();
  339. return ("<md>" + xml_encode(oCCDManager.MetadataToJSON()) + "</md>" +
  340. "<cd>" + xml_encode(oCCDManager.ContextDataSubsetToJSON(maxValuesPerRDI)) + "</cd>");
  341. }
  342. return "";
  343. };
  344. //For applicable RAP actions, add a Map of dataItem names and a count of
  345. CognosViewerAction.prototype.getDataItemInfoMap = function()
  346. {
  347. var selectionController = this.m_oCV.getSelectionController();
  348. if (typeof selectionController!="undefined" && selectionController!=null &&
  349. typeof selectionController.getCCDManager!="undefined" && selectionController.getCCDManager()!=null) {
  350. var oCCDManager = selectionController.getCCDManager();
  351. return ("<di>" + xml_encode(oCCDManager.DataItemInfoToJSON()) + "</di>" );
  352. }
  353. return "";
  354. };
  355. CognosViewerAction.prototype.getRAPLayoutTag = function(cellRef)
  356. {
  357. var tagValue = null;
  358. if (typeof cellRef == "object" && cellRef != null ) {
  359. tagValue = cellRef.getAttribute("rap_layout_tag");
  360. }
  361. return tagValue;
  362. };
  363. /**
  364. * Helper method to add the correct properties to a menuItem so it shows up 'checked'
  365. * @param {Object} bChecked - boolean if the menuItem should be checked
  366. * @param {Object} oMenuItem - the menuItem object
  367. * @param {Object} sUncheckedIconClass - optional css class to use if the menuItem is unchecked
  368. */
  369. CognosViewerAction.prototype.addMenuItemChecked = function(bChecked, oMenuItem, sUncheckedIconClass) {
  370. if (bChecked) {
  371. if (this.getCognosViewer().isHighContrast()) {
  372. oMenuItem["class"] = "menuItemSelected";
  373. }
  374. oMenuItem.iconClass = "menuItemChecked";
  375. }
  376. else if (sUncheckedIconClass && sUncheckedIconClass.length > 0) {
  377. oMenuItem.iconClass = sUncheckedIconClass;
  378. }
  379. };
  380. CognosViewerAction.prototype.gatherFilterInfoBeforeAction = function(action) {
  381. var widget = this.getCognosViewer().getViewerWidget();
  382. widget.filterRequiredAction = action;
  383. widget.clearRAPCache();
  384. widget.fireEvent("com.ibm.bux.widget.action", null, { action: 'canvas.filters' } );
  385. };
  386. CognosViewerAction.prototype.addClientSideUndo = function(action, aParams) {
  387. var undoCallback = GUtil.generateCallback(action.doUndo, aParams, action);
  388. var redoCallback = GUtil.generateCallback(action.doRedo, aParams, action);
  389. this.getUndoRedoQueue().addClientSideUndo({"tooltip" : action.getUndoHint(), "undoCallback" : undoCallback, "redoCallback" : redoCallback});
  390. this.getCognosViewer().getViewerWidget().updateToolbar();
  391. };
  392. /*
  393. * It is client side menu item checking depending upon two things
  394. * - area: global area or regular tab
  395. * - report type: whether it is prompt part or not
  396. *
  397. * Default:
  398. * - not valid in gloabl area
  399. * - not valid on prompt part in regular tab
  400. * - valid on regular report in regular tab
  401. *
  402. * @override
  403. */
  404. CognosViewerAction.prototype.isValidMenuItem = function()
  405. {
  406. var viewer = this.getCognosViewer();
  407. var widget = viewer.getViewerWidget();
  408. if (this.isPromptWidget()) {
  409. return false; //not valid on prompt part
  410. }
  411. return true;
  412. };
  413. CognosViewerAction.prototype.isPositiveInt = function(value) {
  414. if (typeof value === "undefined" || value === null) {
  415. return false;
  416. }
  417. var paresedValue = parseInt(value, 10);
  418. return value && paresedValue === +value && paresedValue > 0 && value.indexOf('.') == -1;
  419. };
  420. /**
  421. * Builds a PUBLIC object to return error information from an action.
  422. * DO NOT CHANGE THIS API
  423. */
  424. CognosViewerAction.prototype.buildActionResponseObject = function(status, code, msg) {
  425. return {
  426. "status" : status,
  427. "message" : msg ? msg : null,
  428. "code" : code ? code : null,
  429. getStatus : function() { return this.status; },
  430. getMessage : function() { return this.message; },
  431. getCode : function() { return this.code; }
  432. };
  433. };
  434. /**
  435. * LineageAction - implements lineage in cognos viewer
  436. */
  437. function LineageAction(){}
  438. LineageAction.prototype = new CognosViewerAction();
  439. LineageAction.prototype.getCommonOptions = function(request)
  440. {
  441. request.addFormField("cv.responseFormat", "asynchDetailMIMEAttachment");
  442. request.addFormField("bux", this.m_oCV.getViewerWidget() ? "true" : "false");
  443. request.addFormField("cv.id", this.m_oCV.envParams["cv.id"]);
  444. };
  445. LineageAction.prototype.getSelectionOptions = function(request)
  446. {
  447. var selectionController = this.m_oCV.getSelectionController();
  448. var contextIds = getSelectionContextIds(selectionController);
  449. request.addFormField("context.format", "initializer");
  450. request.addFormField("context.type", "reportService");
  451. request.addFormField("context.selection", "metadata," + contextIds.toString());
  452. };
  453. LineageAction.prototype.getPrimaryRequestOptions = function(request)
  454. {
  455. request.addFormField("specificationType", "metadataServiceLineageSpecification");
  456. request.addFormField("ui.action", "runLineageSpecification");
  457. request.addFormField("ui.object", this.m_oCV.envParams["ui.object"]);
  458. };
  459. LineageAction.prototype.getSecondaryRequestOptions = function(request)
  460. {
  461. request.addFormField("ui.conversation", this.m_oCV.getConversation());
  462. request.addFormField("m_tracking", this.m_oCV.getTracking());
  463. request.addFormField("ui.action", "lineage");
  464. };
  465. LineageAction.prototype.updateMenu = function(jsonSpec)
  466. {
  467. if (!this.getCognosViewer().bCanUseLineage) {
  468. return "";
  469. }
  470. jsonSpec.disabled = !this.selectionHasContext();
  471. return jsonSpec;
  472. };
  473. /**
  474. * Execute the lineage request
  475. */
  476. LineageAction.prototype.execute = function()
  477. {
  478. var oCV = this.getCognosViewer();
  479. var request = new AsynchDataDispatcherEntry(oCV);
  480. this.getCommonOptions(request);
  481. this.getSelectionOptions(request);
  482. if(oCV.getConversation() == "")
  483. {
  484. this.getPrimaryRequestOptions(request);
  485. }
  486. else
  487. {
  488. this.getSecondaryRequestOptions(request);
  489. }
  490. request.setCallbacks({"complete":{"object":this, "method":this.handleLineageResponse}});
  491. if (!oCV.m_viewerFragment) {
  492. request.setRequestIndicator(oCV.getRequestIndicator());
  493. var workingDialog = new WorkingDialog(oCV);
  494. workingDialog.setSimpleWorkingDialogFlag(true);
  495. request.setWorkingDialog(workingDialog);
  496. }
  497. oCV.dispatchRequest(request);
  498. };
  499. LineageAction.prototype.handleLineageResponse = function(oResponse) {
  500. var oCV = this.getCognosViewer();
  501. oCV.loadExtra();
  502. // Need to up the asynch info in the Viewer object
  503. oCV.setStatus(oResponse.getAsynchStatus());
  504. oCV.setConversation(oResponse.getConversation());
  505. oCV.setTracking(oResponse.getTracking());
  506. var config = null;
  507. if(typeof MDSRV_CognosConfiguration != "undefined")
  508. {
  509. config = new MDSRV_CognosConfiguration();
  510. var lineageURI = "";
  511. if(this.m_oCV.envParams["metadataInformationURI"])
  512. {
  513. lineageURI = this.m_oCV.envParams["metadataInformationURI"];
  514. }
  515. config.addProperty("lineageURI", lineageURI);
  516. config.addProperty("gatewayURI", this.m_oCV.getGateway());
  517. }
  518. var searchPath = this.m_oCV.envParams["ui.object"];
  519. var sSelectionContext = getViewerSelectionContext(this.m_oCV.getSelectionController(), new CSelectionContext(searchPath));
  520. var lineageHelper = new MDSRV_LineageFragmentContext(config, sSelectionContext);
  521. lineageHelper.setExecutionParameters(this.m_oCV.getExecutionParameters());
  522. if (typeof searchPath == "string")
  523. {
  524. lineageHelper.setReportPath( searchPath );
  525. }
  526. lineageHelper.setReportLineage(oResponse.getResult());
  527. lineageHelper.open();
  528. };