pitaya-launcher/src/components/edit/item-form.js

82 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-09-11 16:25:45 +02:00
var React = require('react');
var _ = require('lodash');
2015-09-11 16:25:45 +02:00
var ItemForm = React.createClass({
2015-09-16 17:26:56 +02:00
getInitialState: function() {
return {
label: '',
icon: '',
exec: ''
};
},
componentWillReceiveProps: function(props) {
if(props.item) {
this.setState({
label: props.item.label,
icon: props.item.icon,
2015-10-13 20:44:55 +02:00
exec: props.item.exec,
background: props.item.background
2015-09-16 17:26:56 +02:00
});
}
},
2015-09-11 16:25:45 +02:00
render: function() {
2015-09-16 17:26:56 +02:00
var state = this.state;
2015-09-11 16:25:45 +02:00
return (
<div className="item-form">
2015-09-16 17:26:56 +02:00
<form>
<div className="form-group">
<input type="text" className="form-control"
placeholder="Label"
value={state.label}
onChange={this.handleChange.bind(this, 'label')} />
</div>
<div className="form-group">
<input type="text" className="form-control"
2015-10-13 20:44:55 +02:00
placeholder="Icône"
2015-09-16 17:26:56 +02:00
value={state.icon}
onChange={this.handleChange.bind(this, 'icon')} />
</div>
<div className="form-group">
<input type="text" className="form-control"
2015-10-13 20:44:55 +02:00
placeholder="Chemin d'exécution" value={state.exec}
2015-09-16 17:26:56 +02:00
onChange={this.handleChange.bind(this, 'exec')} />
</div>
2015-10-13 20:44:55 +02:00
<div className="form-group">
<input type="text" className="form-control"
placeholder="Fond d'écran" value={state.background}
onChange={this.handleChange.bind(this, 'background')} />
</div>
2015-09-16 17:26:56 +02:00
</form>
2015-09-11 16:25:45 +02:00
</div>
);
2015-09-16 17:26:56 +02:00
},
handleChange: function(key, evt) {
evt.preventDefault();
var newState = {};
var value = evt.currentTarget.value;
newState[key] = value;
this.setState(newState);
if(typeof this.props.onItemChange === 'function') {
this.props.onItemChange(this.props.item, key, value);
}
2015-09-11 16:25:45 +02:00
}
});
module.exports = ItemForm;