/** * File: edit-widget.js * Author: Markus Grigull * Date: 08.03.2017 * Copyright: 2017, Institute for Automation of Complex Power Systems, EONERC * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. * Unauthorized copying of this file, via any medium is strictly prohibited. **********************************************************************************/ import React, { Component, PropTypes } from 'react'; import { FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; import Dialog from './dialog'; import EditValueWidget from './edit-widget-value'; import EditPlotWidget from './edit-widget-plot'; import EditTableWidget from './edit-widget-table'; import EditImageWidget from './edit-widget-image'; class EditWidgetDialog extends Component { static propTypes = { show: PropTypes.bool.isRequired, onClose: PropTypes.func.isRequired }; valid: true; constructor(props) { super(props); this.state = { temporal: { name: '', simulator: '', signal: 0 } }; } onClose(canceled) { if (canceled === false) { this.props.onClose(this.state.temporal); } else { this.props.onClose(); } } handleChange(e, index) { var update = this.state.temporal; update[e.target.id] = e.target.value; this.setState({ temporal: update }); //console.log(this.state.widget); } resetState() { var widget_data = Object.assign({}, this.props.widget); this.setState({ temporal: widget_data }); } validateForm(target) { // check all controls var name = true; if (this.state.name === '') { name = false; } this.valid = name; // return state to control if (target === 'name') return name ? "success" : "error"; } render() { // get widget part var widgetDialog = null; if (this.props.widget) { if (this.props.widget.type === 'Value') { widgetDialog = this.validateForm(id)} simulation={this.props.simulation} handleChange={(e) => this.handleChange(e)} />; } else if (this.props.widget.type === 'Plot') { widgetDialog = this.validateForm(id)} simulation={this.props.simulation} handleChange={(e, index) => this.handleChange(e, index)} />; } else if (this.props.widget.type === 'Table') { widgetDialog = this.validateForm(id)} simulation={this.props.simulation} handleChange={(e, index) => this.handleChange(e, index)} />; } else if (this.props.widget.type === 'Image') { widgetDialog = this.validateForm(id)} simulation={this.props.simulation} handleChange={(e, index) => this.handleChange(e, index)} />; } } return ( this.onClose(c)} onReset={() => this.resetState()} valid={this.valid}>
Name this.handleChange(e)} /> {widgetDialog}
); } } export default EditWidgetDialog;