/*** @jsx React.DOM */ var account_management = createReactClass({ getInitialState: function(props) { return { email: window.email, new_email: window.email, email_password: '', editing_email: false, username: window.username, editing_pin: false, new_pin1: '', new_pin2: '', editing_password: false, old_password: '', new_password1: '', new_password2: '', }; }, componentDidUpdate: function() { if (this.focus_element && this.focus_element != this.already_focused) { this.focus_element.focus(); this.already_focused = this.focus_element; } }, saveEmail: function(event) { AJAX.post( Link.get('updateemail'), { email: this.state.new_email, password: this.state.email_password, }, function(response) { this.setState({ email: response.email, new_email: response.email, email_password: '', editing_email: false, }); Messages.success("Your email address has been updated!") }.bind(this) ); event.preventDefault(); }, savePin: function(event) { AJAX.post( Link.get('updatepin'), { old: this.state.old_password, pin1: this.state.new_pin1, pin2: this.state.new_pin2, }, function(response) { this.setState({ old_password: '', new_pin1: '', new_pin2: '', editing_pin: false, }); Messages.success("Your PIN has been updated!") }.bind(this) ); event.preventDefault(); }, savePassword: function(event) { AJAX.post( Link.get('updatepassword'), { old: this.state.old_password, new1: this.state.new_password1, new2: this.state.new_password2, }, function(response) { this.setState({ old_password: '', new_password1: '', new_password2: '', editing_password: false, }); Messages.success("Your password has been updated!") }.bind(this) ); event.preventDefault(); }, renderUsername: function() { return ( { this.state.username } ); }, renderPassword: function() { return ( { !this.state.editing_password ? <> •••••• :
(this.focus_element = c)} value={this.state.old_password} onChange={function(event) { this.setState({old_password: event.target.value}); }.bind(this)} name="old" />
}
); }, renderEmail: function() { return ( { !this.state.editing_email ? <> { this.state.email } :
(this.focus_element = c)} value={this.state.email_password} onChange={function(event) { this.setState({email_password: event.target.value}); }.bind(this)} name="old" />
}
); }, renderPIN: function() { return ( { !this.state.editing_pin ? <> •••• :
(this.focus_element = c)} value={this.state.old_password} onChange={function(event) { this.setState({old_password: event.target.value}); }.bind(this)} name="old" />
(this.focus_element = c)} value={this.state.new_pin1} onChange={function(event) { var intRegex = /^\d*$/; if (event.target.value.length <= 4 && intRegex.test(event.target.value)) { this.setState({new_pin1: event.target.value}); } }.bind(this)} name="pin1" />
(this.focus_element = c)} value={this.state.new_pin2} onChange={function(event) { var intRegex = /^\d*$/; if (event.target.value.length <= 4 && intRegex.test(event.target.value)) { this.setState({new_pin2: event.target.value}); } }.bind(this)} name="pin2" />
}
); }, render: function() { return (
{this.renderUsername()} {this.renderPassword()} {this.renderEmail()} {this.renderPIN()}
); }, }); ReactDOM.render( React.createElement(account_management, null), document.getElementById('content') );