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-13 16:31:12 -05:00
|
|
|
var ReactBootstrap = require('react-bootstrap');
|
|
|
|
var Modal = ReactBootstrap.Modal;
|
|
|
|
var Button = ReactBootstrap.Button;
|
|
|
|
var ButtonGroup = ReactBootstrap.ButtonGroup;
|
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;
|
2016-02-13 16:31:12 -05:00
|
|
|
|
2016-10-05 13:45:09 -04:00
|
|
|
var User = require('../models').User;
|
2016-02-12 20:36:59 -05:00
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: "AccountSettingsModal",
|
|
|
|
_getInitialState: function(props) {
|
|
|
|
return {error: "",
|
|
|
|
name: props.user.Name,
|
|
|
|
username: props.user.Username,
|
|
|
|
email: props.user.Email,
|
2016-02-13 16:31:12 -05:00
|
|
|
password: models.BogusPassword,
|
|
|
|
confirm_password: models.BogusPassword,
|
2016-02-12 20:36:59 -05:00
|
|
|
passwordChanged: false,
|
2016-02-13 16:31:12 -05:00
|
|
|
initial_password: models.BogusPassword};
|
2016-02-12 20:36:59 -05:00
|
|
|
},
|
|
|
|
getInitialState: function() {
|
|
|
|
return this._getInitialState(this.props);
|
|
|
|
},
|
|
|
|
componentWillReceiveProps: function(nextProps) {
|
|
|
|
if (nextProps.show && !this.props.show) {
|
|
|
|
this.setState(this._getInitialState(nextProps));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
passwordValidationState: function() {
|
|
|
|
if (this.state.passwordChanged) {
|
|
|
|
if (this.state.password.length >= 10)
|
|
|
|
return "success";
|
|
|
|
else if (this.state.password.length >= 6)
|
|
|
|
return "warning";
|
|
|
|
else
|
|
|
|
return "error";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
confirmPasswordValidationState: function() {
|
|
|
|
if (this.state.confirm_password.length > 0) {
|
|
|
|
if (this.state.confirm_password == this.state.password)
|
|
|
|
return "success";
|
|
|
|
else
|
|
|
|
return "error";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleCancel: function() {
|
|
|
|
if (this.props.onCancel != null)
|
|
|
|
this.props.onCancel();
|
|
|
|
},
|
|
|
|
handleChange: function() {
|
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
|
|
|
});
|
|
|
|
},
|
|
|
|
handleSubmit: function(e) {
|
|
|
|
var u = new User();
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
u.UserId = this.props.user.UserId;
|
|
|
|
u.Name = this.state.name;
|
|
|
|
u.Username = this.state.username;
|
|
|
|
u.Email = this.state.email;
|
|
|
|
if (this.state.passwordChanged) {
|
|
|
|
u.Password = this.state.password;
|
|
|
|
if (u.Password != this.state.confirm_password) {
|
|
|
|
this.setState({error: "Error: password do not match"});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2016-02-13 16:31:12 -05:00
|
|
|
u.Password = models.BogusPassword;
|
2016-02-12 20:36:59 -05:00
|
|
|
}
|
|
|
|
|
2016-10-05 13:36:47 -04:00
|
|
|
this.props.onUpdateUser(u);
|
|
|
|
this.props.onSubmit();
|
2016-02-12 20:36:59 -05:00
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<Modal show={this.props.show} onHide={this.handleCancel} bsSize="large">
|
|
|
|
<Modal.Header closeButton>
|
|
|
|
<Modal.Title>Edit Account Settings</Modal.Title>
|
|
|
|
</Modal.Header>
|
|
|
|
<Modal.Body>
|
|
|
|
<span color="red">{this.state.error}</span>
|
2016-09-27 11:30:39 -04:00
|
|
|
<Form horizontal onSubmit={this.handleSubmit}>
|
|
|
|
<FormGroup>
|
|
|
|
<Col componentClass={ControlLabel} xs={2}>Name</Col>
|
|
|
|
<Col xs={10}>
|
|
|
|
<FormControl type="text"
|
|
|
|
value={this.state.name}
|
|
|
|
onChange={this.handleChange}
|
|
|
|
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}
|
|
|
|
onChange={this.handleChange}
|
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}
|
|
|
|
onChange={this.handleChange}
|
2016-09-27 11:30:39 -04:00
|
|
|
ref="email"/>
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
<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}
|
|
|
|
onChange={this.handleChange}
|
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}
|
|
|
|
onChange={this.handleChange}
|
2016-09-27 11:30:39 -04:00
|
|
|
ref="confirm_password"/>
|
|
|
|
<FormControl.Feedback/>
|
|
|
|
</Col>
|
|
|
|
</FormGroup>
|
|
|
|
</Form>
|
2016-02-12 20:36:59 -05:00
|
|
|
</Modal.Body>
|
|
|
|
<Modal.Footer>
|
|
|
|
<ButtonGroup>
|
|
|
|
<Button onClick={this.handleCancel} bsStyle="warning">Cancel</Button>
|
|
|
|
<Button onClick={this.handleSubmit} bsStyle="success">Save Settings</Button>
|
|
|
|
</ButtonGroup>
|
|
|
|
</Modal.Footer>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|