ensl_gathers/app/javascripts/components/admin.js

114 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-02-18 11:06:35 +00:00
const React = require("react");
import {MenubarMixin} from "javascripts/components/menubar";
const UserLogin = React.createClass({
propTypes: {
socket: React.PropTypes.object.isRequired
},
getInitialState() {
return {
userId: null
};
},
handleChange(e) {
const newId = e.target.value || null;
this.setState({ userId: newId });
},
authorizeId(id) {
this.props.socket.emit("users:authorize", {
id: id
});
},
handleSubmit(e) {
e.preventDefault();
this.authorizeId(this.state.userId);
},
render() {
return (
<form>
<div className="input-group signin">
<input
id="btn-input"
type="text"
className="form-control"
vaue={this.state.userId}
onChange={this.handleChange}
placeholder="Change user (input ID)" />
<span className="input-group-btn">
<input
type="submit"
className="btn btn-primary"
onClick={this.handleSubmit}
value="Assume ID" />
</span>
</div>
</form>
);
}
});
2016-03-19 23:37:28 +00:00
const ResetGatherButton = exports.ResetGatherButton = React.createClass({
2016-02-18 11:06:35 +00:00
propTypes: {
2016-03-19 23:37:28 +00:00
socket: React.PropTypes.object.isRequired,
gather: React.PropTypes.string.isRequired
2016-02-18 11:06:35 +00:00
},
handleGatherReset() {
2016-03-19 23:37:28 +00:00
this.props.socket.emit("gather:reset", {
type: this.props.gather.type
});
},
render() {
return (
<button
className="btn btn-danger max-width"
onClick={this.handleGatherReset}>
Reset {this.props.gather.name}</button>
);
}
});
const AdminPanel = exports.AdminPanel = React.createClass({
mixins: [MenubarMixin],
propTypes: {
socket: React.PropTypes.object.isRequired,
gatherPool: React.PropTypes.object.isRequired
2016-02-18 11:06:35 +00:00
},
render() {
2016-03-19 23:37:28 +00:00
const gatherPool = this.props.gatherPool;
const resetButtons = [];
for (let attr in gatherPool) {
let gather = gatherPool[attr];
resetButtons.push(
<ResetGatherButton socket={this.props.socket}
gather={gather} key={gather.type} />
);
}
2016-02-18 11:06:35 +00:00
return (
<li className={this.componentClass()}>
<a href="#" onClick={this.toggleShow}>
<i className="fa fa-rebel"></i>
</a>
<ul className="dropdown-menu">
<li className="header">Admin</li>
<ul className="news-menu">
<h5>Swap Into a Different Account (Only works for admins)</h5>
<UserLogin socket={this.props.socket} />
<h5>Gather Options</h5>
<div>
2016-03-19 23:37:28 +00:00
{resetButtons}
2016-02-18 11:06:35 +00:00
</div>
</ul>
</ul>
</li>
);
}
});