From 7e2a59f6bab832cc9bb7ff6c0ee006979a6eb364 Mon Sep 17 00:00:00 2001 From: Jari Bakken Date: Fri, 24 Oct 2014 11:54:59 +0200 Subject: [PATCH] Ugly bootstrap form. --- unleash-server/public/js/unleash.jsx | 114 ++++++++++++++++++++++++--- 1 file changed, 105 insertions(+), 9 deletions(-) diff --git a/unleash-server/public/js/unleash.jsx b/unleash-server/public/js/unleash.jsx index 0f85e4e970..6c9818ba3e 100644 --- a/unleash-server/public/js/unleash.jsx +++ b/unleash-server/public/js/unleash.jsx @@ -14,12 +14,66 @@ var Menu = React.createClass({ var UnsavedFeature = React.createClass({ - // TODO: form - render: function() { return
; } + render: function() { + return ( +
+
+
+ + +
+ +
+
+ +
+
+ +
+ + +
+ +
+ +
+ + +
+
+ ); + }, + + saveFeature: function(e) { + e.preventDefault(); + + this.props.feature.name = this.refs.name.getDOMNode().value; + this.props.feature.description = this.refs.description.getDOMNode().value; + this.props.feature.strategy = this.refs.strategy.getDOMNode().value; + this.props.feature.enabled = this.refs.enabled.getDOMNode().checked; + + this.props.onSubmit(this.props.feature); + } }); var SavedFeature = React.createClass({ - onChange: function(event) { this.props.onChange({ name: this.props.feature.name, @@ -52,8 +106,14 @@ var FeatureList = React.createClass({ render: function() { var featureNodes = []; - this.props.unsavedFeatures.forEach(function(feature) { - featureNodes.push(); + this.props.unsavedFeatures.forEach(function(feature, idx) { + var key = 'new-' + idx; + featureNodes.push( + + ); }.bind(this)); this.props.savedFeatures.forEach(function(feature) { @@ -70,7 +130,9 @@ var FeatureList = React.createClass({

Features

-
@@ -86,7 +148,6 @@ var FeatureList = React.createClass({ var ErrorMessages = React.createClass({ - render: function() { if (!this.props.errors.length) { return
; @@ -151,7 +212,40 @@ var Unleash = React.createClass({ }, createFeature: function (feature) { - console.log(feature); + var unsaved = [], state = this.state; + + this.state.unsavedFeatures.forEach(function(f) { + // TODO: make sure we don't overwrite an existing feature + if (f.name === feature.name) { + state.savedFeatures.unshift(f); + } else { + unsaved.push(f); + } + }); + + this.setState({unsavedFeatures: unsaved}); + + reqwest({ + url: 'features', + method: 'post', + type: 'json', + contentType: 'application/json', + data: JSON.stringify(feature) + }).then(function(r) { + console.log(r); + }.bind(this), this.handleError); + }, + + newFeature: function() { + var blankFeature = { + name: '', + enabled: false, + strategy: 'default', + parameters: {} + }; + + this.state.unsavedFeatures.push(blankFeature); + this.forceUpdate(); }, render: function() { @@ -163,7 +257,9 @@ var Unleash = React.createClass({ unsavedFeatures={this.state.unsavedFeatures} savedFeatures={this.state.savedFeatures} onFeatureChanged={this.updateFeature} - onFeatureSubmit={this.createFeature} /> + onFeatureSubmit={this.createFeature} + onNewFeature={this.newFeature} + />
); }