1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/public/js/components/feature/FeatureForm.jsx

90 lines
2.5 KiB
React
Raw Normal View History

2014-10-30 18:25:38 +01:00
var React = require('react');
2014-11-12 13:47:21 +01:00
var strategyStore = require('../../stores/StrategyStore');
2014-10-30 18:25:38 +01:00
2014-11-03 13:54:06 +01:00
var FeatureForm = React.createClass({
2014-11-12 13:47:21 +01:00
getInitialState: function() {
return {strategyOptions: []};
},
componentDidMount: function() {
strategyStore.getStrategies().then(this.handleStrategyResponse);
},
handleStrategyResponse: function(response) {
var strategyNames = response.strategies.map(function(strategy) {
return strategy.name;
});
this.setState({strategyOptions: strategyNames});
},
2014-10-30 18:25:38 +01:00
render: function() {
2014-11-12 13:47:21 +01:00
var strategyNodes = this.state.strategyOptions.map(function(name) {
return <option value={name}>{name}</option>;
});
2014-10-30 18:25:38 +01:00
return (
2014-10-31 10:30:23 +01:00
<form ref="form" className="bg-blue-xlt">
<div className="line mal ptl pbl">
<div className="unit prl r-size1of6">
2014-11-03 13:54:06 +01:00
<input ref="enabled" type="checkbox" defaultValue={false} />
2014-10-30 18:25:38 +01:00
</div>
2014-10-31 10:30:23 +01:00
<div className="unit r-size2of5">
2014-10-30 18:25:38 +01:00
<input
type="text"
2014-10-31 10:30:23 +01:00
className="mbs"
2014-10-30 18:25:38 +01:00
id="name"
ref="name"
placeholder="Enter name" />
2014-10-31 10:30:23 +01:00
<input className=""
type="text"
ref="description"
placeholder="Enter description" />
2014-10-30 18:25:38 +01:00
</div>
2014-10-31 10:30:23 +01:00
<div className="unit r-size2of6 plm">
2014-10-30 18:25:38 +01:00
<select id="strategy"
ref="strategy"
className=""
2014-11-03 13:54:06 +01:00
defaultValue="default">
2014-11-12 13:47:21 +01:00
{strategyNodes}
2014-10-30 18:25:38 +01:00
</select>
</div>
2014-11-10 14:56:38 +01:00
<div className="unit r-size1of6 rightify">
<button className="primary mrs" onClick={this.saveFeature}>
Save
</button>
2014-10-30 18:25:38 +01:00
2014-11-10 14:56:38 +01:00
<button className="" onClick={this.cancelFeature}>
Cancel
</button>
</div>
2014-10-31 10:30:23 +01:00
</div>
</form>
2014-10-30 18:25:38 +01:00
);
},
saveFeature: function(e) {
e.preventDefault();
2014-11-03 13:54:06 +01:00
var feature = {
name: this.refs.name.getDOMNode().value,
description: this.refs.description.getDOMNode().value,
strategy: this.refs.strategy.getDOMNode().value,
enabled: this.refs.enabled.getDOMNode().checked
}
2014-10-30 18:25:38 +01:00
2014-11-03 13:54:06 +01:00
this.props.onSubmit(feature);
2014-10-30 18:25:38 +01:00
},
cancelFeature: function(e) {
e.preventDefault();
2014-11-03 13:54:06 +01:00
this.props.onCancel();
2014-10-30 18:25:38 +01:00
}
});
2014-11-03 13:54:06 +01:00
module.exports = FeatureForm;