ensl_gathers/lib/react/user.jsx

226 lines
5.4 KiB
React
Raw Normal View History

2015-07-28 15:54:29 +00:00
"use strict";
var UserLogin = React.createClass({
2015-08-11 00:25:25 +00:00
authorizeId(id) {
2015-07-28 15:54:29 +00:00
socket.emit("users:authorize", {
2015-07-31 11:21:25 +00:00
id: parseInt(id, 10)
2015-07-28 15:54:29 +00:00
});
2015-07-28 23:32:50 +00:00
setTimeout(function () {
socket.emit("gather:refresh");
2015-08-08 19:14:16 +00:00
}, 1000);
2015-07-28 15:54:29 +00:00
},
2015-08-11 00:25:25 +00:00
handleSubmit(e) {
2015-07-28 15:54:29 +00:00
e.preventDefault();
2015-08-11 00:31:03 +00:00
let id = React.findDOMNode(this.refs.authorize_id).value.trim();
2015-07-28 15:54:29 +00:00
if (!id) return;
React.findDOMNode(this.refs.authorize_id).value = '';
this.authorizeId(id);
},
2015-08-11 00:25:25 +00:00
render() {
2015-07-28 15:54:29 +00:00
return (
<form onSubmit={this.handleSubmit} >
<div className="input-group signin">
<input
id="btn-input"
type="text"
className="form-control"
ref="authorize_id"
2015-08-18 09:56:35 +00:00
placeholder="Change user" />
2015-07-28 15:54:29 +00:00
<span className="input-group-btn">
<input
type="submit"
className="btn btn-primary"
id="btn-chat"
2015-08-18 09:56:35 +00:00
value="Assume ID" />
2015-07-28 15:54:29 +00:00
</span>
</div>
</form>
);
}
})
var UserMenu = React.createClass({
2015-08-11 00:25:25 +00:00
getDefaultProps() {
2015-07-28 15:54:29 +00:00
return {
users: []
};
},
2015-08-11 00:25:25 +00:00
componentDidMount() {
2015-08-11 00:31:03 +00:00
let self = this;
2015-08-11 00:25:25 +00:00
socket.on('users:update', data => self.setProps({users: data.users}));
2015-07-28 15:54:29 +00:00
},
2015-08-11 00:25:25 +00:00
render() {
2015-08-11 00:31:03 +00:00
let users = this.props.users.map(user => {
2015-07-28 15:54:29 +00:00
return (
2015-09-14 22:27:45 +00:00
<li key={user.id}
className="list-group-item">
<a href="#">{user.username}</a>
</li>
2015-07-28 15:54:29 +00:00
);
});
return (
2015-09-14 22:27:45 +00:00
<div>
<div className="panel panel-default add-bottom">
<div className="panel-heading">
2015-09-14 22:34:50 +00:00
<i className="fa fa-users fa-fw"></i> Online
<span className="badge pull-right">{this.props.users.length}</span>
2015-09-14 22:27:45 +00:00
</div>
</div>
<ul className="list-group" id="users-list">
{users}
</ul>
</div>
2015-07-28 15:54:29 +00:00
);
}
});
2015-07-29 14:35:58 +00:00
var AdminPanel = React.createClass({
2015-08-11 00:25:25 +00:00
handleGatherReset() {
2015-07-29 14:35:58 +00:00
socket.emit("gather:reset");
},
2015-08-11 00:25:25 +00:00
render() {
2015-07-29 14:35:58 +00:00
return (
2015-08-18 11:02:27 +00:00
<div>
<h5>Swap Into a Different Account</h5>
<UserLogin />
<h5>Gather Options</h5>
<div>
<button
className="btn btn-danger max-width"
onClick={this.handleGatherReset}>
Reset Gather</button>
</div>
</div>
);
2015-07-29 14:35:58 +00:00
}
});
2015-08-28 20:28:50 +00:00
var ProfileModal = React.createClass({
componentDidMount() {
let self = this;
socket.on("users:update", data => self.setProps({user: data.currentUser}));
},
handleUserUpdate(e) {
e.preventDefault();
let abilities = {
skulk: React.findDOMNode(this.refs.skulk).checked,
lerk: React.findDOMNode(this.refs.lerk).checked,
2015-08-31 13:37:33 +00:00
gorge: React.findDOMNode(this.refs.gorge).checked,
2015-08-28 20:28:50 +00:00
fade: React.findDOMNode(this.refs.fade).checked,
onos: React.findDOMNode(this.refs.onos).checked,
commander: React.findDOMNode(this.refs.commander).checked
};
2015-08-29 23:46:16 +00:00
let skill = React.findDOMNode(this.refs.playerskill).value;
2015-08-28 20:28:50 +00:00
socket.emit("users:update:profile", {
id: this.props.user.id,
profile: {
abilities: abilities,
2015-08-29 23:46:16 +00:00
skill: skill
2015-08-28 20:28:50 +00:00
}
});
},
render() {
if (!this.props.user) return false;
let abilities = this.props.user.profile.abilities;
let abilitiesForm = [];
for (let lifeform in abilities) {
abilitiesForm.push(
<div key={lifeform} className="checkbox">
<label className="checkbox-inline">
<input type="checkbox"
ref={lifeform}
defaultChecked={abilities[lifeform]}/> {_.capitalize(lifeform)}
</label>
</div>
);
}
2015-08-29 23:46:16 +00:00
let division = this.props.user.profile.skill;
let skillLevels = ["Low Skill", "Medium Skill", "High Skill"].map(skill => {
2015-09-15 14:13:03 +00:00
if (skill === division) {
return <option selected="selected" key={skill}>{skill}</option>
2015-08-28 20:28:50 +00:00
} else {
return <option key={skill}>{skill}</option>
}
});
return (
<form>
<div className="form-group">
<label>Player Skill</label><br />
<select className="form-control" ref="playerskill">
{skillLevels}
</select>
2015-08-29 23:46:16 +00:00
<p><small>Try to give an accurate representation of your skill to raise the quality of your gathers</small></p>
2015-08-28 20:28:50 +00:00
</div>
<div className="form-group">
{abilitiesForm}
</div>
<p className="small">You will need to rejoin the gather to see your updated profile</p>
<div className="form-group">
<button
type="submit"
className="btn btn-primary"
data-dismiss="modal"
onClick={this.handleUserUpdate}>
Update &amp; Close</button>
</div>
</form>
);
}
});
2015-07-28 15:54:29 +00:00
var CurrentUser = React.createClass({
2015-08-11 00:25:25 +00:00
componentDidMount() {
2015-08-11 00:31:03 +00:00
let self = this;
2015-08-28 20:28:50 +00:00
React.render(<AdminPanel />, document.getElementById('admin-menu'));
React.render(<ProfileModal />, document.getElementById('profile-panel'));
2015-08-11 00:25:25 +00:00
socket.on("users:update", data => self.setProps({user: data.currentUser}));
2015-07-31 10:51:38 +00:00
socket.emit("users:refresh");
2015-07-28 15:54:29 +00:00
},
2015-08-11 00:25:25 +00:00
render() {
2015-07-28 15:54:29 +00:00
if (this.props.user) {
2015-08-18 11:02:27 +00:00
var adminOptions;
if (this.props.user.admin) {
adminOptions = (
<li>
2015-08-28 20:28:50 +00:00
<a href="#" data-toggle="modal" data-target="#adminmodal">
<i className="fa fa-magic fa-fw"></i> Administration
</a>
2015-08-18 11:02:27 +00:00
</li>
)
}
2015-07-28 15:54:29 +00:00
return (
2015-08-08 19:14:16 +00:00
<li className="dropdown">
<a className="dropdown-toggle" data-toggle="dropdown" href="#">
{this.props.user.username} &nbsp;<img src={this.props.user.avatar}
alt="User Avatar"
height="20"
width="20" /> <i className="fa fa-caret-down"></i>
</a>
<ul className="dropdown-menu dropdown-user">
<li>
2015-08-28 20:28:50 +00:00
<a data-toggle="modal"
data-target="#profilemodal"
href="#"><i className="fa fa-gear fa-fw"></i> Profile</a>
</li>
<li>
<a href="#"><i className="fa fa-flag fa-fw"></i> Notifications</a>
</li>
2015-08-18 11:02:27 +00:00
{adminOptions}
</ul>
</li>
2015-07-28 15:54:29 +00:00
);
} else {
return false;
}
}
});
2015-08-11 00:37:43 +00:00