2016-02-12 20:36:59 -05:00
|
|
|
var React = require('react');
|
2016-09-27 11:30:39 -04:00
|
|
|
var ReactDOM = require('react-dom');
|
2016-02-12 20:36:59 -05:00
|
|
|
|
2016-09-27 11:30:39 -04:00
|
|
|
var ReactBootstrap = require('react-bootstrap');
|
2017-01-08 21:04:01 -05:00
|
|
|
var Modal = ReactBootstrap.Modal;
|
2016-09-27 11:30:39 -04:00
|
|
|
var Form = ReactBootstrap.Form;
|
|
|
|
var FormGroup = ReactBootstrap.FormGroup;
|
|
|
|
var FormControl = ReactBootstrap.FormControl;
|
|
|
|
var ControlLabel = ReactBootstrap.ControlLabel;
|
|
|
|
var Col = ReactBootstrap.Col;
|
|
|
|
var Button = ReactBootstrap.Button;
|
|
|
|
var ButtonGroup = ReactBootstrap.ButtonGroup;
|
2016-02-12 20:36:59 -05:00
|
|
|
|
2017-06-21 21:25:38 -04:00
|
|
|
var Combobox = require('react-widgets').Combobox;
|
|
|
|
|
2016-10-05 13:45:09 -04:00
|
|
|
var models = require('../models');
|
2016-02-13 16:31:12 -05:00
|
|
|
var User = models.User;
|
|
|
|
|
2017-06-07 19:12:53 -04:00
|
|
|
class NewUserModal extends React.Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
|
|
|
error: "",
|
2016-02-12 20:36:59 -05:00
|
|
|
name: "",
|
|
|
|
username: "",
|
|
|
|
email: "",
|
2017-06-21 21:25:38 -04:00
|
|
|
defaultCurrency: '840', // ISO4217 code for USD
|
2016-02-12 20:36:59 -05:00
|
|
|
password: "",
|
|
|
|
confirm_password: "",
|
|
|
|
passwordChanged: false,
|
2017-06-07 19:12:53 -04:00
|
|
|
initial_password: ""
|
|
|
|
};
|
2017-06-10 13:37:13 -04:00
|
|
|
this.onCancel = this.handleCancel.bind(this);
|
|
|
|
this.onChange = this.handleChange.bind(this);
|
2017-06-21 21:25:38 -04:00
|
|
|
this.onSelectCurrency = this.handleSelectCurrency.bind(this);
|
2017-06-10 13:37:13 -04:00
|
|
|
this.onSubmit = this.handleSubmit.bind(this);
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
passwordValidationState() {
|
2016-02-12 20:36:59 -05:00
|
|
|
if (this.state.passwordChanged) {
|
|
|
|
if (this.state.password.length >= 10)
|
|
|
|
return "success";
|
|
|
|
else if (this.state.password.length >= 6)
|
|
|
|
return "warning";
|
|
|
|
else
|
|
|
|
return "error";
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
confirmPasswordValidationState() {
|
2016-02-12 20:36:59 -05:00
|
|
|
if (this.state.confirm_password.length > 0) {
|
|
|
|
if (this.state.confirm_password == this.state.password)
|
|
|
|
return "success";
|
|
|
|
else
|
|
|
|
return "error";
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleCancel() {
|
2016-02-12 20:36:59 -05:00
|
|
|
if (this.props.onCancel != null)
|
|
|
|
this.props.onCancel();
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
handleChange() {
|
2016-09-27 11:30:39 -04:00
|
|
|
if (ReactDOM.findDOMNode(this.refs.password).value != this.state.initial_password)
|
2016-02-12 20:36:59 -05:00
|
|
|
this.setState({passwordChanged: true});
|
|
|
|
this.setState({
|
2016-09-27 11:30:39 -04:00
|
|
|
name: ReactDOM.findDOMNode(this.refs.name).value,
|
|
|
|
username: ReactDOM.findDOMNode(this.refs.username).value,
|
|
|
|
email: ReactDOM.findDOMNode(this.refs.email).value,
|
|
|
|
password: ReactDOM.findDOMNode(this.refs.password).value,
|
|
|
|
confirm_password: ReactDOM.findDOMNode(this.refs.confirm_password).value
|
2016-02-12 20:36:59 -05:00
|
|
|
});
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
2017-06-21 21:25:38 -04:00
|
|
|
handleSelectCurrency(security) {
|
|
|
|
if (security.hasOwnProperty('SecurityId')) {
|
|
|
|
this.setState({
|
|
|
|
defaultCurrency: security.AlternateId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
handleSubmit(e) {
|
2016-02-12 20:36:59 -05:00
|
|
|
var u = new User();
|
|
|
|
var error = "";
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
u.Name = this.state.name;
|
|
|
|
u.Username = this.state.username;
|
|
|
|
u.Email = this.state.email;
|
2017-06-21 21:25:38 -04:00
|
|
|
u.DefaultCurrency = Number.parseInt(this.state.defaultCurrency);
|
2016-02-12 20:36:59 -05:00
|
|
|
u.Password = this.state.password;
|
|
|
|
if (u.Password != this.state.confirm_password) {
|
2017-01-10 08:46:00 -05:00
|
|
|
this.setState({error: "Error: passwords do not match"});
|
2016-02-12 20:36:59 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-08 21:04:01 -05:00
|
|
|
this.props.createNewUser(u);
|
|
|
|
if (this.props.onSubmit != null)
|
|
|
|
this.props.onSubmit(u);
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
render() {
|
2016-02-12 20:36:59 -05:00
|
|
|
return (
|
2017-06-10 13:37:13 -04:00
|
|
|
<Modal show={this.props.show} onHide={this.onCancel} bsSize="large">
|
2017-01-08 21:04:01 -05:00
|
|
|
<Modal.Header closeButton>
|
|
|
|
<Modal.Title>Create New user</Modal.Title>
|
|
|
|
</Modal.Header>
|
|
|
|
<Modal.Body>
|
2017-01-10 08:46:00 -05:00
|
|
|
<span style={{color: "red"}}>{this.state.error}</span>
|
2017-06-10 13:37:13 -04:00
|
|
|
<Form horizontal onSubmit={this.onSubmit}>
|
2016-09-27 11:30:39 -04:00
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>Name</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<FormControl type="text"
|
2016-02-12 20:36:59 -05:00
|
|
|
value={this.state.name}
|
2017-06-10 13:37:13 -04:00
|
|
|
onChange={this.onChange}
|
2016-09-27 11:30:39 -04:00
|
|
|
ref="name"/>
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>Username</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<FormControl type="text"
|
2016-02-12 20:36:59 -05:00
|
|
|
value={this.state.username}
|
2017-06-10 13:37:13 -04:00
|
|
|
onChange={this.onChange}
|
2016-09-27 11:30:39 -04:00
|
|
|
ref="username"/>
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>Email</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<FormControl type="email"
|
2016-02-12 20:36:59 -05:00
|
|
|
value={this.state.email}
|
2017-06-10 13:37:13 -04:00
|
|
|
onChange={this.onChange}
|
2016-09-27 11:30:39 -04:00
|
|
|
ref="email"/>
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
2017-06-21 21:25:38 -04:00
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>Default Currency</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<Combobox
|
|
|
|
data={this.props.currencies}
|
|
|
|
valueField='AlternateId'
|
|
|
|
textField={item => typeof item === 'string' ? item : item.Name + " - " + item.Description}
|
|
|
|
defaultValue={this.state.defaultCurrency}
|
|
|
|
onChange={this.onSelectCurrency}
|
|
|
|
suggest
|
|
|
|
filter='contains'
|
|
|
|
ref="security" />
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
2016-09-27 11:30:39 -04:00
|
|
|
<FormGroup validationState={this.passwordValidationState()}>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>Password</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<FormControl type="password"
|
2016-02-12 20:36:59 -05:00
|
|
|
value={this.state.password}
|
2017-06-10 13:37:13 -04:00
|
|
|
onChange={this.onChange}
|
2016-09-27 11:30:39 -04:00
|
|
|
ref="password"/>
|
|
|
|
<FormControl.Feedback/>
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup validationState={this.confirmPasswordValidationState()}>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>Confirm Password</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<FormControl type="password"
|
2016-02-12 20:36:59 -05:00
|
|
|
value={this.state.confirm_password}
|
2017-06-10 13:37:13 -04:00
|
|
|
onChange={this.onChange}
|
2016-09-27 11:30:39 -04:00
|
|
|
ref="confirm_password"/>
|
|
|
|
<FormControl.Feedback/>
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
2017-01-08 21:04:01 -05:00
|
|
|
</Form>
|
|
|
|
</Modal.Body>
|
|
|
|
<Modal.Footer>
|
|
|
|
<ButtonGroup>
|
2017-06-10 13:37:13 -04:00
|
|
|
<Button onClick={this.onCancel}
|
2016-02-12 20:36:59 -05:00
|
|
|
bsStyle="warning">Cancel</Button>
|
2017-06-10 13:37:13 -04:00
|
|
|
<Button onClick={this.onSubmit}
|
2016-02-12 20:36:59 -05:00
|
|
|
bsStyle="success">Create New User</Button>
|
|
|
|
</ButtonGroup>
|
2017-01-08 21:04:01 -05:00
|
|
|
</Modal.Footer>
|
|
|
|
</Modal>
|
2016-02-12 20:36:59 -05:00
|
|
|
);
|
|
|
|
}
|
2017-06-07 19:12:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = NewUserModal;
|