/*** @jsx React.DOM */ var user_management = React.createClass({ getInitialState: function(props) { var credits = {}; Object.keys(window.arcades).map(function(arcadeid) { credits[arcadeid] = ''; }); return { editing_email: false, email: window.user.email, new_email: window.user.email, editing_username: false, username: window.user.username, new_username: window.user.username, editing_pin: false, new_pin: '', editing_password: false, new_password1: '', new_password2: '', cards: window.cards, new_card: '', balances: window.balances, credits: credits, arcades: window.arcades, events: window.events, eventoffset: 0, eventlimit: 5, }; }, componentDidMount: function() { this.refreshUser(); }, componentDidUpdate: function() { if (this.focus_element && this.focus_element != this.already_focused) { this.focus_element.focus(); this.already_focused = this.focus_element; } }, refreshUser: function() { AJAX.get( Link.get('refresh'), function(response) { this.setState({ cards: response.cards, balances: response.balances, arcades: response.arcades, events: response.events, }); // Refresh every 15 seconds setTimeout(this.refreshUser, 5000); }.bind(this) ); }, deleteExistingCard: function(card) { $.confirm({ escapeKey: 'Cancel', animation: 'none', closeAnimation: 'none', title: 'Delete Card', content: 'Are you sure you want to delete this card from this account?', buttons: { Delete: { btnClass: 'delete', action: function() { AJAX.post( Link.get('removeusercard'), {card: card}, function(response) { this.setState({ cards: response.cards, }); }.bind(this) ); }.bind(this), }, Cancel: function() { }, } }); }, addNewCard: function(event) { AJAX.post( Link.get('addusercard'), {card: this.state.new_card}, function(response) { this.setState({ cards: response.cards, new_card: '', }); }.bind(this) ); event.preventDefault(); }, updateBalance: function(event) { var updates = {}; Object.keys(this.state.credits).map(function(arcadeid) { var intval = parseInt(this.state.credits[arcadeid]); if (!isNaN(intval)) { updates[arcadeid] = intval; } }.bind(this)); AJAX.post( Link.get('updatebalance'), {credits: updates}, function(response) { var credits = {}; Object.keys(response.arcades).map(function(arcadeid) { credits[arcadeid] = ''; }); this.setState({ arcades: response.arcades, balances: response.balances, credits: credits, events: response.events, }); }.bind(this) ); event.preventDefault(); }, saveUsername: function(event) { AJAX.post( Link.get('updateusername'), { username: this.state.new_username, }, function(response) { this.setState({ username: response.username, new_username: response.username, editing_username: false, }); }.bind(this) ); event.preventDefault(); }, saveEmail: function(event) { AJAX.post( Link.get('updateemail'), { email: this.state.new_email, }, function(response) { this.setState({ email: response.email, new_email: response.email, 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'), { new1: this.state.new_password1, new2: this.state.new_password2, }, function(response) { this.setState({ new_password1: '', new_password2: '', editing_password: false, }); }.bind(this) ); event.preventDefault(); }, renderUsername: function() { return ( { !this.state.editing_username ? { this.state.username ? { this.state.username } : unset } :
(this.focus_element = c)} value={this.state.new_username} onChange={function(event) { this.setState({new_username: event.target.value}); }.bind(this)} name="username" />
}
); }, renderPassword: function() { return ( { !this.state.editing_password ? •••••• :
(this.focus_element = c)} value={this.state.new_password1} onChange={function(event) { this.setState({new_password1: event.target.value}); }.bind(this)} name="new1" />
}
); }, renderEmail: function() { return ( { !this.state.editing_email ? { this.state.email ? { this.state.email } : unset } :
(this.focus_element = c)} value={this.state.new_email} onChange={function(event) { this.setState({new_email: event.target.value}); }.bind(this)} name="email" />
}
); }, 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 (

User Details

{this.renderUsername()} {this.renderPassword()} {this.renderEmail()} {this.renderPIN()}

Cards

{this.state.cards.map(function(card) { return (
); }.bind(this))}

Add Card

PASELI Balance

{ Object.keys(this.state.arcades).length == 0 ?
No arcades present!
:
); }.bind(this), } ]} rows={Object.keys(this.state.arcades)} emptymessage="There are no arcades on this network." />
}

PASELI Transaction History

{ this.state.events.length == 0 ?
No events to display!
:
{this.state.events.map(function(event, index) { if (index < this.state.eventoffset || index >= this.state.eventoffset + this.state.eventlimit) { return null; } if(event.type == 'paseli_transaction') { return ; } else { return null; } }.bind(this))}
Timestamp Event Details
{ this.state.eventoffset > 0 ? : null } { (this.state.eventoffset + this.state.eventlimit) < this.state.events.length ? = this.state.events.length) { return } this.setState({eventoffset: page}); }.bind(this)}/> : null }
}
); }, }); ReactDOM.render( React.createElement(user_management, null), document.getElementById('content') );