2015-09-10 10:51:47 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import ReactS3FineUploader from '../ascribe_uploader/react_s3_fine_uploader';
|
|
|
|
|
|
|
|
import AppConstants from '../../constants/application_constants';
|
|
|
|
|
|
|
|
import { getCookie } from '../../utils/fetch_api_utils';
|
|
|
|
|
2015-09-21 12:05:42 +02:00
|
|
|
let InputFineUploader = React.createClass({
|
2015-09-10 10:51:47 +02:00
|
|
|
propTypes: {
|
|
|
|
setIsUploadReady: React.PropTypes.func,
|
|
|
|
isReadyForFormSubmission: React.PropTypes.func,
|
2015-09-14 16:15:01 +02:00
|
|
|
submitFileName: React.PropTypes.func,
|
|
|
|
|
2015-09-21 12:05:42 +02:00
|
|
|
areAssetsDownloadable: React.PropTypes.bool,
|
|
|
|
|
2015-09-10 10:51:47 +02:00
|
|
|
onClick: React.PropTypes.func,
|
2015-09-11 10:11:07 +02:00
|
|
|
keyRoutine: React.PropTypes.shape({
|
|
|
|
url: React.PropTypes.string,
|
|
|
|
fileClass: React.PropTypes.string
|
|
|
|
}),
|
|
|
|
createBlobRoutine: React.PropTypes.shape({
|
|
|
|
url: React.PropTypes.string
|
|
|
|
}),
|
|
|
|
validation: React.PropTypes.shape({
|
|
|
|
itemLimit: React.PropTypes.number,
|
2015-09-14 16:15:01 +02:00
|
|
|
sizeLimit: React.PropTypes.string,
|
|
|
|
allowedExtensions: React.PropTypes.arrayOf(React.PropTypes.string)
|
2015-09-11 10:11:07 +02:00
|
|
|
}),
|
2015-09-10 10:51:47 +02:00
|
|
|
|
|
|
|
// isFineUploaderActive is used to lock react fine uploader in case
|
|
|
|
// a user is actually not logged in already to prevent him from droping files
|
|
|
|
// before login in
|
|
|
|
isFineUploaderActive: React.PropTypes.bool,
|
|
|
|
onLoggedOut: React.PropTypes.func,
|
2015-09-21 12:05:42 +02:00
|
|
|
|
2015-09-10 10:51:47 +02:00
|
|
|
enableLocalHashing: React.PropTypes.bool,
|
|
|
|
|
|
|
|
// provided by Property
|
2015-09-14 16:33:32 +02:00
|
|
|
disabled: React.PropTypes.bool,
|
|
|
|
|
|
|
|
// A class of a file the user has to upload
|
|
|
|
// Needs to be defined both in singular as well as in plural
|
|
|
|
fileClassToUpload: React.PropTypes.shape({
|
|
|
|
singular: React.PropTypes.string,
|
|
|
|
plural: React.PropTypes.string
|
|
|
|
})
|
2015-09-10 10:51:47 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
value: null
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-09-14 14:46:03 +02:00
|
|
|
submitFile(file){
|
2015-09-10 10:51:47 +02:00
|
|
|
this.setState({
|
2015-09-14 14:46:03 +02:00
|
|
|
value: file.key
|
2015-09-10 10:51:47 +02:00
|
|
|
});
|
2015-09-14 16:15:01 +02:00
|
|
|
|
|
|
|
if(typeof this.props.submitFileName === 'function') {
|
|
|
|
this.props.submitFileName(file.originalName);
|
|
|
|
}
|
2015-09-10 10:51:47 +02:00
|
|
|
},
|
|
|
|
|
2015-09-10 11:22:42 +02:00
|
|
|
reset() {
|
|
|
|
this.refs.fineuploader.reset();
|
|
|
|
},
|
2015-09-10 10:51:47 +02:00
|
|
|
|
2015-09-10 11:22:42 +02:00
|
|
|
render() {
|
2015-09-10 10:51:47 +02:00
|
|
|
let editable = this.props.isFineUploaderActive;
|
|
|
|
|
|
|
|
// if disabled is actually set by property, we want to override
|
|
|
|
// isFineUploaderActive
|
|
|
|
if(typeof this.props.disabled !== 'undefined') {
|
|
|
|
editable = !this.props.disabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ReactS3FineUploader
|
2015-09-10 11:22:42 +02:00
|
|
|
ref="fineuploader"
|
2015-09-10 10:51:47 +02:00
|
|
|
onClick={this.props.onClick}
|
2015-09-11 10:11:07 +02:00
|
|
|
keyRoutine={this.props.keyRoutine}
|
|
|
|
createBlobRoutine={this.props.createBlobRoutine}
|
|
|
|
validation={this.props.validation}
|
2015-09-14 14:46:03 +02:00
|
|
|
submitFile={this.submitFile}
|
2015-09-10 10:51:47 +02:00
|
|
|
setIsUploadReady={this.props.setIsUploadReady}
|
|
|
|
isReadyForFormSubmission={this.props.isReadyForFormSubmission}
|
2015-09-21 12:05:42 +02:00
|
|
|
areAssetsDownloadable={this.props.areAssetsDownloadable}
|
2015-09-10 10:51:47 +02:00
|
|
|
areAssetsEditable={editable}
|
|
|
|
signature={{
|
|
|
|
endpoint: AppConstants.serverUrl + 's3/signature/',
|
|
|
|
customHeaders: {
|
|
|
|
'X-CSRFToken': getCookie(AppConstants.csrftoken)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
deleteFile={{
|
|
|
|
enabled: true,
|
|
|
|
method: 'DELETE',
|
|
|
|
endpoint: AppConstants.serverUrl + 's3/delete',
|
|
|
|
customHeaders: {
|
|
|
|
'X-CSRFToken': getCookie(AppConstants.csrftoken)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
onInactive={this.props.onLoggedOut}
|
2015-09-14 17:02:47 +02:00
|
|
|
enableLocalHashing={this.props.enableLocalHashing}
|
2015-09-14 16:33:32 +02:00
|
|
|
fileClassToUpload={this.props.fileClassToUpload}/>
|
2015-09-10 10:51:47 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-09-21 12:05:42 +02:00
|
|
|
export default InputFineUploader;
|