1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-11 03:42:16 +00:00
seahub/frontend/src/components/dialog/transfer-dialog.js

102 lines
3.0 KiB
JavaScript
Raw Normal View History

import React from 'react';
2018-12-07 02:46:47 +00:00
import PropTypes from 'prop-types';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
2019-05-05 08:17:56 +00:00
import Select from 'react-select';
import makeAnimated from 'react-select/lib/animated';
import { seafileAPI } from '../../utils/seafile-api.js';
import { gettext, isPro } from '../../utils/constants';
import UserSelect from '../user-select';
2018-12-07 02:46:47 +00:00
const propTypes = {
itemName: 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: [],
2019-05-05 08:17:56 +00:00
transferToUser: true,
2018-12-07 02:46:47 +00:00
};
this.options = [];
}
handleSelectChange = (option) => {
this.setState({selectedOption: option});
}
submit = () => {
let user = this.state.selectedOption;
this.props.submit(user);
2018-12-07 02:46:47 +00:00
}
2019-05-05 08:17:56 +00:00
componentDidMount() {
2019-05-09 13:26:20 +00:00
seafileAPI.listDepartments().then((res) => {
2019-05-05 08:17:56 +00:00
for (let i = 0 ; i < res.data.length; i++) {
let obj = {};
obj.value = res.data[i].name;
2019-05-09 13:26:20 +00:00
obj.email = res.data[i].email;
2019-05-05 08:17:56 +00:00
obj.label = res.data[i].name;
this.options.push(obj);
}
});
}
onClick = () => {
this.setState({
transferToUser: !this.state.transferToUser,
});
}
2018-12-07 02:46:47 +00:00
render() {
const itemName = this.props.itemName;
2019-02-12 02:50:02 +00:00
const innerSpan = '<span class="op-target" title=' + itemName + '>' + itemName +'</span>';
2019-05-05 08:17:56 +00:00
let msg = gettext('Transfer Library {library_name}');
2018-12-10 06:29:30 +00:00
let message = msg.replace('{library_name}', innerSpan);
2018-12-07 02:46:47 +00:00
return (
2019-05-05 08:17:56 +00:00
<Modal isOpen={true}>
2018-12-07 02:46:47 +00:00
<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>
2019-05-05 08:17:56 +00:00
{this.state.transferToUser ?
<UserSelect
ref="userSelect"
isMulti={false}
className="reviewer-select"
placeholder={gettext('Search users')}
onSelectChange={this.handleSelectChange}
/> :
<Select
isClearable
isMulti={false}
maxMenuHeight={200}
hideSelectedOptions={true}
components={makeAnimated()}
2019-05-10 04:10:10 +00:00
placeholder={gettext('Select a department')}
2019-05-05 08:17:56 +00:00
options={this.options}
onChange={this.handleSelectChange}
/>
}
{isPro &&
<a href="#" onClick={this.onClick}>{this.state.transferToUser ?
2019-05-10 04:10:10 +00:00
gettext('Transfer to department'): gettext('Transfer to user')}
2019-05-05 08:17:56 +00:00
</a>
}
2018-12-07 02:46:47 +00:00
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={this.props.toggleDialog}>{gettext('Cancel')}</Button>
<Button color="primary" onClick={this.submit}>{gettext('Submit')}</Button>
</ModalFooter>
2018-12-07 02:46:47 +00:00
</Modal>
);
}
}
TransferDialog.propTypes = propTypes;
export default TransferDialog;