var React = require('react'); var TextInput = require('../form/TextInput'); var strategyStore = require('../../stores/StrategyStore'); var FeatureForm = React.createClass({ getInitialState: function() { return {strategyOptions: []}; }, componentWillMount: function() { strategyStore.getStrategies().then(this.handleStrategyResponse); }, handleStrategyResponse: function(response) { var strategyNames = response.strategies.map(function(s) { return s.name; }); this.setState({strategyOptions: strategyNames}); }, render: function() { var feature = this.props.feature || { name: '', strategy: 'default', enabled: false }; var title = this.props.feature ? "" : "Create new toggle"; return (
{title}
); }, renderStrategyOptions: function() { var currentStrategy = this.props.feature ? this.props.feature.strategy : "default"; return this.state.strategyOptions.map(function(name) { return ( ); }); }, saveFeature: function(e) { e.preventDefault(); var feature = { name: this.refs.name.getValue(), description: this.refs.description.getValue(), strategy: this.refs.strategy.getDOMNode().value, enabled: this.refs.enabled.getDOMNode().checked }; this.props.onSubmit(feature); }, cancelFeature: function(e) { e.preventDefault(); this.props.onCancel(); } }); module.exports = FeatureForm;