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,
|
2015-07-01 12:13:05 +02:00
|
|
|
areAssetsDownloadable: React.PropTypes.bool,
|
|
|
|
areAssetsEditable: 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-30 16:15:50 +02:00
|
|
|
handleDownloadFile() {
|
|
|
|
if(this.props.file.s3Url) {
|
|
|
|
open(this.props.file.s3Url);
|
|
|
|
}
|
|
|
|
},
|
2015-06-25 14:18:55 +02:00
|
|
|
|
2015-06-23 10:16:53 +02:00
|
|
|
render() {
|
|
|
|
let previewElement;
|
2015-07-01 12:13:05 +02:00
|
|
|
let removeBtn;
|
2015-06-23 10:16:53 +02:00
|
|
|
|
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}
|
2015-06-30 16:15:50 +02:00
|
|
|
areAssetsDownloadable={this.props.areAssetsDownloadable}
|
2015-07-01 10:00:53 +02:00
|
|
|
downloadUrl={this.props.file.s3UrlSafe}/>);
|
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}
|
2015-06-30 16:15:50 +02:00
|
|
|
areAssetsDownloadable={this.props.areAssetsDownloadable}
|
2015-07-01 10:00:53 +02:00
|
|
|
downloadUrl={this.props.file.s3UrlSafe}/>);
|
2015-06-23 10:16:53 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 12:13:05 +02:00
|
|
|
if(this.props.areAssetsEditable) {
|
|
|
|
removeBtn = (<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
|
|
|
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-07-01 12:13:05 +02:00
|
|
|
{removeBtn}
|
2015-06-23 10:16:53 +02:00
|
|
|
{previewElement}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default FileDragAndDropPreview;
|