var ResourceAdd = React.createClass({ componentDidMount: function () { }, getInitialState: function() { return {name: "", model: "IPAD", type: "DYNAMIC", tracking: "CONTINUOUS"}; }, handleSubmit: function(e) { e.preventDefault(); var resource = {rid: this.state.name, model: this.state.model, type: this.state.type}; nutella.net.publish("location/resource/add", resource); if(this.state.tracking == "CONTINUOUS") { if(this.state.type == "STATIC") resource.proximity_range = 0; resource.continuous = {x: this.props.room.x/2, y: this.props.room.y/2}; } else if(this.state.tracking == "DISCRETE") { resource.discrete = {x: 0, y: 0}; } else if(this.state.tracking == "PROXIMITY") { resource.proximity = {}; } nutella.net.publish("location/resource/update", resource); // Clean the form this.setState({name: ""}); }, handleChangeName: function(e) { this.setState({name: event.target.value}); }, handleChangeTypeDynamic: function(e) { this.setState({type: "DYNAMIC"}); }, handleChangeTypeStatic: function(e) { this.setState({type: "STATIC"}); if(this.state.tracking == "PROXIMITY") { this.setState({tracking: "NONE"}); } }, handleChangeTrackingContinuous: function(e) { this.setState({tracking: "CONTINUOUS"}); }, handleChangeTrackingDiscrete: function(e) { this.setState({tracking: "DISCRETE"}); }, handleTrackingProximity: function(e) { this.setState({tracking: "PROXIMITY"}); }, handleChangeTrackingNone: function(e) { this.setState({tracking: "NONE"}); }, handleChangeModelIMAC: function(e) { this.setState({model: "IMAC"}); }, handleChangeModelIPHONE: function(e) { this.setState({model: "IPHONE"}); }, handleChangeModelIPAD: function(e) { this.setState({model: "IPAD"}); }, handleChangeModelIBEACON: function(e) { this.setState({model: "IBEACON"}); }, handleChangeModelADISPLAY: function(e) { this.setState({model: "ADISPLAY"}); }, handleChangeModelTTABLE: function(e) { this.setState({model: "TTABLE"}); }, handleChangeModelOTHER: function(e) { this.setState({model: "OTHER"}); }, handleChangeModel: function(e) { this.setState({model: event.target.value}); }, render: function () { var type = ""; if(this.state.type == "STATIC") { type = S; } else if(this.state.type == "DYNAMIC") { type = D; } var proximity = {}; if(this.state.type == "DYNAMIC") proximity =
Add resource |
---|