LoadMenuAction.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. // Helper class which takes of of dynamic loading of menus
  13. function LoadMenuAction()
  14. {
  15. this.m_action = null;
  16. }
  17. LoadMenuAction.prototype = new CognosViewerAction();
  18. LoadMenuAction.prototype.FROM_TOOLBAR = 'toolbar';
  19. LoadMenuAction.prototype.FROM_TOOLBAR_BLUEDOTMENU = 'toolbarBlueDotMenu';
  20. LoadMenuAction.prototype.FROM_CONTEXTMENU = 'contextMenu';
  21. LoadMenuAction.prototype.FROM_CONTEXTMENU_MOREACTIONS = 'contextMenuMoreActions';
  22. LoadMenuAction.prototype.TOOLBAR_UPDATE_EVENT ="com.ibm.bux.widgetchrome.toolbar.update";
  23. LoadMenuAction.prototype.CONTEXTMENU_UPDATE_EVENT ="com.ibm.bux.widget.contextMenu.update";
  24. LoadMenuAction.prototype.setRequestParms = function(payload)
  25. {
  26. this.m_action = payload.action;
  27. this.m_sFrom = (payload.from) ? payload.from : this.FROM_TOOLBAR;
  28. };
  29. LoadMenuAction.prototype.execute = function()
  30. {
  31. var actionFactory = this.m_oCV.getActionFactory();
  32. var action = actionFactory.load(this.m_action);
  33. var toolbarItem = this.getMenuSpec();
  34. var buildMenuCallback = GUtil.generateCallback(this.buildMenuCallback, [toolbarItem], this);
  35. toolbarItem = action.buildMenu(toolbarItem, buildMenuCallback);
  36. if(toolbarItem != null)
  37. {
  38. this.buildMenuCallback(toolbarItem);
  39. }
  40. };
  41. LoadMenuAction.prototype.buildMenuCallback = function(toolbarItem)
  42. {
  43. toolbarItem.open = true;
  44. toolbarItem.action = null;
  45. this.fireEvent(toolbarItem);
  46. };
  47. LoadMenuAction.prototype.getMenuSpec = function() {
  48. var oCV = this.m_oCV;
  49. var sFrom = this.m_sFrom;
  50. if (!sFrom || !oCV) {
  51. return null;
  52. }
  53. var parentNode = null;
  54. var menuSpec = null;
  55. switch (sFrom) {
  56. case this.FROM_TOOLBAR:
  57. parentNode = oCV.getToolbar();
  58. break;
  59. case this.FROM_TOOLBAR_BLUEDOTMENU:
  60. parentNode = oCV.findBlueDotMenu();
  61. break;
  62. case this.FROM_CONTEXTMENU_MOREACTIONS:
  63. parentNode = oCV.findToolbarItem("MoreActions", oCV.getContextMenu());
  64. break;
  65. }
  66. if (parentNode) {
  67. menuSpec = oCV.findToolbarItem(this.m_action, parentNode);
  68. }
  69. if (menuSpec) {
  70. //attach 'from' to menuSpec
  71. menuSpec.from = sFrom;
  72. }
  73. return menuSpec;
  74. };
  75. LoadMenuAction.prototype.fireEvent = function(buttonSpec) {
  76. var updateItems = [];
  77. if (buttonSpec) {
  78. updateItems.push(buttonSpec);
  79. }
  80. var widget = this.m_oCV.getViewerWidget();
  81. var sFrom = buttonSpec.from;
  82. switch (sFrom) {
  83. case this.FROM_TOOLBAR:
  84. case this.FROM_TOOLBAR_BLUEDOTMENU:
  85. widget.fireEvent( this.TOOLBAR_UPDATE_EVENT, null, updateItems);
  86. break;
  87. case this.FROM_CONTEXTMENU_MOREACTIONS:
  88. widget.fireEvent( this.CONTEXTMENU_UPDATE_EVENT, null, updateItems);
  89. break;
  90. };
  91. };