CustomWidget.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2016, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['./staticwidget/StaticWidget', 'jquery'], function (Base, $) {
  8. var CustomWidget = Base.extend({
  9. init: function init(options) {
  10. CustomWidget.inherited('init', this, arguments);
  11. this.registry = options.registry;
  12. this.eventRouter = options.eventRouter;
  13. // initialize the root nodes
  14. this._initContentRoot();
  15. this._initWidgetProperties(options.initialConfigJSON);
  16. this.onInit(options.registry.params);
  17. },
  18. destroy: function destroy() {
  19. this.onDestroy();
  20. CustomWidget.inherited('destroy', this, arguments);
  21. },
  22. _initContentRoot: function _initContentRoot() {
  23. var contentRoot = this.getContentRootNode();
  24. contentRoot.addClass('staticContent');
  25. var scroll = this.registry.scroll || 'scrollY';
  26. contentRoot.addClass('customWidget_' + scroll);
  27. },
  28. _initWidgetProperties: function _initWidgetProperties(config) {
  29. var root = this.getWidgetStyleNode();
  30. if (config.fillColor) {
  31. root.addClass('fill-' + config.fillColor);
  32. }
  33. if (config.borderColor) {
  34. root.addClass('border-' + config.borderColor);
  35. }
  36. },
  37. render: function render() {
  38. this.onRender();
  39. return Promise.resolve();
  40. },
  41. /**
  42. * API
  43. *
  44. * Initialize the custom widget
  45. *
  46. * @param params - object which contains the parameters to initialize the custom widget
  47. */
  48. onInit: function onInit() /*params*/{},
  49. /**
  50. * API
  51. *
  52. * Destroy the custom widget
  53. */
  54. onDestroy: function onDestroy() {},
  55. /**
  56. * API
  57. *
  58. * Render the custom widget
  59. */
  60. onRender: function onRender() {},
  61. getWidgetStyleNode: function getWidgetStyleNode() {
  62. return $(this.el);
  63. },
  64. getContentRootNode: function getContentRootNode() {
  65. return this.$el;
  66. },
  67. /**
  68. * Register an event with the handler and context.
  69. *
  70. * @param eventName - name of the event
  71. * @param handler - event handler
  72. * @param context - context of the event handler
  73. */
  74. on: function on(eventName, handler, context) {
  75. this.eventRouter.on(eventName, handler, context);
  76. },
  77. /**
  78. * Unregister an event with the handler and context
  79. *
  80. * @param eventName - name of the event
  81. * @param handler - event handler
  82. * @param context - context of the event handler
  83. */
  84. off: function off(eventName, handler, context) {
  85. this.eventRouter.off(eventName, handler, context);
  86. },
  87. /**
  88. * Triggers an event
  89. *
  90. * @param eventName - name of the event
  91. * @param event - event object
  92. */
  93. trigger: function trigger(eventName, event) {
  94. this.eventRouter.trigger(eventName, event);
  95. }
  96. });
  97. return CustomWidget;
  98. });
  99. //# sourceMappingURL=CustomWidget.js.map