/** @jsx React.DOM */ // FeatureList // Feature // - name // - status // - description // - button-edit // - button-delete // - toggle-status // FeatureForm // StrategyList // Strategy // StrategyForm var FeatureList = React.createClass({ getInitialState: function() { return { features: [] }; }, componentDidMount: function () { reqwest('/features').then(this.setFeatures); }, setFeatures: function (data) { this.setState({features: data.features}); }, updateFeature: function (feature) { var newFeatures = this.state.features; newFeatures.forEach(function(f){ if(f.name === feature.name) { f = feature; } }); reqwest({ url: 'features/' + feature.name, method: 'post', type: 'json', data: feature }).then(function() { this.setState({features: newFeatures}); }.bind(this), function() { alert("update failed"); }.bind(this)); }, render: function () { var featureNodes = this.state.features.map(function (feature) { return ( ); }.bind(this)); return (
{featureNodes}
); } }); var Feature = React.createClass({ // TODO: validate props? /* handleStatusChange: function (feature, event) { console.log(feature); console.log(event); }, */ handleEnableChange: function(event) { var feature = this.props.feature; feature.enabled = event.target.checked; this.props.updateFeature(feature); }, render: function () { return (

{this.props.feature.name}

{this.props.feature.description}


); } }); React.renderComponent( FeatureList(null), document.getElementById('content') );