StaticWidget.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2017
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['underscore', '../../../lib/@waca/dashboard-common/dist/ui/WidgetBase'], function (_, WidgetBase) {
  8. /**
  9. * The static widget object is a generic class for "static" widget types (e.g. image, text, shapes) that don't require
  10. * interactivity during consumption mode, but do require some (e.g. to set properties) in authoring mode.
  11. */
  12. var StaticWidget = WidgetBase.extend({
  13. focusOn: false,
  14. init: function init() {
  15. StaticWidget.inherited('init', this, arguments);
  16. },
  17. onContainerReady: function onContainerReady() {
  18. StaticWidget.inherited('onContainerReady', this, arguments);
  19. },
  20. /**
  21. * Notify Properties pane on chrome getting selected as well
  22. */
  23. onChromeSelected: function onChromeSelected() {
  24. StaticWidget.inherited('onChromeSelected', this, arguments);
  25. this.onFocus();
  26. },
  27. /**
  28. * Handler for Widget chrome deselect event
  29. */
  30. onChromeDeselected: function onChromeDeselected() {
  31. StaticWidget.inherited('onChromeDeselected', this, arguments);
  32. this.focusOn = false;
  33. },
  34. /**
  35. * Handler for Focus event
  36. * Gets spec for the widget properties and notifies Property pane so that it can
  37. * show properties to change
  38. */
  39. onFocus: function onFocus() {
  40. if (!this.focusOn) {
  41. this.focusOn = true;
  42. }
  43. },
  44. /**
  45. * Virtual Method: Based on properties, generate the HTML for the static content
  46. */
  47. getHtmlRender: function getHtmlRender() {
  48. return null;
  49. },
  50. /**
  51. * Get the node where we can apply style changes like border and fill colors
  52. * @returns
  53. */
  54. getWidgetStyleNode: function getWidgetStyleNode() {
  55. return this.$el.children('.staticContent');
  56. },
  57. /**
  58. * Update the model when a property is changed for this widget, in the properties side panel.
  59. */
  60. onPropertyUpdate: function onPropertyUpdate() {
  61. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  62. StaticWidget.inherited('onPropertyUpdate', this, arguments);
  63. // update model content
  64. this.updateModelContent(null, options.transactionId, options.sender);
  65. },
  66. /**
  67. * Updates the model version of the markup of this widget
  68. * @param updatedHtml An optional parameter of the markup.
  69. * This is to avoid regenerating the markup if it is already known.
  70. */
  71. updateModelContent: function updateModelContent(updatedHtml, transactionId) {
  72. // regenerate the HTML if not passed
  73. if (!updatedHtml) {
  74. updatedHtml = this.getHtmlRender();
  75. }
  76. // update the model to persist the changes. Use transactionId to combine undos
  77. var data = {};
  78. if (transactionId) {
  79. _.extend(data, {
  80. payloadData: {
  81. undoRedoTransactionId: transactionId
  82. }
  83. });
  84. } else {
  85. _.extend(data, {
  86. silent: true
  87. });
  88. }
  89. this.set({
  90. content: updatedHtml
  91. }, data);
  92. }
  93. });
  94. return StaticWidget;
  95. });
  96. //# sourceMappingURL=StaticWidget.js.map