/** * This file is part of VILLASweb. * * VILLASweb is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VILLASweb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VILLASweb. If not, see . ******************************************************************************/ import React from 'react'; import {FormGroup, FormControl, Button, Col, ProgressBar} from 'react-bootstrap'; import Dialog from '../common/dialogs/dialog'; import AppDispatcher from "../common/app-dispatcher"; import Table from "../common/table"; import TableColumn from "../common/table-column"; class EditFilesDialog extends React.Component { valid = true; constructor(props) { super(props); this.state = { uploadFile: null, uploadProgress: 0 }; } onClose(canceled) { if (canceled === false) { if (this.validChanges()) { this.props.onClose(); } } else { this.props.onClose(); } } selectUploadFile(event) { this.setState({ uploadFile: event.target.files[0] }); }; startFileUpload(){ // upload file const formData = new FormData(); formData.append("file", this.state.uploadFile); AppDispatcher.dispatch({ type: 'files/start-upload', data: formData, token: this.props.sessionToken, progressCallback: this.updateUploadProgress, finishedCallback: this.clearProgress, scenarioID: this.props.scenarioID, }); // TODO make sure that dialog remains open after clicking "Upload" button }; updateUploadProgress = (event) => { this.setState({ uploadProgress: parseInt(event.percent.toFixed(), 10) }); }; clearProgress = (newFileID) => { /*if (this.props.onChange != null) { let event = {} event["target"] = {} event.target["value"] = newFileID this.props.onChange(event); } */ this.setState({ uploadProgress: 0 }); }; deleteFile(index){ let file = this.props.files[index] AppDispatcher.dispatch({ type: 'files/start-remove', data: file, token: this.props.sessionToken }); // TODO make sure that dialog remains open after clicking delete button } render() { let fileOptions = []; if (this.props.files.length > 0){ fileOptions.push( ) fileOptions.push(this.props.files.map((file, index) => ( ))) } else { fileOptions = } const progressBarStyle = { marginLeft: '100px', marginTop: '-40px' }; return (
this.deleteFile(index)} />
this.selectUploadFile(event)} />
); } } export default EditFilesDialog;