1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-10 11:22:09 +00:00
seahub/frontend/src/components/dialog/insert-file-dialog.js

78 lines
2.0 KiB
JavaScript
Raw Normal View History

2019-03-26 03:18:41 +00:00
import React from 'react';
import PropTypes from 'prop-types';
2019-05-15 06:56:46 +00:00
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
2019-03-26 03:18:41 +00:00
import { gettext } from '../../utils/constants';
import FileChooser from '../file-chooser/file-chooser';
const propTypes = {
repoID: PropTypes.string.isRequired,
filePath: PropTypes.string.isRequired,
toggleCancel: PropTypes.func.isRequired,
getInsertLink: PropTypes.func.isRequired,
};
class InsertFileDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
repo: null,
selectedPath: '',
};
}
handleInsert = () => {
this.props.getInsertLink(this.state.repo.repo_id, this.state.selectedPath);
this.props.toggleCancel();
}
onDirentItemClick = (repo, selectedPath, dirent) => {
if (dirent.type === 'file') {
this.setState({
repo: repo,
selectedPath: selectedPath,
});
}
else {
this.setState({
repo: null,
selectedPath: '',
});
}
}
onRepoItemClick = () => {
this.setState({
repo: null,
selectedPath: '',
});
}
render() {
const toggle = this.props.toggleCancel;
return (
2019-03-26 07:03:27 +00:00
<Modal isOpen={true} toggle={toggle} >
2019-03-26 03:18:41 +00:00
<ModalHeader toggle={toggle}>{gettext('Select File')}</ModalHeader>
<ModalBody>
<FileChooser
isShowFile={true}
repoID={this.props.repoID}
onDirentItemClick={this.onDirentItemClick}
onRepoItemClick={this.onRepoItemClick}
mode="current_repo_and_other_repos"
/>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={toggle}>{gettext('Cancel')}</Button>
2019-03-26 07:03:27 +00:00
{this.state.selectedPath ? <Button color="primary" onClick={this.handleInsert}>{gettext('Submit')}</Button>
: <Button color="primary" disabled>{gettext('Submit')}</Button>}
2019-03-26 03:18:41 +00:00
</ModalFooter>
</Modal>
);
}
}
InsertFileDialog.propTypes = propTypes;
export default InsertFileDialog;