AlignDialog.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018, 2021
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define(['../../../../../lib/@waca/core-client/js/core-client/ui/core/View', 'react', 'react-dom', 'ca-ui-toolkit', 'jquery', '../../../../../app/nls/StringResources', '../../../../../lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/align--horizontal-left_32', '../../../../../lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/align--horizontal-center_32', '../../../../../lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/align--horizontal-right_32', '../../../../../lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/align--vertical-top_32', '../../../../../lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/align--vertical-center_32', '../../../../../lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/align--vertical-bottom_32'], function (View, React, ReactDOM, UI_Toolkit, $, stringResources, iconAlignLeft, iconAlignCenter, iconAlignRight, iconAlignTop, iconAlignMiddle, iconAlignBottom) {
  11. var AlignDialog = View.extend({
  12. init: function init() {
  13. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  14. AlignDialog.inherited('init', this, arguments);
  15. this.action = options.actions ? options.actions.apply : options.action;
  16. },
  17. //@dodo convoluted that have to provide this function so that renderCallBack can be called.
  18. //Will fix this in dashboard-common/ui/AuthoringToolbar to pass in the authoringToolbar instance when instantiate an instance
  19. preload: function preload() {
  20. return Promise.resolve();
  21. },
  22. //@dodo convoluted that have to provide this function
  23. //Will fix this in dashboard-common/ui/AuthoringToolbar to pass in the authoringToolbar instance when instantiate an instance
  24. renderCallBack: function renderCallBack(authoringToolbar) {
  25. this.authoringToolbar = authoringToolbar;
  26. this.authoringToolbar.on('flyout:hide', this._unmountReactComponent.bind(this));
  27. },
  28. remove: function remove() {
  29. this._unmountReactComponent();
  30. this.authoringToolbar.off('flyout:hide', this._unmountReactComponent.bind(this));
  31. this.action = null;
  32. this.authoringToolbar = null;
  33. if (this.$container) {
  34. this.$container.remove();
  35. this.$container = null;
  36. }
  37. AlignDialog.inherited('remove', this, arguments);
  38. },
  39. _unmountReactComponent: function _unmountReactComponent() {
  40. //Unmount the React component when clicks anywhere in the dashboard to close the flyout
  41. if (this.$container) {
  42. ReactDOM.unmountComponentAtNode(this.$container[0]);
  43. this.$container = null;
  44. }
  45. },
  46. selectItem: function selectItem(value) {
  47. var _this2 = this;
  48. this.action(value);
  49. //this.onUpdate is actually bound to the AuthoringToolbar.hide function
  50. //When a value is selected, call this.onUpdate to destroy the flyout. So when the flyout is destroyed unmount the Reaact component
  51. return this.onUpdate().then(function () {
  52. if (_this2.$container) {
  53. ReactDOM.unmountComponentAtNode(_this2.$container[0]);
  54. _this2.$container = null;
  55. }
  56. });
  57. },
  58. render: function render() {
  59. var _this4 = this;
  60. var _this = this;
  61. return new Promise(function (resolve) {
  62. var Menu = UI_Toolkit.Menu;
  63. var MenuList = UI_Toolkit.Menu.List;
  64. var AlignMenuWidget = function (_React$Component) {
  65. _inherits(AlignMenuWidget, _React$Component);
  66. function AlignMenuWidget(props) {
  67. _classCallCheck(this, AlignMenuWidget);
  68. var _this3 = _possibleConstructorReturn(this, _React$Component.call(this, props));
  69. _this3.state = {
  70. selected: {}
  71. };
  72. return _this3;
  73. }
  74. AlignMenuWidget.prototype._onChange = function _onChange(label, v) {
  75. var newSelection = {};
  76. var oldSelection = this.state.selected;
  77. for (var item in oldSelection) {
  78. if (oldSelection.hasOwnProperty(item)) {
  79. newSelection[item] = oldSelection[item];
  80. }
  81. }
  82. newSelection[label] = v;
  83. this.setState({ selected: newSelection });
  84. _this.selectItem(v);
  85. };
  86. AlignMenuWidget.prototype.render = function render() {
  87. return React.createElement(Menu, {
  88. onChange: this._onChange.bind(this),
  89. selected: this.state.selected
  90. }, [React.createElement(MenuList, {
  91. name: 'align',
  92. content: [{
  93. label: stringResources.get('alignWidgetLeft'),
  94. value: 'left',
  95. icon: iconAlignLeft.default
  96. }, {
  97. label: stringResources.get('alignWidgetCenter'),
  98. value: 'center',
  99. icon: iconAlignCenter.default
  100. }, {
  101. label: stringResources.get('alignWidgetRight'),
  102. value: 'right',
  103. icon: iconAlignRight.default
  104. }, {
  105. label: stringResources.get('alignWidgetTop'),
  106. value: 'top',
  107. icon: iconAlignTop.default
  108. }, {
  109. label: stringResources.get('alignWidgetMiddle'),
  110. value: 'middle',
  111. icon: iconAlignMiddle.default
  112. }, {
  113. label: stringResources.get('alignWidgetBottom'),
  114. value: 'bottom',
  115. icon: iconAlignBottom.default
  116. }]
  117. })]);
  118. };
  119. return AlignMenuWidget;
  120. }(React.Component);
  121. _this4.$container = $('<div></div>', { 'class': 'ba-theme-default selectionList' });
  122. _this4.$el.addClass('content').append(_this4.$container);
  123. ReactDOM.render(React.createElement(AlignMenuWidget), _this4.$container[0], resolve);
  124. });
  125. }
  126. });
  127. return AlignDialog;
  128. });
  129. //# sourceMappingURL=AlignDialog.js.map