var UIJSONAttribute = React.createClass ({ getInitialState: function() { return({ type: "string", value: "", key: "", application: undefined, instance: undefined, component: undefined }) }, handleTypeChange: function(type) { this.setState({type: type}); this.updateJson = true; }, handleKeyChange: function(event) { /* switch(this.state.type) { case "string": this.setState({key: event.target.value}); break; } */ this.setState({key: event.target.value}); this.props.updateJSON(); }, handleValueChange: function() { switch(this.state.type) { case "string": case "number": this.setState({value: event.target.value}); break; } this.props.updateJSON(); }, getJson: function() { if(this.props.keyEnabled) { var json = {}; switch (this.state.type) { case "string": json[this.refs.key.getDOMNode().value] = this.refs.value.getDOMNode().value; break; case "number": json[this.refs.key.getDOMNode().value] = parseFloat(this.refs.value.getDOMNode().value); break; case "array": // TODO: check refs json[this.refs.key.getDOMNode().value] = this.refs.array.getJson(); break; case "object": json[this.refs.key.getDOMNode().value] = this.refs.object.getJson(); break; } return json; } else { switch (this.state.type) { case "string": return this.refs.value.getDOMNode().value; break; case "number": return parseFloat(this.refs.value.getDOMNode().value); break; case "array": // TODO: check refs return this.refs.array.getJson(); break; case "object": return this.refs.object.getJson(); break; } } }, render: function() { var self = this; var inputBox = ""; switch(this.state.type) { case "string": case "number": inputBox =
; break; case "array": inputBox =
; break; case "object": inputBox =
; break; } return (
{ this.props.keyEnabled ? : "" }
{inputBox}
); }, updateJson: false, componentDidUpdate: function() { if(this.updateJson) { this.props.updateJSON(); this.updateJson = false; } } }); var UIJSONArray = React.createClass ({ getInitialState: function () { return ({ elements: 1 }) }, deleteElement: function(key) { this.setState({ elements: this.state.elements - 1 }); this.updateJson = true; }, addElement: function() { this.setState({elements: this.state.elements + 1}); }, getJson: function() { var array = []; // Construct the json with the children for(var i = 0; i < this.state.elements; i++) { var element = this.refs['array-element-' + i].getJson(); array.push(element); } this.setState({oldJson: array}); return array; }, render: function() { var attributes = []; for(var i = 0; i < this.state.elements; i++) { attributes.push( ); } return(
{attributes}
); }, updateJson: false, componentDidUpdate: function() { if(this.updateJson) { this.props.updateJSON(); this.updateJson = false; } } }); var UIJSONObject = React.createClass ({ getInitialState: function() { return({ attributes: 1 }) }, getJson: function() { //alert("Get json UIJSONObject"); var json = {}; // Construct the json with the children for(var i = 0; i < this.state.attributes; i++) { var attribute = this.refs['object-attribute-' + i].getJson(); json = _.extend(json, attribute); } this.setState({oldJson: json}); return json; }, deleteAttribute: function(key) { this.setState({ attributes: this.state.attributes - 1 }); this.updateJson = true; }, addAttribute: function() { this.setState({attributes: this.state.attributes + 1}); }, render: function() { var attributes = []; for(var i = 0; i < this.state.attributes; i++) { attributes.push( ); } return(
{attributes}
); }, updateJson: false, componentDidUpdate: function() { if(this.updateJson) { this.props.updateJSON(); this.updateJson = false; } } }); var UIJSONRender = React.createClass ({ render: function() { return(
                
                    {JSON.stringify(this.props.json, null, 4)}
                
            
); }, /* componentDidUpdate: function() { $('pre code').each(function(i, block) { hljs.highlightBlock(block); }); } */ }); var UIMessageSend = React.createClass ({ getInitialState: function() { return { application: undefined, instance: undefined, component: undefined, json: {} } }, componentDidMount: function() { var self = this; notificationCenter.subscribe(Notifications.alerts.ALERT_CHANGE, function() { self.setState({ application: alertsModel.application, instance: alertsModel.instance, component: alertsModel.component }); }); }, updateJSON: function() { //alert("Update JSON"); this.setState({json: this.refs.jsonObject.getJson()}) }, sendMessage: function() { alert("Send message"); var payload = this.refs.jsonObject.getJson(); console.log(payload); var channel = messageModel.channel; nutellaFramework.f.net.publish_to_run(this.state.application, this.state.instance, channel, payload) }, render: function() { var self = this; subscription = []; if(this.state.application != undefined) { subscription.push(application: {this.state.application}); } if(this.state.instance != undefined) { subscription.push( instance: {this.state.instance}); } if(this.state.component != undefined) { subscription.push( component: {this.state.component}); } subscription.push( on channel: {messageModel.channel}); return (

Send message to {subscription}

); } });