1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-19 00:15:43 +01:00

Link for deleting strategies (#60)

This commit is contained in:
ivaosthu 2014-12-09 09:22:54 +01:00 committed by Ivar Conradi Østhus
parent 5515f05350
commit 4fdf41850a
4 changed files with 37 additions and 8 deletions

View File

@ -14,9 +14,16 @@ var StrategiesComponent = React.createClass({
}, },
componentDidMount: function () { componentDidMount: function () {
strategyStore.getStrategies().then(function(res) { this.fetchStrategies();
this.setState({strategies: res.strategies}); },
}.bind(this), this.initError);
fetchStrategies: function(res) {
strategyStore.getStrategies()
.then(function(res) {
this.setState({strategies: res.strategies})
}.bind(this))
.catch(this.initError);
}, },
initError: function() { initError: function() {
@ -57,6 +64,12 @@ var StrategiesComponent = React.createClass({
.catch(this.onError); .catch(this.onError);
}, },
onRemove: function(strategy) {
strategyStore.removeStrategy(strategy)
.then(this.fetchStrategies)
.catch(this.onError);
},
render: function() { render: function() {
return ( return (
<div> <div>
@ -66,7 +79,7 @@ var StrategiesComponent = React.createClass({
<hr /> <hr />
<StrategyList strategies={this.state.strategies} /> <StrategyList strategies={this.state.strategies} onRemove={this.onRemove} />
</div> </div>
); );
}, },

View File

@ -5,12 +5,20 @@ var Strategy = React.createClass({
strategy: React.PropTypes.object.isRequired strategy: React.PropTypes.object.isRequired
}, },
onRemove: function(event) {
event.preventDefault();
if (confirm("Are you sure you want to delete strategy '"+this.props.strategy.name+"'?")) {
this.props.onRemove(this.props.strategy);
}
},
render: function() { render: function() {
return ( return (
<div className="line mal"> <div className="line mal">
<div className="unit"> <div className="unit">
<strong>{this.props.strategy.name}</strong><br /> <strong>{this.props.strategy.name} </strong>
<em>{this.props.strategy.description}</em> <a href="" title="Delete strategy" onClick={this.onRemove}>(remove)</a><br />
<em>{this.props.strategy.description}</em><br />
</div> </div>
</div> </div>
); );

View File

@ -8,8 +8,8 @@ var StrategyList = React.createClass({
render: function() { render: function() {
var strategyNodes = this.props.strategies.map(function(strategy) { var strategyNodes = this.props.strategies.map(function(strategy) {
return <Strategy strategy={strategy} key={strategy.name} />; return <Strategy strategy={strategy} key={strategy.name} onRemove={this.props.onRemove} />;
}); }.bind(this));
return ( return (
<div>{strategyNodes}</div> <div>{strategyNodes}</div>
); );

View File

@ -14,6 +14,14 @@ var StrategyStore = {
}); });
}, },
removeStrategy: function (strategy) {
return reqwest({
url: 'strategies/'+strategy.name,
method: 'delete',
type: TYPE
});
},
getStrategies: function () { getStrategies: function () {
return reqwest({ return reqwest({
url: 'strategies', url: 'strategies',