2015-06-25 13:28:49 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-06-23 10:16:53 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import FileDragAndDropPreviewImage from './file_drag_and_drop_preview_image';
|
|
|
|
import FileDragAndDropPreviewOther from './file_drag_and_drop_preview_other';
|
|
|
|
|
|
|
|
|
|
|
|
let FileDragAndDropPreview = React.createClass({
|
|
|
|
|
2015-06-25 13:28:49 +02:00
|
|
|
propTypes: {
|
2015-06-23 10:16:53 +02:00
|
|
|
file: React.PropTypes.shape({
|
|
|
|
url: React.PropTypes.string,
|
|
|
|
type: React.PropTypes.string
|
|
|
|
}).isRequired,
|
2015-06-29 10:01:54 +02:00
|
|
|
handleDeleteFile: React.PropTypes.func,
|
2015-06-29 17:37:14 +02:00
|
|
|
handleCancelFile: React.PropTypes.func,
|
|
|
|
handlePauseFile: React.PropTypes.func,
|
2015-06-30 13:53:02 +02:00
|
|
|
handleResumeFile: React.PropTypes.func,
|
|
|
|
areAssetsDownloadable: React.PropTypes.bool
|
2015-06-23 10:16:53 +02:00
|
|
|
},
|
|
|
|
|
2015-06-29 16:57:31 +02:00
|
|
|
toggleUploadProcess() {
|
2015-06-29 17:37:14 +02:00
|
|
|
if(this.props.file.status === 'uploading') {
|
|
|
|
this.props.handlePauseFile(this.props.file.id);
|
|
|
|
} else if(this.props.file.status === 'paused') {
|
|
|
|
this.props.handleResumeFile(this.props.file.id);
|
|
|
|
}
|
2015-06-29 16:57:31 +02:00
|
|
|
},
|
|
|
|
|
2015-06-29 16:00:26 +02:00
|
|
|
handleDeleteFile() {
|
2015-06-23 10:16:53 +02:00
|
|
|
// handleDeleteFile is optional, so if its not submitted,
|
|
|
|
// don't run it
|
2015-06-29 10:01:54 +02:00
|
|
|
// On the other hand, if the files progress is not yet at a 100%,
|
|
|
|
// just run fineuploader.cancel
|
|
|
|
if(this.props.handleDeleteFile && this.props.file.progress === 100) {
|
2015-06-23 10:16:53 +02:00
|
|
|
this.props.handleDeleteFile(this.props.file.id);
|
2015-06-29 10:01:54 +02:00
|
|
|
} else if(this.props.handleCancelFile && this.props.file.progress !== 100) {
|
|
|
|
this.props.handleCancelFile(this.props.file.id);
|
2015-06-23 10:16:53 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-25 14:18:55 +02:00
|
|
|
// implement a handle cancel action here that triggers fineuploaders cancel method
|
|
|
|
// to delete files that are currently uploading
|
|
|
|
|
2015-06-23 10:16:53 +02:00
|
|
|
render() {
|
|
|
|
let previewElement;
|
|
|
|
|
2015-06-25 13:28:49 +02:00
|
|
|
// Decide whether an image or a placeholder picture should be displayed
|
2015-06-23 10:16:53 +02:00
|
|
|
if(this.props.file.type.split('/')[0] === 'image') {
|
2015-06-25 13:28:49 +02:00
|
|
|
previewElement = (<FileDragAndDropPreviewImage
|
2015-06-25 13:46:10 +02:00
|
|
|
onClick={this.handleDeleteFile}
|
|
|
|
progress={this.props.file.progress}
|
2015-06-29 16:57:31 +02:00
|
|
|
url={this.props.file.url}
|
2015-06-30 13:53:02 +02:00
|
|
|
toggleUploadProcess={this.toggleUploadProcess}
|
|
|
|
areAssetsDownloadable={this.props.areAssetsDownloadable}/>);
|
2015-06-23 10:16:53 +02:00
|
|
|
} else {
|
2015-06-25 13:28:49 +02:00
|
|
|
previewElement = (<FileDragAndDropPreviewOther
|
2015-06-25 13:46:10 +02:00
|
|
|
onClick={this.handleDeleteFile}
|
|
|
|
progress={this.props.file.progress}
|
2015-06-29 16:57:31 +02:00
|
|
|
type={this.props.file.type.split('/')[1]}
|
2015-06-30 13:53:02 +02:00
|
|
|
toggleUploadProcess={this.toggleUploadProcess}
|
|
|
|
areAssetsDownloadable={this.props.areAssetsDownloadable}/>);
|
2015-06-23 10:16:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2015-06-25 13:28:49 +02:00
|
|
|
<div
|
2015-06-25 13:46:10 +02:00
|
|
|
className="file-drag-and-drop-position">
|
2015-06-29 17:59:35 +02:00
|
|
|
<div className="delete-file">
|
|
|
|
<span className="glyphicon glyphicon-remove text-center" aria-hidden="true" title="Remove file" onClick={this.handleDeleteFile}/>
|
|
|
|
</div>
|
2015-06-23 10:16:53 +02:00
|
|
|
{previewElement}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default FileDragAndDropPreview;
|