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

80 lines
2.6 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 ProgressBar from 'react-bootstrap/lib/ProgressBar';
2015-06-23 10:16:53 +02:00
import AscribeSpinner from '../../ascribe_spinner';
2015-09-15 11:13:17 +02:00
import { getLangText } from '../../../utils/lang_utils';
2015-06-29 17:37:14 +02:00
const { number, string, func, bool } = React.PropTypes;
const FileDragAndDropPreviewImage = React.createClass({
2015-06-23 10:16:53 +02:00
propTypes: {
progress: number,
url: string,
toggleUploadProcess: func,
downloadUrl: string,
areAssetsDownloadable: bool
2015-06-23 10:16:53 +02:00
},
2015-06-29 14:36:55 +02:00
getInitialState() {
return {
2015-06-29 16:57:31 +02:00
paused: true
2015-06-29 14:36:55 +02:00
};
},
2015-06-29 16:46:12 +02:00
toggleUploadProcess(e) {
e.preventDefault();
e.stopPropagation();
this.setState({
2015-06-29 17:37:14 +02:00
paused: !this.state.paused
2015-06-29 16:46:12 +02:00
});
2015-06-29 17:37:14 +02:00
this.props.toggleUploadProcess();
2015-06-29 14:36:55 +02:00
},
2015-06-23 10:16:53 +02:00
render() {
let imageStyle = {
backgroundImage: 'url("' + this.props.url + '")',
backgroundSize: 'cover'
};
2015-06-29 16:57:31 +02:00
let actionSymbol;
2015-06-29 17:37:14 +02:00
if(this.props.progress > 0 && this.props.progress < 99 && this.state.paused) {
2015-07-03 19:08:56 +02:00
actionSymbol = <span className="glyphicon glyphicon-pause action-file" aria-hidden="true" title={getLangText('Pause upload')} onClick={this.toggleUploadProcess}/>;
2015-06-29 17:37:14 +02:00
} else if(this.props.progress > 0 && this.props.progress < 99 && !this.state.paused) {
2015-07-03 19:08:56 +02:00
actionSymbol = <span className="glyphicon glyphicon-play action-file" aria-hidden="true" title={getLangText('Resume uploading')} onClick={this.toggleUploadProcess}/>;
2015-06-29 17:37:14 +02:00
} else if(this.props.progress === 100) {
2015-06-30 13:53:02 +02:00
// only if assets are actually downloadable, there should be a download icon if the process is already at
// 100%. If not, no actionSymbol should be displayed
if(this.props.areAssetsDownloadable) {
2015-07-03 19:08:56 +02:00
actionSymbol = <a href={this.props.downloadUrl} target="_blank" className="glyphicon glyphicon-download action-file" aria-hidden="true" title={getLangText('Download file')}/>;
2015-06-30 13:53:02 +02:00
}
2015-06-29 17:37:14 +02:00
} else {
actionSymbol = (
<div className="spinner-file">
<AscribeSpinner color='dark-blue' size='md' />
</div>
);
2015-06-29 16:57:31 +02:00
}
2015-06-23 10:16:53 +02:00
return (
<div
className="file-drag-and-drop-preview-image"
style={imageStyle}>
<ProgressBar
now={Math.ceil(this.props.progress)}
className="ascribe-progress-bar ascribe-progress-bar-xs"/>
2015-06-29 16:57:31 +02:00
{actionSymbol}
2015-06-23 10:16:53 +02:00
</div>
);
}
});
2015-07-03 19:08:56 +02:00
export default FileDragAndDropPreviewImage;