1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 13:41:57 +02:00
onion/js/components/ascribe_uploader/file_drag_and_drop_preview.js

66 lines
2.3 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';
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,
handleCancelFile: React.PropTypes.func
2015-06-23 10:16:53 +02:00
},
2015-06-29 16:57:31 +02:00
toggleUploadProcess() {
},
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}
toggleUploadProcess={this.toggleUploadProcess}/>);
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]}
toggleUploadProcess={this.toggleUploadProcess}/>);
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-23 10:16:53 +02:00
{previewElement}
</div>
);
}
});
export default FileDragAndDropPreview;