WidgetHelper.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Storytelling
  5. * (C) Copyright IBM Corp. 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['baglass/core-client/js/core-client/ui/core/Class'], function (Class) {
  9. var WidgetHelper = Class.extend({
  10. init: function init(options) {
  11. this.dashboardApi = options.dashboardApi;
  12. },
  13. /**
  14. * @param {string} widgetId
  15. * @return WidgetAPI object
  16. */
  17. getWidget: function getWidget(widgetId) {
  18. var content = this.getContent(widgetId);
  19. return content ? content.getFeature('WidgetAPI.deprecated') : null;
  20. },
  21. /**
  22. * @param {string} contentId
  23. * @return ContentAPI object
  24. */
  25. getContent: function getContent(contentId) {
  26. var canvas = this.dashboardApi.getCanvas();
  27. return canvas ? canvas.getContent(contentId) : null;
  28. },
  29. /**
  30. * @param {string} contentId
  31. * @return {Number} event group id
  32. */
  33. getEventGroupId: function getEventGroupId(contentId) {
  34. var eventGroups = this.dashboardApi.getFeature('EventGroups');
  35. return eventGroups.getGroupId(contentId);
  36. },
  37. /**
  38. * Recursively walk the content and it's parent to find the page content
  39. * @param {ContentAPI} content
  40. * @returns {ContentAPI} page content. If a page can not be found, returns null
  41. */
  42. getPageContent: function getPageContent(content) {
  43. var pageContent = null;
  44. while (content) {
  45. if (content.getType() === 'page') {
  46. pageContent = content;
  47. }
  48. content = content.getContainer();
  49. }
  50. return pageContent;
  51. },
  52. /**
  53. * @param {string} contentId
  54. * @return DOM node
  55. */
  56. getContentNode: function getContentNode(contentId) {
  57. var content = this.getContent(contentId);
  58. return content ? content.getFeature('ContentViewDOM').getNode() : null;
  59. },
  60. /**
  61. * @param {string} contentId
  62. * @return DOM node
  63. */
  64. getContentState: function getContentState(contentId) {
  65. var content = this.getContent(contentId);
  66. return content ? content.getFeature('state.internal') : null;
  67. }
  68. });
  69. return WidgetHelper;
  70. });
  71. //# sourceMappingURL=WidgetHelper.js.map