2015-07-07 18:07:12 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
2015-07-27 14:21:26 +02:00
|
|
|
import Router from 'react-router';
|
|
|
|
|
2015-07-23 17:17:48 +02:00
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
|
|
|
|
2015-07-27 14:21:26 +02:00
|
|
|
let Link = Router.Link;
|
|
|
|
|
2015-07-07 18:07:12 +02:00
|
|
|
let FileDragAndDropDialog = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
hasFiles: React.PropTypes.bool,
|
|
|
|
multipleFiles: React.PropTypes.bool,
|
2015-07-27 09:23:01 +02:00
|
|
|
onClick: React.PropTypes.func,
|
2015-07-27 15:34:45 +02:00
|
|
|
enableLocalHashing: React.PropTypes.bool
|
2015-07-07 18:07:12 +02:00
|
|
|
},
|
|
|
|
|
2015-07-27 14:21:26 +02:00
|
|
|
mixins: [Router.State],
|
|
|
|
|
2015-07-07 18:07:12 +02:00
|
|
|
render() {
|
2015-07-27 14:21:26 +02:00
|
|
|
const queryParams = this.getQuery();
|
|
|
|
|
2015-07-07 18:07:12 +02:00
|
|
|
if(this.props.hasFiles) {
|
|
|
|
return null;
|
|
|
|
} else {
|
2015-07-27 15:34:45 +02:00
|
|
|
if(this.props.enableLocalHashing && !queryParams.method) {
|
2015-07-27 14:21:26 +02:00
|
|
|
|
|
|
|
let queryParamsHash = Object.assign({}, queryParams);
|
|
|
|
queryParamsHash.method = 'hash';
|
|
|
|
|
|
|
|
let queryParamsUpload = Object.assign({}, queryParams);
|
|
|
|
queryParamsUpload.method = 'upload';
|
|
|
|
|
2015-07-07 18:07:12 +02:00
|
|
|
return (
|
2015-07-27 14:21:26 +02:00
|
|
|
<span className="file-drag-and-drop-dialog present-options">
|
|
|
|
<p>{getLangText('Would you rather')}</p>
|
|
|
|
<Link
|
|
|
|
to={this.getPath()}
|
|
|
|
query={queryParamsHash}>
|
|
|
|
<span className="btn btn-default btn-sm">
|
|
|
|
{getLangText('Hash your work')}
|
|
|
|
</span>
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
<span> or </span>
|
|
|
|
|
|
|
|
<Link
|
|
|
|
to={this.getPath()}
|
|
|
|
query={queryParamsUpload}>
|
|
|
|
<span className="btn btn-default btn-sm">
|
|
|
|
{getLangText('Upload and hash your work')}
|
|
|
|
</span>
|
|
|
|
</Link>
|
2015-07-23 17:17:48 +02:00
|
|
|
</span>
|
2015-07-07 18:07:12 +02:00
|
|
|
);
|
|
|
|
} else {
|
2015-07-27 14:21:26 +02:00
|
|
|
if(this.props.multipleFiles) {
|
|
|
|
return (
|
|
|
|
<span className="file-drag-and-drop-dialog">
|
|
|
|
{getLangText('Click or drag to add files')}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
let dialog = queryParams.method === 'hash' ? getLangText('choose a file to hash') : getLangText('choose a file to upload');
|
2015-07-27 09:23:01 +02:00
|
|
|
|
2015-07-27 14:21:26 +02:00
|
|
|
return (
|
|
|
|
<span className="file-drag-and-drop-dialog">
|
|
|
|
<p>{getLangText('Drag a file here')}</p>
|
|
|
|
<p>{getLangText('or')}</p>
|
|
|
|
<span
|
|
|
|
className="btn btn-default"
|
|
|
|
onClick={this.props.onClick}>
|
|
|
|
{dialog}
|
|
|
|
</span>
|
2015-07-15 16:50:32 +02:00
|
|
|
</span>
|
2015-07-27 14:21:26 +02:00
|
|
|
);
|
|
|
|
}
|
2015-07-07 18:07:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default FileDragAndDropDialog;
|