1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 17:45:10 +01:00
onion/js/components/ascribe_uploader/file_drag_and_drop_preview.js

94 lines
3.5 KiB
JavaScript
Raw Normal View History

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';
2015-07-03 19:08:56 +02:00
import { getLangText } from '../../utils/lang_utils.js'
2015-06-23 10:16:53 +02:00
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,
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
}
},
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;
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}
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}
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
}
if(this.props.areAssetsEditable) {
removeBtn = (<div className="delete-file">
2015-07-07 18:07:12 +02:00
<span
className="glyphicon glyphicon-remove text-center"
aria-hidden="true"
2015-07-03 19:08:56 +02:00
title={getLangText('Remove file')}
2015-07-07 18:07:12 +02:00
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">
{removeBtn}
2015-06-23 10:16:53 +02:00
{previewElement}
</div>
);
}
});
2015-07-03 19:08:56 +02:00
export default FileDragAndDropPreview;