2014-11-01 14:52:37 +01:00
|
|
|
var React = require('react'),
|
2014-11-01 15:53:14 +01:00
|
|
|
StrategyList = require('./StrategyList'),
|
|
|
|
CreateStrategy = require('./CreateStrategy'),
|
|
|
|
strategyStore = require('../../stores/StrategyStore'),
|
|
|
|
ErrorMessages = require('../ErrorMessages');
|
2014-11-01 14:52:37 +01:00
|
|
|
|
|
|
|
var StrategyComponent = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
createView: false,
|
2014-11-01 15:53:14 +01:00
|
|
|
strategies: [],
|
|
|
|
errors: []
|
2014-11-01 14:52:37 +01:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function () {
|
|
|
|
strategyStore.getStrategies().then(function(res) {
|
|
|
|
this.setState({strategies: res.strategies});
|
2014-11-01 15:53:14 +01:00
|
|
|
}.bind(this), this.initError);
|
|
|
|
},
|
|
|
|
|
|
|
|
initError: function() {
|
|
|
|
this.handleError("Could not load inital strategies from server");
|
|
|
|
},
|
|
|
|
|
|
|
|
clearErrors: function() {
|
|
|
|
this.setState({errors: []});
|
|
|
|
},
|
|
|
|
|
|
|
|
handleError: function(error) {
|
|
|
|
var errors = this.state.errors.concat([error]);
|
|
|
|
this.setState({errors: errors});
|
|
|
|
},
|
|
|
|
|
|
|
|
handleNewStrategy: function() {
|
|
|
|
this.setState({createView: true});
|
|
|
|
},
|
|
|
|
|
|
|
|
handleCancelNewStrategy: function() {
|
|
|
|
this.setState({createView: false});
|
2014-11-01 14:52:37 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<div>
|
2014-11-01 15:53:14 +01:00
|
|
|
<div className="line">
|
|
|
|
<div className="unit r-size1of4">
|
|
|
|
<h2>Strategies</h2>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="unit r-size3of4 rightify prl ptm">
|
|
|
|
<button className="" onClick={this.handleNewStrategy}>Create Strategy</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<ErrorMessages errors={this.state.errors} onClearErrors={this.clearErrors} />
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
{this.state.createView ? this.renderCreateView() : null}
|
|
|
|
|
|
|
|
<StrategyList strategies={this.state.strategies} />
|
2014-11-01 14:52:37 +01:00
|
|
|
</div>
|
|
|
|
);
|
2014-11-01 15:53:14 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
renderCreateView: function() {
|
|
|
|
return (<CreateStrategy handleCancelNewStrategy={this.handleCancelNewStrategy} />)
|
2014-11-01 14:52:37 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = StrategyComponent;
|