/** * 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"; import EditFileContent from "./edit-file-content"; class EditFilesDialog extends React.Component { valid = true; constructor(props) { super(props); this.state = { uploadFile: null, uploadProgress: 0, editModal: false, modalFile: {} }; } onClose() { 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, }); this.setState({ uploadFile: null }); }; updateUploadProgress = (event) => { if (event.hasOwnProperty("percent")){ this.setState({ uploadProgress: parseInt(event.percent.toFixed(), 10) }); } else { this.setState({ uploadProgress: 0 }); } }; clearProgress = (newFileID) => { /*if (this.props.onChange != null) { let event = {} event["target"] = {} event.target["value"] = newFileID this.props.onChange(event); } */ this.setState({ uploadProgress: 0 }); }; closeEditModal(){ this.setState({editModal: false}); } deleteFile(index){ let file = this.props.files[index] AppDispatcher.dispatch({ type: 'files/start-remove', data: file, token: this.props.sessionToken }); } 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.onClose()} blendOutCancel = {true} valid={true} size = 'lg'>
this.deleteFile(index)} editButton onEdit={index => this.setState({ editModal: true, modalFile: this.props.files[index] })} />
this.selectUploadFile(event)} />
this.closeEditModal(data)} sessionToken={this.props.sessionToken} file={this.state.modalFile} />
); } } export default EditFilesDialog;