EventChannelRouterHelper.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2015, 2017
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. /**
  8. * This class creates EventChannelRouter object by Channel type.
  9. *
  10. * SAME_PAGE channel is supported meaning that widgets on same page will be notified.
  11. */
  12. define(['underscore', '../lib/@waca/core-client/js/core-client/ui/core/Class', '../app/EventChannelRouter'], function (_, Class, EventChannelRouter) {
  13. // private members
  14. var CHANNEL_TYPE = {
  15. SAME_PAGE: 1, //A channel is established with a single page
  16. Page2Page: 2, //For future, Channel is established between explicit two pages
  17. Widget2Widget: 3 //For future, Channel is established between explicit two widgets
  18. };
  19. // list event names that will go through channel
  20. var EVENT_NAMES = {
  21. SAME_PAGE: ['dw:filters'],
  22. Page2Page: [], //For future
  23. Widget2Widget: [] //For future
  24. };
  25. var EventChannelRouterHelper = null;
  26. EventChannelRouterHelper = Class.extend({
  27. //Channel type
  28. TYPE: CHANNEL_TYPE,
  29. widgetAndPageMap: null, //Id (string) map - pairs of widgetId and pageId.
  30. pageAndChannelRouterMap: null, //pageId and EventChannelRouter object map
  31. eventRouter: null,
  32. init: function init(options) {
  33. EventChannelRouterHelper.inherited('init', this, arguments);
  34. this.eventRouter = options.eventRouter;
  35. this.pageAndChannelRouterMap = {};
  36. },
  37. destroy: function destroy() {
  38. for (var containerPageId in this.pageAndChannelRouterMap) {
  39. if (this.pageAndChannelRouterMap.hasOwnProperty(containerPageId)) {
  40. delete this.pageAndChannelRouterMap[containerPageId];
  41. }
  42. }
  43. delete this.topLayoutModel;
  44. delete this.pageAndChannelRouterMap;
  45. delete this.eventRouter;
  46. },
  47. /**
  48. * Create SamePage type EventChannelRouter for given containerPageId and store in the map
  49. */
  50. createSamePageEventChannelRouter: function createSamePageEventChannelRouter(containerPageId) {
  51. var channelOptoins = {
  52. channelId: containerPageId,
  53. eventNames: EVENT_NAMES.SAME_PAGE,
  54. globalEventRouter: this.eventRouter,
  55. alias: _.unique('tabPageECR_')
  56. };
  57. var pageEventRouter = new EventChannelRouter(channelOptoins);
  58. this.pageAndChannelRouterMap[containerPageId] = pageEventRouter;
  59. return pageEventRouter;
  60. },
  61. /**
  62. * @returns eventChannelRouter for the given pageId. Create and save one if does not exist
  63. */
  64. getChannelRouter: function getChannelRouter(containerPageId) {
  65. if (this.pageAndChannelRouterMap[containerPageId]) {
  66. return this.pageAndChannelRouterMap[containerPageId];
  67. }
  68. return this.createSamePageEventChannelRouter(containerPageId);
  69. }
  70. });
  71. return EventChannelRouterHelper;
  72. });
  73. //# sourceMappingURL=EventChannelRouterHelper.js.map