mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-04 08:28:11 +00:00
Add related documents UI (#2577)
This commit is contained in:
102
frontend/src/components/dialog/add-related-file-dialog.js
Normal file
102
frontend/src/components/dialog/add-related-file-dialog.js
Normal file
@@ -0,0 +1,102 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Alert } from 'reactstrap';
|
||||
import { gettext } from '../../utils/constants';
|
||||
import { seafileAPI } from '../../utils/seafile-api';
|
||||
import FileChooser from '../file-chooser/file-chooser';
|
||||
|
||||
const propTypes = {
|
||||
repoID: PropTypes.string.isRequired,
|
||||
filePath: PropTypes.string.isRequired,
|
||||
toggleCancel: PropTypes.func.isRequired,
|
||||
onRelatedFileChange: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
class AddRelatedFileDialog extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
repo: null,
|
||||
selectedPath: '',
|
||||
isShowFile: true,
|
||||
errMessage: '',
|
||||
};
|
||||
}
|
||||
|
||||
handleSubmit = () => {
|
||||
this.onAddRelatedFile();
|
||||
}
|
||||
|
||||
onAddRelatedFile = () => {
|
||||
let { repo, selectedPath } = this.state;
|
||||
let oRepoID = this.props.repoID;
|
||||
let rRepoID = repo.repo_id;
|
||||
let oFilePath = this.props.filePath;
|
||||
let rFilePath = selectedPath;
|
||||
|
||||
if (oRepoID === rRepoID && oFilePath === rFilePath) {
|
||||
let message = gettext('Can not select self as a related file.');
|
||||
this.setState({errMessage: message});
|
||||
return;
|
||||
}
|
||||
|
||||
seafileAPI.addRelatedFile(oRepoID, rRepoID, oFilePath, rFilePath).then((res) => {
|
||||
this.props.onRelatedFileChange();
|
||||
this.toggle();
|
||||
}).catch((error) => {
|
||||
if (error.response) {
|
||||
this.setState({
|
||||
errMessage: error.response.data.error_msg
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggle = () => {
|
||||
this.props.toggleCancel();
|
||||
}
|
||||
|
||||
onDirentItemClick = (repo, selectedPath, dirent) => {
|
||||
if(dirent.type === 'file') {
|
||||
this.setState({
|
||||
repo: repo,
|
||||
selectedPath: selectedPath,
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.setState({
|
||||
repo: null,
|
||||
selectedPath: '',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal isOpen={true} className="sf-add-related-file">
|
||||
<ModalHeader toggle={this.toggle}>{gettext('Select File')}</ModalHeader>
|
||||
<ModalBody>
|
||||
<FileChooser
|
||||
isShowFile={this.state.isShowFile}
|
||||
repoID={this.props.repoID}
|
||||
onDirentItemClick={this.onDirentItemClick}
|
||||
/>
|
||||
{this.state.errMessage && <Alert color="danger">{this.state.errMessage}</Alert>}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
|
||||
{ this.state.selectedPath ?
|
||||
<Button color="primary" onClick={this.handleSubmit}>{gettext('Submit')}</Button>
|
||||
:
|
||||
<Button color="primary" disabled>{gettext('Submit')}</Button>
|
||||
}
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
AddRelatedFileDialog.propTypes = propTypes;
|
||||
|
||||
export default AddRelatedFileDialog;
|
Reference in New Issue
Block a user