DrillUpDownAction.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2011
  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. * DrillUpDownAction - implements drill-related actions including drillability
  14. * and returning/performing drilling in the "default drill direction" in cognos viewer
  15. */
  16. function DrillUpDownAction()
  17. {
  18. this.m_sAction = "DrillDown";
  19. this.m_drillOption = "drillDown";
  20. this.undoTooltip = "";
  21. }
  22. DrillUpDownAction.prototype = new DrillAction();
  23. DrillUpDownAction.prototype.getHoverClassName = function() { return "dl"; };
  24. DrillUpDownAction.prototype.getUndoHint = function()
  25. {
  26. return this.undoTooltip;
  27. };
  28. DrillUpDownAction.prototype.keepRAPCache = function()
  29. {
  30. return false;
  31. };
  32. DrillUpDownAction.prototype.updateDrillability = function(cognosViewer, ctxNode)
  33. {
  34. this.m_oCV = cognosViewer;
  35. var ctxValueString = ctxNode.getAttribute("ctx");
  36. this.drillability = 0;
  37. if (ctxValueString) {
  38. var ctxValues = ctxValueString.split("::");
  39. if (ctxValues && ctxValues.length > 0) {
  40. if (ctxValues.length > 2) {
  41. this.drillability = this.getDrillabilityForIntersection(ctxValues[1].split(":")[0],
  42. ctxValues[2].split(":")[0]);
  43. } else if( ctxValues.length === 2 ) {
  44. /**
  45. * Handles the case for measure::categories ctx, which vizCharts like treemap generates.
  46. */
  47. this.drillability = this.getDrillabilityForCtxValue(ctxValues[1].split(":")[0]);
  48. } else {
  49. this.drillability = this.getDrillabilityForCtxValue(ctxValues[0].split(":")[0]);
  50. }
  51. }
  52. }
  53. //set the default action to match the default drill
  54. if (this.isDefaultDrillUp(ctxNode)) {
  55. this.m_sAction = "DrillUp";
  56. this.m_drillOption = "drillUp";
  57. this.undoTooltip = RV_RES.RV_DRILL_UP;
  58. } else {
  59. this.m_sAction = "DrillDown";
  60. this.m_drillOption = "drillDown";
  61. this.undoTooltip = RV_RES.RV_DRILL_DOWN;
  62. }
  63. return this.drillability;
  64. };
  65. DrillUpDownAction.prototype.updateDrillabilityFromSelections = function()
  66. {
  67. var selectionController = this.m_oCV.getSelectionController();
  68. var selectedObjects = selectionController.getAllSelectedObjects();
  69. this.drillability=0;
  70. if (selectedObjects != null && typeof selectedObjects != "undefined"
  71. && selectedObjects.length == 1 && selectedObjects[0].m_contextIds!=null)
  72. {
  73. if (selectedObjects[0].getLayoutType() == "section") {
  74. this.drillability = 0; //no drilling on section header in a sectioned list.
  75. } else if (selectedObjects[0].m_contextIds.length == 0) {
  76. this.drillability = 0;
  77. } else if (typeof DrillContextMenuHelper !== "undefined" && DrillContextMenuHelper.needsDrillSubMenu(this.m_oCV)) {
  78. //Normally, look at the level closest to the data to determine if you can drill up or down on a particular node or cell.
  79. //But...when the drill submenu is enabled, return true if you can drill up/down on upper levels as well...because all items are in the menu.
  80. this.drillability = this.getDrillabilityForAll(selectedObjects[0].m_contextIds);
  81. } else {
  82. if (selectedObjects[0].m_contextIds.length > 2) {
  83. this.drillability = this.getDrillabilityForIntersection(selectedObjects[0].m_contextIds[1][0],
  84. selectedObjects[0].m_contextIds[2][0]);
  85. } else {
  86. this.drillability = this.getDrillabilityForCtxValue(selectedObjects[0].m_contextIds[0][0]);
  87. }
  88. }
  89. }
  90. return this.drillability;
  91. };
  92. DrillUpDownAction.prototype.getDrillabilityForCtxValue = function(ctxValue)
  93. {
  94. var drillability = 0;
  95. var selectionController = this.m_oCV.getSelectionController();
  96. var refDataItem = selectionController.getRefDataItem( ctxValue )
  97. if( this.getHierarchyHasExpandedSet( this.m_oCV, refDataItem) && this.getIsRSDrillParent( this.m_oCV, refDataItem ) )
  98. {
  99. //we want to make sure that user can still drill up on the parent member when there is expanded set in the hierarchy
  100. drillability = 1; //up
  101. return drillability;
  102. }
  103. if (selectionController.getMun(ctxValue) !== "" && selectionController.getUsageInfo(ctxValue) !== '2')
  104. {
  105. //Start with the drill flags, then augment with reportInfo....
  106. drillability = (+selectionController.getDrillFlagForMember(ctxValue));
  107. var drillabilityObj = this.getDrillabilityForItemFromReportInfo(selectionController.getRefDataItem(ctxValue));
  108. if (drillabilityObj != null) {
  109. if (drillabilityObj.disableDown == true || drillabilityObj.isolated == true) {
  110. if (drillability == 1 || drillability >= 3 || drillabilityObj.isolated == true) { //up or both
  111. drillability = 1; //up
  112. } else {
  113. drillability = 0; //none
  114. }
  115. }
  116. if (drillabilityObj.disableUp == true) {
  117. if (drillability >= 2) { //down or both
  118. drillability = 2; //down
  119. } else {
  120. drillability = 0; //none
  121. }
  122. }
  123. }
  124. }
  125. return drillability;
  126. };
  127. DrillUpDownAction.prototype.getDrillabilityForIntersection = function(ctxValue1, ctxValue2)
  128. {
  129. var drillability1 = this.getDrillabilityForCtxValue(ctxValue1);
  130. return this.mergeDrillability(drillability1, ctxValue2);
  131. };
  132. /**
  133. * This function merges the drillability for all components of a selection (including nested parents)
  134. * It is used for visualizations to determine whether we need to show drill up/drill down and a submenu
  135. * (ie: it may not be possible to drill on the innermost but it may be possible to drill on one of the nested parents).
  136. */
  137. DrillUpDownAction.prototype.getDrillabilityForAll = function(contextArray)
  138. {
  139. //Process all levels...when 1 dimension, its an edge so process the first dimension
  140. // when 2 dimensions, its an intersection so process dimensions 1 and 2 for all levels.
  141. var iStartDim=(contextArray.length >= 2) ? 1 : 0;
  142. var iEndDim;
  143. if(contextArray.length == 2){
  144. iEndDim = 1;
  145. } else if (contextArray.length > 2) {
  146. iEndDim = 2;
  147. } else {
  148. iEndDim = 0;
  149. }
  150. var netDrillability=0;
  151. for (var iDim=iStartDim; iDim<=iEndDim; ++iDim) {
  152. for (var iLevel=0; iLevel<contextArray[iDim].length; ++iLevel) {
  153. netDrillability=this.mergeDrillability(netDrillability, contextArray[iDim][iLevel]);
  154. }
  155. }
  156. return netDrillability;
  157. };
  158. DrillUpDownAction.prototype.mergeDrillability = function(drillability1, ctxValue2)
  159. {
  160. var drillability2 = this.getDrillabilityForCtxValue(ctxValue2);
  161. if (drillability1 == drillability2) {
  162. return drillability1;
  163. }
  164. //swap so that d2 > d1
  165. if (drillability1 > drillability2) {
  166. var temp = drillability1;
  167. drillability1 = drillability2;
  168. drillability2 = temp;
  169. }
  170. if (drillability1 == 1 && drillability2 == 2) {
  171. return 3; //down or up
  172. }
  173. return drillability2;
  174. };
  175. DrillUpDownAction.prototype.hasPermission = function()
  176. {
  177. if( this.m_oCV)
  178. {
  179. if (this.m_oCV.isDrillBlackListed()) {
  180. return false;
  181. }
  182. var envParams = this.m_oCV.envParams;
  183. if( envParams )
  184. {
  185. return !( this.m_oCV.isLimitedInteractiveMode() || ( envParams['cv.objectPermissions'].indexOf( 'read' ) === -1 ));
  186. }
  187. }
  188. return false;
  189. };
  190. DrillUpDownAction.prototype.canDrillUp = function()
  191. {
  192. //0=none, 1=up, 2=down, 3=downorup, 4=upordown
  193. return ((this.drillability == 1 || this.drillability == 3 || this.drillability == 4) && this.hasPermission() );
  194. };
  195. DrillUpDownAction.prototype.canDrillDown = function()
  196. {
  197. //0=none, 1=up, 2=down, 3=downorup, 4=upordown
  198. return ( (this.drillability == 2 || this.drillability == 3 || this.drillability == 4) && this.hasPermission() );
  199. };
  200. DrillUpDownAction.prototype.isDefaultDrillUp = function(ctxNode)
  201. {
  202. if (this.drillability == 1 || this.drillability == 4 || (ctxNode && ctxNode.getAttribute("ischarttitle") === "true")) {
  203. return true;
  204. } else {
  205. return false;
  206. }
  207. };
  208. DrillUpDownAction.prototype.doOnMouseOver = function(evt)
  209. {
  210. if (this.drillability > 0 && !this.getCognosViewer().isLimitedInteractiveMode()) {
  211. var ctxNode = getCtxNodeFromEvent(evt);
  212. this.addDrillableClass(ctxNode);
  213. if (evt.toElement && evt.toElement.nodeName && evt.toElement.nodeName.toLowerCase() == "img") {
  214. this.addDrillableClass(evt.toElement);
  215. }
  216. }
  217. };
  218. DrillUpDownAction.prototype.doOnMouseOut = function(evt)
  219. {
  220. var ctxNode = getCtxNodeFromEvent(evt);
  221. if (ctxNode) {
  222. this.removeDrillableClass(ctxNode);
  223. if (evt.toElement && evt.toElement.nodeName && evt.toElement.nodeName.toLowerCase() == "img") {
  224. this.removeDrillableClass(evt.toElement);
  225. }
  226. }
  227. };
  228. DrillUpDownAction.prototype.onMouseOver = function(evt)
  229. {
  230. this.doOnMouseOver(evt);
  231. };
  232. DrillUpDownAction.prototype.onMouseOut = function(evt)
  233. {
  234. this.doOnMouseOut(evt);
  235. };
  236. DrillUpDownAction.prototype.onDoubleClick = function(evt)
  237. {
  238. if (this.drillability > 0 && this.hasPermission() && !this.isSelectionFilterEnabled()) {
  239. this.execute();
  240. var ctxNode = getCtxNodeFromEvent(evt);
  241. if (ctxNode!=null) {
  242. this.removeDrillableClass(ctxNode);
  243. }
  244. }
  245. };
  246. DrillUpDownAction.prototype.addDrillableClass = function(node) {
  247. if (! node.className.match(new RegExp('(\\s|^)' + this.getHoverClassName() + '(\\s|$)'))) {
  248. node.className += " " + this.getHoverClassName();
  249. }
  250. };
  251. DrillUpDownAction.prototype.removeDrillableClass = function(node) {
  252. var className = node.className;
  253. className = className.replace(new RegExp('(\\s|^)' + this.getHoverClassName() + '(\\s|$)'), ' ');
  254. node.className = className.replace(/^\s*/, "").replace(/\s*$/, "");
  255. };
  256. /**
  257. * DrillUpDownOrThroughAction - Manage drill cursors for authored drill/drillability and double-click "default drill" (charts only)
  258. */
  259. function DrillUpDownOrThroughAction()
  260. {
  261. this.m_hasAuthoredDrillTargets=false;
  262. this.m_canDrillUpDown=false;
  263. }
  264. DrillUpDownOrThroughAction.prototype = new DrillUpDownAction();
  265. DrillUpDownOrThroughAction.prototype.init = function(hasAuthoredDrillTargets, canDrillUpDown) {
  266. if (this.getCognosViewer()) {
  267. var oWidget = this.getCognosViewer().getViewerWidget();
  268. if (oWidget && oWidget.isSelectionFilterEnabled()) {
  269. return;
  270. }
  271. else if (this.m_oCV.isDrillBlackListed()) {
  272. return;
  273. }
  274. }
  275. this.m_hasAuthoredDrillTargets=hasAuthoredDrillTargets;
  276. this.m_canDrillUpDown=canDrillUpDown;
  277. };
  278. DrillUpDownOrThroughAction.prototype.updateDrillabilityInfo = function(cognosViewer, ctxNode)
  279. {
  280. if (this.m_canDrillUpDown) {
  281. return this.updateDrillability(cognosViewer, ctxNode);
  282. }
  283. return null;
  284. };
  285. DrillUpDownOrThroughAction.prototype.onMouseOver = function(evt)
  286. {
  287. if (this.m_hasAuthoredDrillTargets) {
  288. var ctxNode = getCtxNodeFromEvent(evt);
  289. if (ctxNode) {
  290. this.addDrillableClass(ctxNode);
  291. this._set_chartImage_drillThroughCursor_IE("pointer", evt);
  292. }
  293. }
  294. if (this.m_canDrillUpDown && !this.isSelectionFilterEnabled() && !this.m_oCV.isDrillBlackListed()) {
  295. this.doOnMouseOver(evt);
  296. }
  297. };
  298. DrillUpDownOrThroughAction.prototype.onMouseOut = function(evt)
  299. {
  300. if (this.m_hasAuthoredDrillTargets) {
  301. var ctxNode = getCtxNodeFromEvent(evt);
  302. if (ctxNode) {
  303. this.removeDrillableClass(ctxNode);
  304. this._set_chartImage_drillThroughCursor_IE("default", evt);
  305. }
  306. }
  307. if (this.m_canDrillUpDown && !this.isSelectionFilterEnabled() && !this.m_oCV.isDrillBlackListed()) {
  308. this.doOnMouseOut(evt);
  309. }
  310. };
  311. /**
  312. * IE8 and IE9 has limitations to dynamically change an "AREA" element's cursor type
  313. * by fliping pedefined CSS styles when there is cursor type css style defined in the
  314. * "IMG" element's parent element, the function below is to get the IMG object from the
  315. * onMouseOver event on the "AREA" and programatically change the img's cursor to show
  316. * hand icon when it's drill through able.
  317. * */
  318. DrillUpDownOrThroughAction.prototype._getDrillThroughChartImage_from_chartArea = function(evt){
  319. var oSrcElement = getCrossBrowserNode(evt);
  320. if(oSrcElement){
  321. var selectionController = this.m_oCV.getSelectionController();
  322. return selectionController.getSelectedChartImageFromChartArea(oSrcElement);
  323. }
  324. };
  325. DrillUpDownOrThroughAction.prototype._set_chartImage_drillThroughCursor_IE = function(sCursor, evt){
  326. if(dojo.isIE || dojo.isTrident){//We only do this for IE
  327. var oImg = this._getDrillThroughChartImage_from_chartArea( evt);
  328. if(oImg){
  329. oImg.style.cursor = sCursor;
  330. }
  331. }
  332. };