2018-12-07 02:46:47 +00:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import AsyncSelect from 'react-select/lib/Async';
|
2018-12-10 04:05:54 +00:00
|
|
|
import toaster from '../toast';
|
2018-12-07 02:46:47 +00:00
|
|
|
import { gettext } from '../../utils/constants';
|
2018-12-21 06:25:15 +00:00
|
|
|
import { Button, Modal, ModalHeader, ModalBody } from 'reactstrap';
|
2018-12-07 02:46:47 +00:00
|
|
|
import { seafileAPI } from '../../utils/seafile-api.js';
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
itemName: PropTypes.string.isRequired,
|
|
|
|
repoID: PropTypes.string.isRequired,
|
|
|
|
toggleDialog: PropTypes.func.isRequired,
|
|
|
|
submit: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
class TransferDialog extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
selectedOption: null,
|
|
|
|
errorMsg: [],
|
|
|
|
sharedItems: []
|
|
|
|
};
|
|
|
|
this.options = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSelectChange = (option) => {
|
|
|
|
this.setState({selectedOption: option});
|
|
|
|
this.options = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
loadOptions = (value, callback) => {
|
|
|
|
if (value.trim().length > 0) {
|
|
|
|
seafileAPI.searchUsers(value.trim()).then((res) => {
|
|
|
|
this.options = [];
|
|
|
|
for (let i = 0 ; i < res.data.users.length; i++) {
|
|
|
|
let obj = {};
|
|
|
|
obj.value = res.data.users[i].name;
|
|
|
|
obj.email = res.data.users[i].email;
|
|
|
|
obj.label =
|
|
|
|
<Fragment>
|
|
|
|
<img src={res.data.users[i].avatar_url} className="avatar reviewer-select-avatar" alt=""/>
|
|
|
|
<span className='reviewer-select-name'>{res.data.users[i].name}</span>
|
|
|
|
</Fragment>;
|
|
|
|
this.options.push(obj);
|
|
|
|
}
|
|
|
|
callback(this.options);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
submit = () => {
|
|
|
|
let repoID = this.props.repoID;
|
|
|
|
let user = this.state.selectedOption.email;
|
|
|
|
seafileAPI.transferRepo(repoID, user).then(res => {
|
2018-12-10 04:05:54 +00:00
|
|
|
let message = gettext('Successfully transferred the library.');
|
|
|
|
toaster.success(message);
|
2018-12-07 02:46:47 +00:00
|
|
|
this.props.submit(repoID);
|
|
|
|
this.props.toggleDialog();
|
2018-12-10 04:05:54 +00:00
|
|
|
}).catch(res => {
|
2018-12-21 06:25:15 +00:00
|
|
|
let message = gettext('Failed. Please check the network.');
|
|
|
|
this.props.toggleDialog();
|
|
|
|
toaster.danger(message);
|
|
|
|
});
|
2018-12-07 02:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const itemName = this.props.itemName;
|
2018-12-10 06:29:30 +00:00
|
|
|
const innerSpan = '<span class="sf-font" title=' + itemName + '>' + itemName +'</span>';
|
|
|
|
let msg = gettext('Transfer Library {library_name} To');
|
|
|
|
let message = msg.replace('{library_name}', innerSpan);
|
2018-12-07 02:46:47 +00:00
|
|
|
return (
|
|
|
|
<Modal isOpen={true} centered={true}>
|
|
|
|
<ModalHeader toggle={this.props.toggleDialog}>
|
2018-12-10 06:29:30 +00:00
|
|
|
<div dangerouslySetInnerHTML={{__html:message}} />
|
2018-12-07 02:46:47 +00:00
|
|
|
</ModalHeader>
|
|
|
|
<ModalBody>
|
|
|
|
<AsyncSelect
|
|
|
|
className='reviewer-select' isFocused
|
|
|
|
loadOptions={this.loadOptions}
|
|
|
|
placeholder={gettext('Please enter 1 or more character')}
|
|
|
|
onChange={this.handleSelectChange}
|
|
|
|
isClearable classNamePrefix
|
|
|
|
inputId={'react-select-transfer-input'}
|
|
|
|
/><br />
|
2018-12-12 08:23:41 +00:00
|
|
|
<Button color="primary" onClick={this.submit}>{gettext('Submit')}</Button>
|
2018-12-07 02:46:47 +00:00
|
|
|
</ModalBody>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TransferDialog.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default TransferDialog;
|