'use strict'; import React from 'react'; import FileDragAndDropPreviewImage from './file_drag_and_drop_preview_image'; import FileDragAndDropPreviewOther from './file_drag_and_drop_preview_other'; import { getLangText } from '../../utils/lang_utils.js'; let FileDragAndDropPreview = React.createClass({ propTypes: { file: React.PropTypes.shape({ url: React.PropTypes.string, type: React.PropTypes.string }).isRequired, handleDeleteFile: React.PropTypes.func, handleCancelFile: React.PropTypes.func, handlePauseFile: React.PropTypes.func, handleResumeFile: React.PropTypes.func, areAssetsDownloadable: React.PropTypes.bool, areAssetsEditable: React.PropTypes.bool }, toggleUploadProcess() { 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); } }, handleDeleteFile() { // handleDeleteFile is optional, so if its not submitted, // don't run it // 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) { this.props.handleDeleteFile(this.props.file.id); } else if(this.props.handleCancelFile && this.props.file.progress !== 100) { this.props.handleCancelFile(this.props.file.id); } }, handleDownloadFile() { if(this.props.file.s3Url) { open(this.props.file.s3Url); } }, render() { let previewElement; let removeBtn; // Decide whether an image or a placeholder picture should be displayed if(this.props.file.type.split('/')[0] === 'image') { previewElement = (); } else { previewElement = (); } if(this.props.areAssetsEditable) { removeBtn = (
); } return (
{removeBtn} {previewElement}
); } }); export default FileDragAndDropPreview;