2016-02-12 20:36:59 -05:00
|
|
|
var React = require('react');
|
2015-07-03 09:33:45 -04:00
|
|
|
|
2016-02-12 20:36:59 -05:00
|
|
|
var ReactBootstrap = require('react-bootstrap');
|
|
|
|
var Alert = ReactBootstrap.Alert;
|
2015-07-03 09:33:45 -04:00
|
|
|
var Input = ReactBootstrap.Input;
|
|
|
|
var Button = ReactBootstrap.Button;
|
|
|
|
var DropdownButton = ReactBootstrap.DropdownButton;
|
|
|
|
var MenuItem = ReactBootstrap.MenuItem;
|
|
|
|
var Row = ReactBootstrap.Row;
|
|
|
|
var Col = ReactBootstrap.Col;
|
|
|
|
|
2016-02-13 16:31:12 -05:00
|
|
|
var User = require('./models.js').User;
|
|
|
|
|
2015-07-04 09:40:12 -04:00
|
|
|
const LoginBar = React.createClass({
|
2015-07-03 09:33:45 -04:00
|
|
|
getInitialState: function() {
|
|
|
|
return {username: '', password: ''};
|
|
|
|
},
|
|
|
|
onUsernameChange: function(e) {
|
|
|
|
this.setState({username: e.target.value});
|
|
|
|
},
|
|
|
|
onPasswordChange: function(e) {
|
|
|
|
this.setState({password: e.target.value});
|
|
|
|
},
|
|
|
|
handleSubmit: function(e) {
|
|
|
|
var user = new User();
|
|
|
|
e.preventDefault();
|
|
|
|
user.Username = this.refs.username.getValue();
|
|
|
|
user.Password = this.refs.password.getValue();
|
|
|
|
this.props.onLoginSubmit(user);
|
|
|
|
},
|
|
|
|
handleNewUserSubmit: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.onCreateNewUser();
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<form onSubmit={this.handleSubmit}>
|
|
|
|
<Input wrapperClassName="wrapper">
|
|
|
|
<Row>
|
|
|
|
<Col xs={4}></Col>
|
|
|
|
<Col xs={2}>
|
|
|
|
<Button bsStyle="link"
|
|
|
|
onClick={this.handleNewUserSubmit}>Create New User</Button>
|
|
|
|
</Col>
|
|
|
|
<Col xs={2}>
|
|
|
|
<Input type="text"
|
|
|
|
placeholder="Username..."
|
|
|
|
ref="username"/>
|
|
|
|
</Col>
|
|
|
|
<Col xs={2}>
|
|
|
|
<Input type="password"
|
|
|
|
placeholder="Password..."
|
|
|
|
ref="password" block/>
|
|
|
|
</Col>
|
|
|
|
<Col xs={2}>
|
|
|
|
<Button type="submit" bsStyle="primary" block>
|
|
|
|
Login</Button>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Input>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-04 09:40:12 -04:00
|
|
|
const LogoutBar = React.createClass({
|
2016-02-12 20:36:59 -05:00
|
|
|
handleOnSelect: function(e, key) {
|
2015-07-03 09:33:45 -04:00
|
|
|
if (key == 1) {
|
|
|
|
if (this.props.onAccountSettings != null)
|
|
|
|
this.props.onAccountSettings();
|
|
|
|
} else if (key == 2) {
|
|
|
|
this.props.onLogoutSubmit();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var signedInString = "Signed in as "+this.props.user.Name;
|
|
|
|
return (
|
|
|
|
<Input wrapperClassName="wrapper">
|
|
|
|
<Row>
|
|
|
|
<Col xs={2}><label className="control-label pull-left">Money<i>Go</i></label></Col>
|
|
|
|
<Col xs={6}></Col>
|
|
|
|
<Col xs={4}>
|
|
|
|
<div className="pull-right">
|
2016-02-12 20:36:59 -05:00
|
|
|
<DropdownButton id="logout-settings-dropdown" title={signedInString} onSelect={this.handleOnSelect} bsStyle="info">
|
2015-07-03 09:33:45 -04:00
|
|
|
<MenuItem eventKey="1">Account Settings</MenuItem>
|
|
|
|
<MenuItem eventKey="2">Logout</MenuItem>
|
|
|
|
</DropdownButton>
|
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Input>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-12 20:36:59 -05:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: "TopBar",
|
2015-07-03 09:33:45 -04:00
|
|
|
render: function() {
|
|
|
|
var barContents;
|
|
|
|
var errorAlert;
|
|
|
|
if (!this.props.user.isUser())
|
|
|
|
barContents = <LoginBar onLoginSubmit={this.props.onLoginSubmit} onCreateNewUser={this.props.onCreateNewUser} />;
|
|
|
|
else
|
|
|
|
barContents = <LogoutBar user={this.props.user} onLogoutSubmit={this.props.onLogoutSubmit} onAccountSettings={this.props.onAccountSettings}/>;
|
|
|
|
if (this.props.error.isError())
|
|
|
|
errorAlert =
|
|
|
|
<Alert bsStyle="danger" onDismiss={this.props.onErrorClear}>
|
|
|
|
<h4>Error!</h4>
|
|
|
|
<p>Error {this.props.error.ErrorId}: {this.props.error.ErrorString}</p>
|
|
|
|
<Button onClick={this.props.onErrorClear}>Clear</Button>
|
|
|
|
</Alert>;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{barContents}
|
|
|
|
{errorAlert}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|