1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 09:50:31 +01:00
onion/js/components/ascribe_forms/input_fineuploader.js

116 lines
3.8 KiB
JavaScript
Raw Normal View History

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';
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,
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-10 10:51:47 +02:00
enableLocalHashing: React.PropTypes.bool,
// provided by Property
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
}),
location: React.PropTypes.object
2015-09-10 10:51:47 +02:00
},
getInitialState() {
return {
value: null
};
},
submitFile(file){
2015-09-10 10:51:47 +02:00
this.setState({
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}
submitFile={this.submitFile}
2015-09-10 10:51:47 +02:00
setIsUploadReady={this.props.setIsUploadReady}
isReadyForFormSubmission={this.props.isReadyForFormSubmission}
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}
enableLocalHashing={this.props.enableLocalHashing}
fileClassToUpload={this.props.fileClassToUpload}
location={this.props.location}/>
2015-09-10 10:51:47 +02:00
);
}
});
export default InputFineUploader;