VisChangerView.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2018
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. /**
  8. *
  9. * View to swap the Live Widget Visualization
  10. * Options
  11. * {
  12. * showTitles: boolean, // Whether to show the titles for the available/recommended visualizations
  13. * visualizations: {
  14. * recommended: [], // Array of visualizations to place in recommended section
  15. * other: [] // Array of visualizations to put in other section
  16. * },
  17. * currentVis: String, // The id of the currently selected visualization
  18. * widget: Live Widget, // The widget that is creating the vischanger view
  19. * inFocusView: bool // If the widget is in focus view, will render titles and not limit selections
  20. * }
  21. *
  22. **/
  23. define(['../../../lib/@waca/core-client/js/core-client/ui/core/View', '../../../lib/@waca/dashboard-common/dist/utils/Flyout', '../nls/StringResources', 'jquery', 'underscore', '../../../lib/@waca/core-client/js/core-client/utils/JQueryExt'], function (BaseView, Flyout, resources, $, _) {
  24. var View = BaseView.extend({
  25. init: function init(options) {
  26. View.inherited('init', this, arguments);
  27. this.visualizations = {};
  28. _.extend(this, options || {});
  29. },
  30. /**
  31. * Flyout is closing and has already destoyed itself, cleanup our member variables and view
  32. */
  33. onPopupDone: function onPopupDone() {
  34. this.flyout = null;
  35. this._cleanup();
  36. },
  37. /**
  38. * Clean up the props of this object (flyout and vis changer flyout view)
  39. */
  40. _cleanup: function _cleanup() {
  41. if (this.flyout) {
  42. this.flyout.destroy();
  43. }
  44. this.flyout = null;
  45. if (this.visChangerFlyoutView) {
  46. this.visChangerFlyoutView.removeDialog();
  47. }
  48. this.visChangerFlyoutView = null;
  49. },
  50. /**
  51. * When we remove the object we want to cleanup its elements.
  52. * @returns {object} this
  53. */
  54. remove: function remove() {
  55. this._cleanup();
  56. View.inherited('remove', this, arguments);
  57. return this;
  58. },
  59. setFocus: function setFocus() {
  60. this.$('.vis').first().focus();
  61. },
  62. /**
  63. * Render the flyout and all the flyout view.
  64. * @param {object} currentVis - id, widget
  65. */
  66. render: function render(options) {
  67. _.extend(this, options || {});
  68. this.setElement($('<div class=\'visChangerContainer\'></div>'));
  69. // Initialize the elements, open the flyout and render.
  70. this._initializeElements();
  71. this.flyout.open('.allVisualizations');
  72. if (!this.visChangerFlyoutView) {
  73. this.visChangerFlyoutView = this.dashboard.getFeature('changeVisTypeAction');
  74. }
  75. var dialogOptions = {
  76. currentVis: this.currentVis,
  77. content: this.dashboard.getCanvas().getContent(this.widgetId),
  78. el: this.el,
  79. selectVisCB: this._selectVis.bind(this), // CB for when vis has changed
  80. dashboard: this.dashboard
  81. };
  82. return this.visChangerFlyoutView.openDialog(options, dialogOptions);
  83. },
  84. /**
  85. * Hide flyout and clean up.
  86. */
  87. _hideFlyout: function _hideFlyout() {
  88. this.$el.trigger($.Event('keyup', { keyCode: 27 })); // Trigger escape keypress to hide the toolbar
  89. this._cleanup();
  90. },
  91. /**
  92. * Callback method for when the vis changer flyout view changes a vis.
  93. */
  94. _selectVis: function _selectVis() {
  95. this._hideFlyout();
  96. },
  97. getRenderedHtml: function getRenderedHtml() {
  98. var $content = $('<div class="toolbarPopoverContent"></div>');
  99. $content.append(this.$el);
  100. return $content;
  101. },
  102. _getFlyout: function _getFlyout(options) {
  103. return new Flyout(options);
  104. },
  105. /**
  106. * Initialize the elements needed to render the vis changer
  107. */
  108. _initializeElements: function _initializeElements() {
  109. this._cleanup();
  110. var options = {
  111. viewInstance: this,
  112. selector: '.allVisualizations',
  113. content: this.el,
  114. popoverClass: 'visChangerPopover',
  115. placement: 'top',
  116. maxHt: 400,
  117. trigger: 'manual',
  118. modal: true
  119. };
  120. this.flyout = this._getFlyout(options);
  121. }
  122. });
  123. return View;
  124. });
  125. //# sourceMappingURL=VisChangerView.js.map