1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-09 19:01:42 +00:00

insert iamge

This commit is contained in:
Michael An
2019-04-18 16:42:27 +08:00
parent 309aa08ce8
commit 2eb1e15b05
3 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { gettext } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import FileChooser from '../file-chooser/file-chooser';
import { siteRoot } from '../../utils/constants';
import '../../css/insert-repo-image-dialog.css';
const propTypes = {
repoID: PropTypes.string.isRequired,
filePath: PropTypes.string.isRequired,
toggleCancel: PropTypes.func.isRequired,
};
class InsertRepoImageDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
repo: null,
selectedPath: '',
};
}
insertImage = () => {
const url = siteRoot + 'thumbnail/' + this.state.repo.repo_id + '/1024' + this.state.selectedPath;
window.richMarkdownEditor.onInsertImage(url);
this.props.toggleCancel();
}
onDirentItemClick = (repo, selectedPath, dirent) => {
if (dirent.type === 'file' && Utils.imageCheck(dirent.name)) {
this.setState({
repo: repo,
selectedPath: selectedPath,
});
}
else {
this.setState({repo: null, selectedPath: ''});
}
}
onRepoItemClick = () => {
this.setState({repo: null, selectedPath: ''});
}
render() {
const toggle = this.props.toggleCancel;
let imageUrl;
if (this.state.repo) {
imageUrl = siteRoot + 'thumbnail/' + this.state.repo.repo_id + '/1024' + this.state.selectedPath;
}
return (
<Modal isOpen={true} toggle={toggle} size='lg'>
<ModalHeader toggle={toggle}>{gettext('Select Image')}</ModalHeader>
<ModalBody>
<div className="d-flex">
<div className="col-6">
<FileChooser
isShowFile={true}
repoID={this.props.repoID}
onDirentItemClick={this.onDirentItemClick}
onRepoItemClick={this.onRepoItemClick}
mode="current_repo_and_other_repos"
/>
</div>
<div className="insert-image-container col-6">
{imageUrl ?
<img src={imageUrl} className='d-inline-block mh-100 mw-100' alt=''/> :
<span>{gettext("No preview")}</span>
}
</div>
</div>
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={toggle}>{gettext('Cancel')}</Button>
{this.state.selectedPath ?
<Button color="primary" onClick={this.insertImage}>{gettext('Submit')}</Button>
: <Button color="primary" disabled>{gettext('Submit')}</Button>
}
</ModalFooter>
</Modal>
);
}
}
InsertRepoImageDialog.propTypes = propTypes;
export default InsertRepoImageDialog;