TriggerEventActionHandler.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: CA
  6. *| (C) Copyright IBM Corp. 2017 - 2018
  7. *| US Government Users Restricted Rights - Use, duplication or disclosure
  8. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *+------------------------------------------------------------------------+
  10. */
  11. define(['jquery'], function ($) {
  12. var TriggerEventActionHandler = function TriggerEventActionHandler(options) {
  13. // Only passed in when we're dealing with a button. Options is undefined for a menu item
  14. this.dashboardApi = options && options.dashboardApi;
  15. };
  16. /**
  17. * Button action handler
  18. */
  19. TriggerEventActionHandler.prototype.execute = function (event, buttonDefinition) {
  20. TriggerEventActionHandler._triggerEvent(this.dashboardApi, buttonDefinition);
  21. };
  22. /**
  23. * Menu action handler
  24. */
  25. TriggerEventActionHandler.prototype.onSelectItem = function (context) {
  26. var menuId = context.target.itemId;
  27. // Need to find the menu contribution specification
  28. var menuSpec = $.grep(context.target.plugin.itemSpec.items, function (item) {
  29. return item.id === menuId;
  30. });
  31. if (!menuSpec || menuSpec.length === 0) {
  32. console.debug('Could not find menu with id ' + menuId);
  33. }
  34. var dashboardApi = context.glassContext.appController.getCurrentContentView().getDashboardApi();
  35. TriggerEventActionHandler._triggerEvent(dashboardApi, menuSpec[0]);
  36. };
  37. TriggerEventActionHandler._triggerEvent = function (dashboardApi, contribDef) {
  38. var eventName = contribDef ? contribDef.eventName : null;
  39. if (!eventName) {
  40. console.debug('No eventName property in the button definition.');
  41. return;
  42. }
  43. dashboardApi.triggerDashboardEvent(eventName);
  44. };
  45. return TriggerEventActionHandler;
  46. });
  47. //# sourceMappingURL=TriggerEventActionHandler.js.map