1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/public/js/components/strategy/StrategiesComponent.jsx

62 lines
1.7 KiB
React
Raw Normal View History

2015-03-17 22:01:46 +01:00
var React = require('react');
var StrategyList = require('./StrategyList');
var StrategyForm = require('./StrategyForm');
var StrategyActions = require('../../stores/StrategyActions');
2014-11-03 14:00:45 +01:00
var StrategiesComponent = React.createClass({
getInitialState: function() {
return {
createView: false
};
},
onNewStrategy: function() {
this.setState({createView: true});
},
onCancelNewStrategy: function() {
this.setState({createView: false});
},
onSave: function(strategy) {
2015-03-17 22:01:46 +01:00
StrategyActions.create.triggerPromise(strategy)
.then(this.onCancelNewStrategy);
},
2014-12-09 09:22:54 +01:00
onRemove: function(strategy) {
2015-03-17 22:01:46 +01:00
StrategyActions.remove.triggerPromise(strategy);
2014-12-09 09:22:54 +01:00
},
render: function() {
return (
<div>
2015-03-28 09:51:31 +01:00
<h1>Activation Strategies</h1>
2015-03-17 22:01:46 +01:00
{this.state.createView ?
this.renderCreateView() : this.renderCreateButton()}
<hr />
2015-03-17 20:29:03 +01:00
<StrategyList
strategies={this.props.strategies}
2015-03-17 20:29:03 +01:00
onRemove={this.onRemove} />
</div>
2015-03-17 20:29:03 +01:00
);
},
renderCreateView: function() {
2015-03-17 20:29:03 +01:00
return (
<StrategyForm
onCancelNewStrategy={this.onCancelNewStrategy}
onSave={this.onSave}
/>);
2015-03-17 22:01:46 +01:00
},
renderCreateButton: function() {
return (
<button className="mal" onClick={this.onNewStrategy}>
Create strategy
</button>
);
}
});
module.exports = StrategiesComponent;