/*** @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_pin: '', 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, }); }.bind(this) ); event.preventDefault(); }, savePin: function(event) { AJAX.post( Link.get('updatepin'), {pin: this.state.new_pin}, function(response) { this.setState({ new_pin: '', editing_pin: false, }); }.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, }); }.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.new_pin} onChange={function(event) { var intRegex = /^\d*$/; if (event.target.value.length <= 4 && intRegex.test(event.target.value)) { this.setState({new_pin: event.target.value}); } }.bind(this)} name="pin" />
}
); }, render: function() { return (
{this.renderUsername()} {this.renderPassword()} {this.renderEmail()} {this.renderPIN()}
); }, }); ReactDOM.render( React.createElement(account_management, null), document.getElementById('content') );