2
0

SavePageControls.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { translate } from 'react-i18next';
  4. import ButtonToolbar from 'react-bootstrap/es/ButtonToolbar';
  5. import SplitButton from 'react-bootstrap/es/SplitButton';
  6. import MenuItem from 'react-bootstrap/es/MenuItem';
  7. import SlackNotification from './SlackNotification';
  8. import GrantSelector from './SavePageControls/GrantSelector';
  9. class SavePageControls extends React.PureComponent {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. pageId: this.props.pageId,
  14. };
  15. this.getCurrentOptionsToSave = this.getCurrentOptionsToSave.bind(this);
  16. this.submit = this.submit.bind(this);
  17. this.submitAndOverwriteScopesOfDescendants = this.submitAndOverwriteScopesOfDescendants.bind(this);
  18. }
  19. componentWillMount() {
  20. }
  21. getCurrentOptionsToSave() {
  22. const slackNotificationOptions = this.refs.slackNotification.getCurrentOptionsToSave();
  23. const pageTagOptions = this.refs.pageTagForm.getCurrentOptionsToSave();
  24. const grantSelectorOptions = this.refs.grantSelector.getCurrentOptionsToSave();
  25. return Object.assign(slackNotificationOptions, pageTagOptions, grantSelectorOptions);
  26. }
  27. /**
  28. * update pageId of state
  29. * @param {string} pageId
  30. */
  31. setPageId(pageId) {
  32. this.setState({pageId});
  33. }
  34. submit() {
  35. this.props.onSubmit();
  36. }
  37. submitAndOverwriteScopesOfDescendants() {
  38. this.props.onSubmit({ overwriteScopesOfDescendants: true });
  39. }
  40. render() {
  41. const { t } = this.props;
  42. const config = this.props.crowi.getConfig();
  43. const isAclEnabled = config.isAclEnabled;
  44. const labelSubmitButton = this.state.pageId == null ? t('Create') : t('Update');
  45. const labelOverwriteScopes = t('page_edit.overwrite_scopes', { operation: labelSubmitButton });
  46. return (
  47. <div className="d-flex align-items-center form-inline">
  48. <div className="mr-2">
  49. <SlackNotification
  50. ref='slackNotification'
  51. crowi={this.props.crowi}
  52. pageId={this.props.pageId}
  53. pagePath={this.props.pagePath}
  54. isSlackEnabled={false}
  55. slackChannels={this.props.slackChannels} />
  56. </div>
  57. {isAclEnabled &&
  58. <div className="mr-2">
  59. <GrantSelector crowi={this.props.crowi}
  60. ref={(elem) => {
  61. if (this.refs.grantSelector == null) {
  62. this.refs.grantSelector = elem.getWrappedInstance();
  63. }
  64. }}
  65. grant={this.props.grant}
  66. grantGroupId={this.props.grantGroupId}
  67. grantGroupName={this.props.grantGroupName} />
  68. </div>
  69. }
  70. <ButtonToolbar>
  71. <SplitButton id="spl-btn-submit" bsStyle="primary" className="btn-submit" dropup pullRight onClick={this.submit}
  72. title={labelSubmitButton}>
  73. <MenuItem eventKey="1" onClick={this.submitAndOverwriteScopesOfDescendants}>{labelOverwriteScopes}</MenuItem>
  74. {/* <MenuItem divider /> */}
  75. </SplitButton>
  76. </ButtonToolbar>
  77. </div>
  78. );
  79. }
  80. }
  81. SavePageControls.propTypes = {
  82. t: PropTypes.func.isRequired, // i18next
  83. crowi: PropTypes.object.isRequired,
  84. onSubmit: PropTypes.func.isRequired,
  85. pageId: PropTypes.string,
  86. // for SlackNotification
  87. pagePath: PropTypes.string,
  88. slackChannels: PropTypes.string,
  89. pageTags: PropTypes.string,
  90. // for GrantSelector
  91. grant: PropTypes.number,
  92. grantGroupId: PropTypes.string,
  93. grantGroupName: PropTypes.string,
  94. };
  95. export default translate()(SavePageControls);