1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-10 21:18:38 +01:00
onion/js/components/ascribe_buttons/upload_file_button.js

93 lines
2.8 KiB
JavaScript
Raw Normal View History

2015-11-09 10:35:23 +01:00
'use strict';
import React from 'react';
import Glyphicon from 'react-bootstrap/lib/Glyphicon';
2015-11-09 10:35:23 +01:00
import ReactS3FineUploader from '../ascribe_uploader/react_s3_fine_uploader';
import UploadButton from '../ascribe_uploader/ascribe_upload_button/upload_button';
import AppConstants from '../../constants/application_constants';
import ApiUrls from '../../constants/api_urls';
import { getCookie } from '../../utils/fetch_api_utils';
import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils';
const { shape, arrayOf, string, object, number, oneOfType } = React.PropTypes;
const UploadFileButton = React.createClass({
propTypes: {
keyRoutine: shape({
url: string,
fileClass: string
}).isRequired,
validation: shape({
itemLimit: number,
sizeLimit: oneOfType([string, number]),
allowedExtensions: arrayOf(string)
}),
location: object,
fileClassToUpload: shape({
singular: string,
plural: string
}).isRequired,
createBlobRoutine: shape({
url: string,
pieceId: number
})
2015-11-09 10:35:23 +01:00
},
getInitialState() {
return {
file: null
};
2015-11-09 10:35:23 +01:00
},
handleSubmitFile(file) {
this.setState({
file
});
},
2015-11-09 10:35:23 +01:00
createBlobRoutine() {
const { fineuploader } = this.refs;
const { file } = this.state;
fineuploader.createBlob(file);
},
render() {
const { fileClassToUpload, validation, keyRoutine, createBlobRoutine } = this.props;
2015-11-09 10:35:23 +01:00
return (
<ReactS3FineUploader
ref="fineuploader"
2015-11-09 10:35:23 +01:00
fileInputElement={UploadButton}
keyRoutine={keyRoutine}
createBlobRoutine={createBlobRoutine}
2015-11-09 10:35:23 +01:00
validation={validation}
setIsUploadReady={() =>{/* So that ReactS3FineUploader is not complaining */}}
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)
}
}}
fileClassToUpload={fileClassToUpload}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
submitFile={this.handleSubmitFile}
2015-11-09 10:35:23 +01:00
location={this.props.location}/>
);
2015-11-09 10:35:23 +01:00
}
});
export default UploadFileButton;