SelectionAction.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. function SelectionAction() {}
  13. SelectionAction.prototype = new CognosViewerAction();
  14. SelectionAction.prototype.onMouseOver = function(evt)
  15. {
  16. if(DragDropAction_isDragging(evt) == false)
  17. {
  18. var selectionController = this.getCognosViewer().getSelectionController();
  19. selectionController.pageHover(evt);
  20. }
  21. };
  22. SelectionAction.prototype.onMouseOut = function(evt)
  23. {
  24. if(DragDropAction_isDragging(evt) == false)
  25. {
  26. var selectionController = this.getCognosViewer().getSelectionController();
  27. selectionController.pageHover(evt);
  28. }
  29. };
  30. SelectionAction.prototype.hasPermission = function()
  31. {
  32. var oCV = this.getCognosViewer();
  33. return !( oCV.isLimitedInteractiveMode() || oCV.envParams['cv.objectPermissions'].indexOf( 'read' ) === -1 );
  34. };
  35. SelectionAction.prototype.executeDrillUpDown = function(evt)
  36. {
  37. var oCV = this.getCognosViewer();
  38. var oWidget = oCV.getViewerWidget();
  39. if (oCV.isDrillBlackListed() || (oWidget && oWidget.isSelectionFilterEnabled())) {
  40. return false;
  41. }
  42. if(evt.button == 0 || evt.button == 1 || evt.keyCode == "13")
  43. {
  44. // check to see if we're hovering over a drillable item and the cell is selected. If so, invoke the drill action
  45. var ctxNode = getCtxNodeFromEvent(evt);
  46. if(ctxNode != null)
  47. {
  48. var selectionController = this.m_oCV.getSelectionController();
  49. var descriptionNode = ctxNode.getAttribute("type") != null ? ctxNode : ctxNode.parentNode;
  50. var type = descriptionNode.getAttribute("type");
  51. var ctxValue = ctxNode.getAttribute("ctx");
  52. ctxValue = ctxValue.split("::")[0].split(":")[0];
  53. if((descriptionNode.getAttribute("CTNM") != null || type == "datavalue") && selectionController.getMun(ctxValue) != "")
  54. {
  55. var selectedObjects = selectionController.getAllSelectedObjects();
  56. for(var index = 0; index < selectedObjects.length; ++index)
  57. {
  58. var selectedObject = selectedObjects[index];
  59. if(selectedObject.getCellRef() == ctxNode.parentNode)
  60. {
  61. if (selectedObjects.length>1) {
  62. selectionController.clearSelectedObjects();
  63. selectionController.addSelectionObject(selectedObject);
  64. }
  65. var factory = this.m_oCV.getActionFactory();
  66. var drillAction = factory.load("DrillUpDown");
  67. drillAction.updateDrillability(this.m_oCV, ctxNode);
  68. if (drillAction.drillability > 0 && this.hasPermission()) {
  69. drillAction.execute();
  70. return true;
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }
  77. return false;
  78. };
  79. SelectionAction.prototype.executeDrillThrough = function(evt)
  80. {
  81. var oWidget = this.getCognosViewer().getViewerWidget();
  82. if (oWidget && oWidget.isSelectionFilterEnabled()) {
  83. return;
  84. }
  85. // try and see if there's a drill through
  86. var oDrillMgr = this.getCognosViewer().getDrillMgr();
  87. return oDrillMgr.getDrillThroughParameters('execute', evt);
  88. };
  89. SelectionAction.prototype.pageClicked = function(evt) {
  90. var bDrillThroughExecuted = false;
  91. var leftMouseButton = evt.which ? evt.which == 1 : evt.button == 1;
  92. var cvSort = new CognosViewerSort(evt, this.m_oCV);
  93. var sClass, crossBrowserNode = getCrossBrowserNode(evt);
  94. try {
  95. sClass = (crossBrowserNode && crossBrowserNode.className) || "";
  96. }
  97. catch (ex) {
  98. sClass = "";
  99. // sometimes node may not be an HTML element (like a XUL element) and accessing nodeType/nodeName/className will generate an error.
  100. }
  101. var oCV = this.getCognosViewer();
  102. var selectionController = null;
  103. if(leftMouseButton && cvSort.isSort(evt) && !oCV.isLimitedInteractiveMode() && !oCV.isBlacklisted("Sort") )
  104. {
  105. cvSort.execute();
  106. }
  107. else if(leftMouseButton && sClass.indexOf("expandButton") > -1 ) {
  108. var nNode = crossBrowserNode;
  109. if(sClass.indexOf("expandButtonCaption") > -1) {
  110. nNode = nNode.parentNode;
  111. sClass = nNode.className;
  112. }
  113. selectionController = getCognosViewerSCObjectRef(this.m_oCV.getId());
  114. selectionController.selectSingleDomNode(nNode.parentNode);
  115. var oAction;
  116. if(sClass.indexOf("collapse") === -1 ) {
  117. oAction = new ExpandMemberAction();
  118. } else {
  119. oAction = new CollapseMemberAction();
  120. }
  121. oAction.setCognosViewer(oCV);
  122. oAction.execute();
  123. }
  124. else
  125. {
  126. selectionController = this.m_oCV.getSelectionController();
  127. if(this.executeDrillUpDown(evt) === false)
  128. {
  129. var oCVWidget = this.m_oCV.getViewerWidget();
  130. if( oCVWidget.isSelectionFilterEnabled() ){
  131. if( leftMouseButton || evt.keyCode === 13 ){
  132. oCVWidget.preprocessPageClicked( false /*invokingContextMenu*/, evt);
  133. } else {
  134. //if we get here, it means that context menu is invoked and previous selections should be saved if it hasn't been yet.
  135. oCVWidget.preprocessPageClicked( true /*invokingContextMenu*/);
  136. }
  137. }
  138. if (selectionController.pageClicked(evt) != false) {
  139. this.m_oCV.getViewerWidget().updateToolbar();
  140. selectionController.resetAllowHorizontalDataValueSelection();
  141. }
  142. setNodeFocus(evt);
  143. }
  144. if (leftMouseButton || evt.keyCode === 13)
  145. {
  146. bDrillThroughExecuted = this.executeDrillThrough(evt);
  147. }
  148. if(leftMouseButton && this.m_oCV.getViewerWidget() && this.m_oCV.getViewerWidget().onSelectionChange) {
  149. this.m_oCV.getViewerWidget().onSelectionChange();
  150. }
  151. }
  152. return bDrillThroughExecuted;
  153. };
  154. SelectionAction.prototype.mouseActionInvolvesSelection = function(evt) {
  155. var leftMouseButton = evt.which ? evt.which == 1 : evt.button == 1;
  156. var cvSort = new CognosViewerSort(evt, this.m_oCV);
  157. if (leftMouseButton && cvSort.isSort(evt)) {
  158. return false;
  159. }
  160. if (this.executeDrillUpDown(evt) !== false) {
  161. return false;
  162. }
  163. return true;
  164. };
  165. SelectionAction.prototype.onMouseDown = function(evt)
  166. {
  167. this.delegateClickToMouseUp = false;
  168. if (this.mouseActionInvolvesSelection(evt) && !this.m_oCV.getSelectionController().shouldExecutePageClickedOnMouseDown(evt)) {
  169. this.delegateClickToMouseUp = true;
  170. return false;
  171. }
  172. return this.pageClicked(evt);
  173. };
  174. SelectionAction.prototype.onMouseUp = function(evt, consumed)
  175. {
  176. var ret = false;
  177. if(!consumed && this.mouseActionInvolvesSelection(evt) && this.delegateClickToMouseUp) {
  178. ret = this.pageClicked(evt);
  179. }
  180. this.delegateClickToMouseUp = false;
  181. return ret;
  182. };
  183. SelectionAction.prototype.onKeyDown = function(evt)
  184. {
  185. this.pageClicked(evt);
  186. };
  187. SelectionAction.prototype.onDoubleClick = function(evt)
  188. {
  189. // This is called by onDoubleClick from ViewerIWidget.js,
  190. // because the action we get from ActionFactory_loadActionHandler will be the SelectionAction.
  191. // Try to determine the drillability and run the drill action if available.
  192. // This is mostly the case for a chart type.
  193. // This approach is consistent with what happens when we use the context menu for drill up and down.
  194. var viewerObject = this.m_oCV;
  195. var oWidget = viewerObject.getViewerWidget();
  196. if (viewerObject.isDrillBlackListed() || (oWidget && oWidget.isSelectionFilterEnabled())) {
  197. return;
  198. }
  199. if(viewerObject.getStatus() == "complete")
  200. {
  201. var drillManager = viewerObject.getDrillMgr();
  202. var sDrillAction = "DrillDown";
  203. var sPayload = "DrillDown";
  204. var canDrillDown = false;
  205. var canDrillUp = false;
  206. if(drillManager != null)
  207. {
  208. if( !this.hasPermission() )
  209. {
  210. return true;
  211. }
  212. var selObj = drillManager.getSelectedObject();
  213. if (selObj == null ||
  214. (selObj.m_dataContainerType=="list" && selObj.m_sLayoutType=="columnTitle"))
  215. {
  216. //Can't drill up or down with no selections OR on a list column title.
  217. return true;
  218. }
  219. var drillOptions = selObj.getDrillOptions();
  220. if (typeof drillOptions == "undefined" || drillOptions == null || !drillOptions.length)
  221. {
  222. return true;
  223. }
  224. canDrillDown = drillManager.canDrillDown();
  225. if (!canDrillDown)
  226. {
  227. // We might be at the leaf level.
  228. // See if we can drill up and execute the action if this is the case.
  229. canDrillUp = drillManager.canDrillUp();
  230. if (canDrillUp)
  231. {
  232. sDrillAction = "DrillUp";
  233. sPayload = "DrillUp";
  234. }
  235. }
  236. // If we can drill down or up execute the action, otherwise do nothing (do not reload).
  237. if (canDrillDown || canDrillUp)
  238. {
  239. viewerObject.executeAction(sDrillAction, sPayload);
  240. }
  241. }
  242. else
  243. {
  244. return true;
  245. }
  246. }
  247. };