From 7b5cf3de2d517d091f7e9436c2ce5ac13bf7848f Mon Sep 17 00:00:00 2001 From: andsandv Date: Thu, 23 Oct 2014 15:16:09 +0200 Subject: [PATCH] #12 post new features --- unleash-server/public/js/unleash.jsx | 70 ++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/unleash-server/public/js/unleash.jsx b/unleash-server/public/js/unleash.jsx index eadc60c70a..9cc7c0317a 100644 --- a/unleash-server/public/js/unleash.jsx +++ b/unleash-server/public/js/unleash.jsx @@ -18,44 +18,72 @@ var FeatureForm = React.createClass({ + getInitialState: function () { + return {name: '', description: '', strategy: 'Default'}; + }, + + handleNameChange: function(e) { this.setState({name: e.target.value.trim()}); }, + handleDescriptionChange: function(e) { this.setState({description: e.target.value.trim()}); }, + handleStrategyChange: function(e) { this.setState({strategy: e.target.value.trim()}); }, + + handleSubmit: function(e) { + e.preventDefault(); + this.props.onFeatureSubmit(this.state); + return; + }, + render: function () { return ( -
+
Add a new feature
- +
- +

Give the feature a name

- +
- +

Describe the feature

- +
- +
-
- +
@@ -152,7 +180,7 @@ var FeatureList = React.createClass({ f[changeRequest.field] = changeRequest.value; } }); - console.log(changeRequest); + reqwest({ url: 'features/' + changeRequest.name, method: 'patch', @@ -166,6 +194,20 @@ var FeatureList = React.createClass({ }.bind(this)); }, + createFeature: function (feature, callback) { + reqwest({ + url: 'features', + method: 'post', + type: 'json', + contentType: 'application/json', + data: JSON.stringify(feature) + }).then(function() { + // how do we communicate success? + }.bind(this), function() { + window.alert('create failed'); + }.bind(this)); + }, + render: function () { var featureNodes = this.state.features.map(function (feature) { return ( @@ -180,7 +222,7 @@ var FeatureList = React.createClass({
{featureNodes} - +
);