2019-11-12 13:59:55 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Modal, ModalHeader, ModalBody } from 'reactstrap';
|
|
|
|
import { SimpleEditor } from '@seafile/seafile-editor';
|
|
|
|
import { gettext } from '../../utils/constants';
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
title: PropTypes.string,
|
2019-11-16 11:21:15 +00:00
|
|
|
content: PropTypes.string,
|
2019-11-12 13:59:55 +00:00
|
|
|
onCommit: PropTypes.func.isRequired,
|
|
|
|
onCloseEditorDialog: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
class TermsEditorDialog extends React.Component {
|
|
|
|
|
2023-12-07 06:20:29 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
isValueChanged: false,
|
|
|
|
};
|
|
|
|
this.editorRef = React.createRef();
|
|
|
|
}
|
|
|
|
|
2019-11-12 13:59:55 +00:00
|
|
|
static defaultProps = {
|
|
|
|
title: gettext('Terms'),
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-11-12 13:59:55 +00:00
|
|
|
|
|
|
|
onKeyDown = (event) => {
|
|
|
|
event.stopPropagation();
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-11-12 13:59:55 +00:00
|
|
|
|
|
|
|
toggle = () => {
|
2023-12-07 06:20:29 +00:00
|
|
|
const { isValueChanged } = this.state;
|
|
|
|
if (isValueChanged) {
|
2019-11-12 13:59:55 +00:00
|
|
|
let currentContent = this.getCurrentContent();
|
|
|
|
this.props.onCommit(currentContent);
|
|
|
|
}
|
|
|
|
this.props.onCloseEditorDialog();
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-11-12 13:59:55 +00:00
|
|
|
|
2023-12-07 06:20:29 +00:00
|
|
|
onValueChanged = () => {
|
|
|
|
return this.setState({isValueChanged: true});
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-11-12 13:59:55 +00:00
|
|
|
|
|
|
|
getCurrentContent = () => {
|
2023-12-07 06:20:29 +00:00
|
|
|
return this.editorRef.current.getValue();
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-11-12 13:59:55 +00:00
|
|
|
|
|
|
|
setSimpleEditorRef = (editor) => {
|
|
|
|
this.simpleEditor = editor;
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-11-12 13:59:55 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
let { content, title } = this.props;
|
|
|
|
return (
|
2020-11-02 05:56:35 +00:00
|
|
|
<Modal
|
|
|
|
isOpen={true}
|
|
|
|
toggle={this.toggle}
|
2019-11-12 13:59:55 +00:00
|
|
|
onKeyDown={this.onKeyDown}
|
|
|
|
wrapClassName={'conditions-editor-dialog-wrapper'}
|
|
|
|
className={'conditions-editor-dialog'}
|
|
|
|
contentClassName={'conditions-editor-dialog-content'}
|
|
|
|
size={'lg'}
|
|
|
|
style={{width: 770}}
|
|
|
|
>
|
|
|
|
<ModalHeader className="conditions-editor-dialog-title" toggle={this.toggle}>{title}</ModalHeader>
|
|
|
|
<ModalBody className={'conditions-editor-dialog-main'}>
|
2020-11-02 05:56:35 +00:00
|
|
|
<SimpleEditor
|
2023-12-07 06:20:29 +00:00
|
|
|
ref={this.editorRef}
|
2019-11-16 11:21:15 +00:00
|
|
|
value={content || ''}
|
2023-12-07 06:20:29 +00:00
|
|
|
onValueChanged={this.onValueChanged}
|
2019-11-12 13:59:55 +00:00
|
|
|
/>
|
|
|
|
</ModalBody>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TermsEditorDialog.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default TermsEditorDialog;
|