CustomGroupActionsListDialog.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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: Dashboard (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(['../lib/@waca/core-client/js/core-client/ui/core/View', 'underscore', '../widgets/livewidget/nls/StringResources', 'react', 'react-dom', 'ca-ui-toolkit'], function (View, _, stringResources, React, ReactDOM, Toolkit) {
  11. /* eslint react/prop-types: 0 */ // TODO: Remove once we have prop-types brought in from glass.
  12. var Menu = Toolkit.Menu;
  13. /**
  14. * Wrapper around the Menu ui-toolkit item that we pass the list items into and handles the onchange
  15. *
  16. */
  17. var CustomGroupList = function (_React$Component) {
  18. _inherits(CustomGroupList, _React$Component);
  19. function CustomGroupList(props) {
  20. _classCallCheck(this, CustomGroupList);
  21. var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
  22. _this.state = {
  23. selected: {}
  24. };
  25. _this.removeView = props.removeView;
  26. _this.menuContent = props.possibleItems;
  27. return _this;
  28. }
  29. /*
  30. * Call the action associated with the current item selected
  31. */
  32. CustomGroupList.prototype._onChange = function _onChange(label, action) {
  33. action();
  34. this.removeView();
  35. };
  36. CustomGroupList.prototype.render = function render() {
  37. return React.createElement(
  38. Menu,
  39. { onChange: this._onChange.bind(this), selected: this.state.selected },
  40. React.createElement(Menu.List, { content: this.menuContent, name: 'customGroupList' })
  41. );
  42. };
  43. return CustomGroupList;
  44. }(React.Component);
  45. /**
  46. * @classdesc Creates a dropdown list for custom groups with the list items passed
  47. *
  48. * @public
  49. *
  50. * @param {object} options.listItems - The items to list
  51. */
  52. var CustomGroupActionsListDialog = function (_View) {
  53. _inherits(CustomGroupActionsListDialog, _View);
  54. function CustomGroupActionsListDialog(options) {
  55. _classCallCheck(this, CustomGroupActionsListDialog);
  56. var _this2 = _possibleConstructorReturn(this, _View.call(this, options));
  57. _this2.possibleItems = options.possibleItems;
  58. return _this2;
  59. }
  60. CustomGroupActionsListDialog.prototype.remove = function remove() {
  61. var flyout = this.toolbar && this.toolbar.flyout;
  62. if (this.$el) {
  63. ReactDOM.unmountComponentAtNode(this.$el[0]);
  64. }
  65. this.viewState = null;
  66. if (flyout) {
  67. flyout.destroy();
  68. }
  69. _View.prototype.remove.call(this);
  70. };
  71. /**
  72. * @param {Object} toolbar that the dialog is being rendered from.
  73. */
  74. CustomGroupActionsListDialog.prototype.renderCallBack = function renderCallBack(toolbar) {
  75. this.toolbar = toolbar;
  76. };
  77. /**
  78. * Needed so toolbar is set in NextView and the flyout can be closed when remove the dialog
  79. */
  80. CustomGroupActionsListDialog.prototype.preload = function preload() {
  81. return Promise.resolve();
  82. };
  83. CustomGroupActionsListDialog.prototype.render = function render() {
  84. this.$el.addClass('popoverDialogContainer customGroup');
  85. ReactDOM.render(React.createElement(CustomGroupList, { possibleItems: this.possibleItems, removeView: this.remove.bind(this) }), this.$el[0]);
  86. return this;
  87. };
  88. return CustomGroupActionsListDialog;
  89. }(View);
  90. return CustomGroupActionsListDialog;
  91. });
  92. //# sourceMappingURL=CustomGroupActionsListDialog.js.map