DataSlotsViewAuthoringToolbar.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /**
  6. * Licensed Materials - Property of IBM
  7. * IBM Watson Analytics (C) Copyright IBM Corp. 2019
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define(['jquery', '../../../lib/@waca/dashboard-common/dist/ui/AuthoringToolbar'], function ($, AuthoringToolbar) {
  11. 'use strict';
  12. /*
  13. * This class override the AuthoringToolbar default behaviours so that the toolbar
  14. * can synchronize the re-rendering of the DataSlotsView when the toolbar/flyout get
  15. * destroy(removed)
  16. *
  17. */
  18. var DataSlotsViewAuthoringToolbar = function (_AuthoringToolbar) {
  19. _inherits(DataSlotsViewAuthoringToolbar, _AuthoringToolbar);
  20. function DataSlotsViewAuthoringToolbar(options) {
  21. _classCallCheck(this, DataSlotsViewAuthoringToolbar);
  22. var _this = _possibleConstructorReturn(this, _AuthoringToolbar.call(this, options));
  23. DataSlotsViewAuthoringToolbar.inherited('init', _this, arguments);
  24. _this.dataSlotsView = options.dataSlotsView;
  25. _this.isShowingPreviousView = false;
  26. _this.isShowingNextView = false;
  27. _this.isRemoving = false;
  28. _this.on('flyout:hide', _this.onHideFlyout.bind(_this));
  29. _this.on('toolbar:hide', _this.onHideToolbar.bind(_this));
  30. return _this;
  31. }
  32. DataSlotsViewAuthoringToolbar.prototype.onHideFlyout = function onHideFlyout(event) {
  33. //Note that 'flyout:hide' is triggered when Flyout.close() is called
  34. //This is different that the 'toolbar:hide' hide event. The 'toolbar:hide' is called by the AuthoringToolbar when it destroys the flyout
  35. if (event instanceof $.Event) {
  36. // This event is triggered only when user clicks anywhere in Focuse Mode or press Escape to close and destroy the toolbar.
  37. this.dataSlotsView._clearToolbar();
  38. this.dataSlotsView._reRender();
  39. } else if (!this.isShowingPreviousView && !this.isShowingNextView && !this.isRemoving) {
  40. // Handle the case when the application manually call Flyout.close() to close the toolbar flyout
  41. // Currently only Filter flyouts manually call Flyout.close()
  42. this.dataSlotsView._setIsImplicitClosingTheToolbar(true);
  43. } else {
  44. this.dataSlotsView._clearToolbar();
  45. }
  46. };
  47. DataSlotsViewAuthoringToolbar.prototype.onHideToolbar = function onHideToolbar() {
  48. // Trigger by the AuthoringToolbar when it destroys the current opened flyout
  49. if (!this.isShowingPreviousView && !this.isShowingNextView && !this.isRemoving) {
  50. //Only reRender the if and only if:
  51. //1. Not launch NextView
  52. //2. Not click the top banner to go back to the previous view
  53. //3. Not destroying this toolbar
  54. this.dataSlotsView._reRender();
  55. } else if (!this.isShowingPreviousView && !this.isShowingNextView && this.isRemoving) {
  56. // cover case when leaving authoringToolbar and opening MUI (i.e. calculation dialog)
  57. // No previous or next value to show, and we are removing toolbar, in this case make sure
  58. // to clear the toolbar
  59. this.dataSlotsView._clearToolbar();
  60. }
  61. };
  62. DataSlotsViewAuthoringToolbar.prototype.showPreviousView = function showPreviousView() {
  63. var _AuthoringToolbar$pro;
  64. this.isShowingPreviousView = true;
  65. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  66. args[_key] = arguments[_key];
  67. }
  68. (_AuthoringToolbar$pro = _AuthoringToolbar.prototype.showPreviousView).call.apply(_AuthoringToolbar$pro, [this].concat(args));
  69. };
  70. DataSlotsViewAuthoringToolbar.prototype.pushItemsOnStack = function pushItemsOnStack() {
  71. var _AuthoringToolbar$pro2;
  72. //This function is called when click to show NextView from the toolbar
  73. this.isShowingNextView = true;
  74. for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  75. args[_key2] = arguments[_key2];
  76. }
  77. (_AuthoringToolbar$pro2 = _AuthoringToolbar.prototype.pushItemsOnStack).call.apply(_AuthoringToolbar$pro2, [this].concat(args));
  78. };
  79. DataSlotsViewAuthoringToolbar.prototype.remove = function remove() {
  80. if (!this.isRemoving) {
  81. var _AuthoringToolbar$pro3;
  82. this.isRemoving = true;
  83. for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  84. args[_key3] = arguments[_key3];
  85. }
  86. (_AuthoringToolbar$pro3 = _AuthoringToolbar.prototype.remove).call.apply(_AuthoringToolbar$pro3, [this].concat(args));
  87. }
  88. };
  89. return DataSlotsViewAuthoringToolbar;
  90. }(AuthoringToolbar);
  91. return DataSlotsViewAuthoringToolbar;
  92. });
  93. //# sourceMappingURL=DataSlotsViewAuthoringToolbar.js.map