/*** @jsx React.DOM */ var valid_versions = Object.keys(window.rivals); var pagenav = new History(valid_versions); var rivals_view = React.createClass({ getInitialState: function(props) { var profiles = Object.keys(window.rivals); var version = pagenav.getInitialState(profiles[profiles.length - 1]); return { rivals: window.rivals, players: window.players, profiles: profiles, version: version, term_id: "", term_name: "", results: {}, searching_id: false, searching_name: false, offset: 0, limit: 5, }; }, componentDidMount: function() { pagenav.onChange(function(version) { this.setState({version: version, offset: 0}); }.bind(this)); this.refreshRivals(); }, refreshRivals: function() { AJAX.get( Link.get('refresh'), function(response) { this.setState({ rivals: response.rivals, players: response.players, }); setTimeout(this.refreshRivals, 5000); }.bind(this) ); }, searchForPlayersID: function(event) { this.setState({searching_id: true}); AJAX.post( Link.get('search'), { version: this.state.version, term: this.state.term_id.substring(0, 9), }, function(response) { this.setState({ results: response.results, searching_id: false, }); }.bind(this) ); event.preventDefault(); }, searchForPlayersName: function(event) { this.setState({searching_name: true}); AJAX.post( Link.get('search'), { version: this.state.version, term: this.state.term_name, }, function(response) { this.setState({ results: response.results, searching_name: false, }); }.bind(this) ); event.preventDefault(); }, addRival: function(event, userid) { AJAX.post( Link.get('addrival'), { version: this.state.version, userid: userid, }, function(response) { this.setState({ rivals: response.rivals, players: response.players, }); }.bind(this) ); event.preventDefault(); }, removeRival: function(event, userid) { AJAX.post( Link.get('removerival'), { version: this.state.version, userid: userid, }, function(response) { this.setState({ rivals: response.rivals, players: response.players, }); }.bind(this) ); event.preventDefault(); }, addRivals: function(userid) { if (userid == window.userid) { return null; } var avail = true; var count = 0; var current_rivals = this.state.rivals[this.state.version]; for (var i = 0; i < current_rivals.length; i++) { count++; if (current_rivals[i].userid == userid) { avail = false; } } if (count >= 4) { avail = false; } return ( {avail ? : null } ); }, render: function() { if (this.state.rivals[this.state.version]) { var rivals = this.state.rivals[this.state.version]; var resultlength = 0; Object.keys(this.state.results).map(function(userid, index) { var player = this.state.results[userid][this.state.version]; if (player) { resultlength++; } }.bind(this)); return (

Rivals

{this.state.profiles.map(function(version) { return (

= '0'.charCodeAt(0) && c <= '9'.charCodeAt(0)) { c = 0xFF10 + (c - '0'.charCodeAt(0)); } else if(c >= 'A'.charCodeAt(0) && c <= 'Z'.charCodeAt(0)) { c = 0xFF21 + (c - 'A'.charCodeAt(0)); } else if(c >= 'a'.charCodeAt(0) && c <= 'z'.charCodeAt(0)) { c = 0xFF41 + (c - 'a'.charCodeAt(0)); } else if(c == '@'.charCodeAt(0)) { c = 0xFF20; } else if(c == ','.charCodeAt(0)) { c = 0xFF0C; } else if(c == '.'.charCodeAt(0)) { c = 0xFF0E; } else if(c == '_'.charCodeAt(0)) { c = 0xFF3F; } value = value + String.fromCharCode(c); } var nameRegex = new RegExp( "^[" + "\uFF20-\uFF3A" + // widetext A-Z and @ "\uFF41-\uFF5A" + // widetext a-z "\uFF10-\uFF19" + // widetext 0-9 "\uFF0C\uFF0E\uFF3F" + // widetext ,._ "\u3041-\u308D\u308F\u3092\u3093" + // hiragana "\u30A1-\u30ED\u30EF\u30F2\u30F3\u30FC" + // katakana "]*$" ); if (value.length <= 6 && nameRegex.test(value)) { this.setState({term_name: value}); } }.bind(this)} name="search" /> { this.state.searching_name ? : null }

{ this.state.searching_id ? : null }
{resultlength > 0 ? { Object.keys(this.state.results).map(function(userid, index) { if (index < this.state.offset || index >= this.state.offset + this.state.limit) { return null; } var player = this.state.results[userid][this.state.version]; if (!player) { return null; } return ( ); }.bind(this)) }
Name Pop'n Music ID
{ player.extid } {this.addRivals(userid)}
{ this.state.offset > 0 ? : null } { (this.state.offset + this.state.limit) < resultlength ? = resultlength) { return; } this.setState({offset: page}); }.bind(this)}/> : null }
:
No players match the specified search.
}

Rivals

{this.state.rivals[this.state.version].map(function(rival, index) { var player = this.state.players[rival.userid][this.state.version]; return ( ); }.bind(this))}
Name Pop'n Music ID
{ player.extid }
); } else { return (
You have no profile for {window.versions[this.state.version]}!
{this.state.profiles.map(function(version) { return (
); } }, }); ReactDOM.render( React.createElement(rivals_view, null), document.getElementById('content') );