diff --git a/ShadowEditor.Web/src/editor/system/dept/EditDeptWindow.jsx b/ShadowEditor.Web/src/editor/system/dept/EditDeptWindow.jsx new file mode 100644 index 00000000..81b9034a --- /dev/null +++ b/ShadowEditor.Web/src/editor/system/dept/EditDeptWindow.jsx @@ -0,0 +1,96 @@ +import { PropTypes, Window, Content, Buttons, Form, FormControl, Label, Input, Button } from '../../../third_party'; + +/** + * 组织机构编辑窗口 + * @author tengge / https://github.com/tengge1 + */ +class EditDeptWindow extends React.Component { + constructor(props) { + super(props); + + this.state = { + id: props.id, + name: props.name, + }; + + this.handleChange = this.handleChange.bind(this); + this.handleSave = this.handleSave.bind(this, props.callback); + this.handleClose = this.handleClose.bind(this); + } + + render() { + const { name } = this.state; + + return + +
+ + + + +
+
+ + + + +
; + } + + handleChange(value, name) { + this.setState({ + [name]: value, + }); + } + + handleSave(callback) { + const { id, name } = this.state; + + if (!name || name.trim() === '') { + app.toast(_t('Name is not allowed to be empty.')); + return; + } + + const url = !id ? `/api/Role/Add` : `/api/Role/Edit`; + + fetch(`${app.options.server}${url}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: `ID=${id}&Name=${name}`, + }).then(response => { + response.json().then(json => { + if (json.Code !== 200) { + app.toast(_t(json.Msg)); + return; + } + this.handleClose(); + callback && callback(); + }); + }); + } + + handleClose() { + app.removeElement(this); + } +} + +EditDeptWindow.propTypes = { + id: PropTypes.string, + name: PropTypes.string, + callback: PropTypes.func, +}; + +EditDeptWindow.defaultProps = { + id: '', + name: '', + callback: null, +}; + +export default EditDeptWindow; \ No newline at end of file