diff --git a/src/widget/edit-widget/edit-widget-image-control.js b/src/widget/edit-widget/edit-widget-image-control.js index 0f2c9e7..abfd517 100644 --- a/src/widget/edit-widget/edit-widget-image-control.js +++ b/src/widget/edit-widget/edit-widget-image-control.js @@ -21,6 +21,7 @@ import {FormGroup, FormControl, FormLabel, Button, ProgressBar} from 'react-boot import AppDispatcher from '../../common/app-dispatcher'; class EditImageWidgetControl extends React.Component { + constructor(props) { super(props); @@ -43,7 +44,7 @@ class EditImageWidgetControl extends React.Component { for (let key in this.state.fileList) { if (this.state.fileList.hasOwnProperty(key) && this.state.fileList[key] instanceof File) { - formData.append(key, this.state.fileList[key]); + formData.append("file", this.state.fileList[key]); } } @@ -68,7 +69,6 @@ class EditImageWidgetControl extends React.Component { } handleFileChange(e){ - console.log("Changing image: ", this.props.controlId, "to", e.target.value) this.props.handleChange({ target: { id: this.props.controlId, value: e.target.value } }); } @@ -80,7 +80,14 @@ class EditImageWidgetControl extends React.Component { isCustomProperty = false; } - console.log("edit image: files: ", this.props.files, "widget", this.state.widget, "upload file list:", this.state.fileList); + let fileOptions; + if (this.props.files.length > 0){ + fileOptions = this.props.files.map((file, index) => ( + + )) + } else { + fileOptions.set = + } return
, prevState: Readonly, snapshot: SS) {
- fileData = new Blob([file.data], {type: file.type});
- objectURL = window.URL.createObjectURL(fileData);
- console.log("Image created new file", fileData, "and objectID", objectURL)
+ let file = this.props.files.find(file => file.id === parseInt(this.props.widget.customProperties.file, 10));
+
+ if(file !== undefined){
+ if(this.state.file === undefined || (this.state.file.id !== file.id )){
+
+ // if file has changed, download new file
+ if (this.state.file !== undefined && this.state.file.id !== file.id){
+ AppDispatcher.dispatch({
+ type: 'files/start-download',
+ data: file.id,
+ token: this.props.token
+ });
+ }
+
+ // either first time update or file id has changed
+ this.setState({file:file})
}
}
- console.log("Image: has data:", fileHasData);
+ }
+
+ imageError(e){
+ console.error("Image ", this.state.file.name, "cannot be displayed.");
+ }
+
+ render() {
+
+ let objectURL=''
+ if(this.state.file !== undefined && this.state.file.objectURL !== undefined) {
+ objectURL = this.state.file.objectURL
+ }
return (
e.preventDefault()} />
+ {objectURL !== '' ? (
+
this.imageError(e)} className="full" alt={this.state.file.name} src={objectURL} onDragStart={e => e.preventDefault()} />
) : (
)}