1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00
This commit is contained in:
Jari Bakken 2014-10-23 16:00:13 +02:00
parent c32b101093
commit dbcba1e49d

View File

@ -5,18 +5,21 @@
// Meny // Meny
// FeatureList // FeatureList
// Feature // Feature
// - name // FeatureViewer
// - status // - props
// - description
// - button-edit // - button-edit
// - button-delete // - button-delete
// - toggle-status // - toggle-status
// FeatureEditor
// - name
// - status
// - description
// //
// NewFeaturePage // NewFeaturePage
// Meny // Meny
// NewFeatureForm // NewFeatureForm
var FeatureForm = React.createClass({ var FeatureEditor = React.createClass({
getInitialState: function () { getInitialState: function () {
return {name: '', description: '', strategy: 'Default'}; return {name: '', description: '', strategy: 'Default'};
@ -84,16 +87,20 @@ var FeatureForm = React.createClass({
<div className="control-group"> <div className="control-group">
<div className="controls"> <div className="controls">
<input type="submit" value="Save" className="btn btn-success" /> <input type="submit" value="Save" className="btn btn-success" />
<input
type="button"
value="Cancel"
className="btn"
onClick={this.props.onToggleMode} />
</div> </div>
</div> </div>
</fieldset> </fieldset>
</form> </form>
); );
} }
}); });
var Feature = React.createClass({ var FeatureViewer = React.createClass({
// TODO: validate props? // TODO: validate props?
handleEnableChange: function(event) { handleEnableChange: function(event) {
var feature = this.props.feature; var feature = this.props.feature;
@ -101,7 +108,7 @@ var Feature = React.createClass({
name: feature.name, name: feature.name,
field: 'enabled', field: 'enabled',
value: event.target.checked value: event.target.checked
}); });
}, },
render: function () { render: function () {
@ -144,7 +151,7 @@ var Feature = React.createClass({
<div className='mod'> <div className='mod'>
<div className='inner'> <div className='inner'>
<div className='bd'> <div className='bd'>
<button className='pam mtl mll'>Edit</button> <button className='pam mtl mll' onClick={this.props.onToggleMode}>Edit</button>
<button className='pam mtl mll'>Delete</button> <button className='pam mtl mll'>Delete</button>
</div> </div>
</div> </div>
@ -158,6 +165,32 @@ var Feature = React.createClass({
} }
}); });
var Feature = React.createClass({
getInitialState: function() {
return { mode: 'view' };
},
onToggleMode: function() {
if (this.state.mode === 'view') {
this.setState({mode: 'edit'});
} else if (this.state.mode === 'edit') {
this.setState({mode: 'view'});
} else {
throw "invalid mode: " + this.state.mode;
}
},
render: function() {
if (this.state.mode === 'view') {
return (<FeatureViewer feature={this.props.feature} onToggleMode={this.onToggleMode} />);
} else if (this.state.mode === 'edit') {
return (<FeatureEditor feature={this.props.feature} onToggleMode={this.onToggleMode} />);
} else {
throw "invalid mode: " + this.state.mode;
}
}
});
var FeatureList = React.createClass({ var FeatureList = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
@ -199,7 +232,7 @@ var FeatureList = React.createClass({
}.bind(this)); }.bind(this));
}, },
createFeature: function (feature, callback) { createFeature: function (feature) {
reqwest({ reqwest({
url: 'features', url: 'features',
method: 'post', method: 'post',
@ -227,7 +260,6 @@ var FeatureList = React.createClass({
</div> </div>
<div className='panel-body'> <div className='panel-body'>
{featureNodes} {featureNodes}
<FeatureForm onFeatureSubmit={this.createFeature}/>
</div> </div>
</div> </div>
); );