cv_override.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2012
  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. * Override the page click event so that mobile can show their
  14. * own context menu
  15. */
  16. CMainWnd.prototype.pageClicked = function(evt) {
  17. var oCV = this.getCV();
  18. var selectionController = oCV.getSelectionController();
  19. if (selectionController && oCV.bCanUseCognosViewerSelection == true) {
  20. selectionController.resetSelections();
  21. var nodeSelected = selectionController.pageClickedForMobile(evt);
  22. // Only show the menu in Mobile if there's something selected
  23. if (nodeSelected) {
  24. // If we have a bookmark drill through with no target then execute the drill through instead of showing a menu
  25. if (this._bookmarkDrillThrough(evt, oCV)) {
  26. return;
  27. }
  28. var contextMenu = CCognosViewerToolbarHelper.updateContextMenuForCurrentSelection(oCV, oCV.getContextMenu());
  29. this._fixGotoMenu(contextMenu);
  30. var containerType = selectionController.getContainerType();
  31. // if we're dealing with a chart then get the tooltip
  32. var chartTooltip = containerType === "chart" ? selectionController.getChartTooltip() : null;
  33. var payload = {
  34. "action" : "showMenu",
  35. "event" : evt,
  36. "payload" : contextMenu.length > 0 ? contextMenu : null,
  37. "displayValues" : selectionController.getDisplayValues(selectionController),
  38. "chartTooltip" : chartTooltip,
  39. "containerType" : containerType
  40. };
  41. // window.onAction is the entry point into Mobile, call them so they can show their own menu
  42. if (window.onAction) {
  43. window.onAction(payload);
  44. }
  45. else if(typeof console != "undefined") {
  46. // must not be in Mobile, log it to the console
  47. console.log(payload);
  48. }
  49. }
  50. }
  51. };
  52. /**
  53. * If the user clicked on a cell with a bookmark drill with no target report
  54. * then execute the drill through
  55. * @returns true if a drill through was executed
  56. */
  57. CMainWnd.prototype._bookmarkDrillThrough = function(evt, oCV) {
  58. var oDrillMgr = oCV.getDrillMgr();
  59. var drillThroughs = oDrillMgr.getAuthoredDrillsForCurrentSelection();
  60. if (drillThroughs) {
  61. // If we have a bookmark drill through with no target then execute the drill through instead of showing a menu
  62. var drillTargets = XMLHelper_FindChildrenByTagName(drillThroughs, "drillTarget", false);
  63. if (drillTargets && drillTargets.length == 1) {
  64. var drillTarget = drillTargets[0];
  65. var bookmarkRef = drillTarget.getAttribute("bookmarkRef");
  66. var path = drillTarget.getAttribute("path");
  67. if (bookmarkRef && bookmarkRef.length > 0 && (!path || path.length == 0)) {
  68. oDrillMgr.singleClickDrillEvent(evt, 'RV');
  69. return true;
  70. }
  71. }
  72. }
  73. return false;
  74. };
  75. /**
  76. * Override the displayContextMenu so that we call Mobile instead
  77. */
  78. CMainWnd.prototype.displayContextMenu = function(evt, selectNode) {
  79. if(!this.getCV().bEnableContextMenu) {
  80. return false;
  81. }
  82. this.pageClicked(evt);
  83. };
  84. /**
  85. * Mobile doesn't want all the drill through items in a sub-menu
  86. */
  87. CMainWnd.prototype._fixGotoMenu = function(contextMenu) {
  88. if (contextMenu && contextMenu.length) {
  89. var gotoMenuItem = null;
  90. var menuSize = contextMenu.length;
  91. var menuPosition = 0;
  92. // find the 'Goto' menu
  93. for (var i=0; i < menuSize; i++) {
  94. if (contextMenu[i].name === 'Goto') {
  95. menuPosition = i;
  96. gotoMenuItem = contextMenu.splice(i, 1);
  97. break;
  98. }
  99. }
  100. // Loop through all the sub-menu items and move them into the main menu
  101. if (gotoMenuItem && gotoMenuItem[0] && gotoMenuItem[0].items) {
  102. var gotoItems = gotoMenuItem[0].items;
  103. var gotoSize = gotoItems.length;
  104. for (var i=0; i < gotoSize; i++) {
  105. // Mobile doesn't want separators or the 'Goto' menu item
  106. if (!gotoItems[i].separator) {
  107. contextMenu.splice(menuPosition, 0, gotoItems[i]);
  108. menuPosition++;
  109. }
  110. }
  111. }
  112. }
  113. };