2015-08-12 13:34:41 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import Property from './../ascribe_forms/property';
|
|
|
|
|
|
|
|
import ReactS3FineUploader from './../ascribe_uploader/react_s3_fine_uploader';
|
|
|
|
|
|
|
|
import ApiUrls from '../../constants/api_urls';
|
|
|
|
import AppConstants from '../../constants/application_constants';
|
|
|
|
|
|
|
|
import { getCookie } from '../../utils/fetch_api_utils';
|
2015-12-08 20:55:13 +01:00
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
|
|
|
|
2015-08-12 13:34:41 +02:00
|
|
|
|
2015-12-08 20:57:40 +01:00
|
|
|
const { func, bool, number, object, string, arrayOf } = React.PropTypes;
|
2015-12-08 18:09:24 +01:00
|
|
|
|
2015-08-12 13:34:41 +02:00
|
|
|
let FurtherDetailsFileuploader = React.createClass({
|
|
|
|
propTypes: {
|
2015-12-08 20:55:13 +01:00
|
|
|
label: string,
|
2015-12-08 18:09:24 +01:00
|
|
|
pieceId: number,
|
|
|
|
otherData: arrayOf(object),
|
|
|
|
editable: bool,
|
|
|
|
|
|
|
|
// Props for ReactS3FineUploader
|
|
|
|
multiple: bool,
|
2015-12-08 18:22:11 +01:00
|
|
|
showErrorPrompt: bool,
|
2015-12-08 18:09:24 +01:00
|
|
|
submitFile: func, // TODO: rename to onSubmitFile
|
|
|
|
|
|
|
|
setIsUploadReady: func, //TODO: rename to setIsUploaderValidated
|
|
|
|
isReadyForFormSubmission: func
|
2015-08-12 13:34:41 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
2015-12-08 20:55:13 +01:00
|
|
|
label: getLangText('Additional files'),
|
2015-08-12 13:34:41 +02:00
|
|
|
multiple: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
2015-12-08 18:09:24 +01:00
|
|
|
const {
|
|
|
|
editable,
|
|
|
|
isReadyForFormSubmission,
|
|
|
|
multiple,
|
|
|
|
otherData,
|
|
|
|
pieceId,
|
|
|
|
setIsUploadReady,
|
2015-12-08 18:22:11 +01:00
|
|
|
showErrorPrompt,
|
2015-12-08 18:09:24 +01:00
|
|
|
submitFile } = this.props;
|
|
|
|
|
2015-08-12 13:34:41 +02:00
|
|
|
// Essentially there a three cases important to the fileuploader
|
|
|
|
//
|
2015-08-24 11:22:44 +02:00
|
|
|
// 1. there is no other_data => do not show the fileuploader at all (where otherData is now an array)
|
2015-08-12 13:34:41 +02:00
|
|
|
// 2. there is other_data, but user has no edit rights => show fileuploader but without action buttons
|
2015-08-20 11:32:11 +02:00
|
|
|
// 3. both other_data and editable are defined or true => show fileuploader with all action buttons
|
2015-12-08 18:09:24 +01:00
|
|
|
if (!editable && (!otherData || otherData.length === 0)) {
|
2015-08-12 13:34:41 +02:00
|
|
|
return null;
|
|
|
|
}
|
2015-08-21 14:07:10 +02:00
|
|
|
|
2015-12-08 18:09:24 +01:00
|
|
|
let otherDataIds = otherData ? otherData.map((data) => data.id).join() : null;
|
2015-08-17 20:52:36 +02:00
|
|
|
|
2015-08-12 13:34:41 +02:00
|
|
|
return (
|
|
|
|
<Property
|
2015-11-02 10:42:15 +01:00
|
|
|
name="other_data_key"
|
2015-12-08 20:55:13 +01:00
|
|
|
label={this.props.label}>
|
2015-08-12 13:34:41 +02:00
|
|
|
<ReactS3FineUploader
|
|
|
|
keyRoutine={{
|
|
|
|
url: AppConstants.serverUrl + 's3/key/',
|
|
|
|
fileClass: 'otherdata',
|
2015-12-08 18:09:24 +01:00
|
|
|
pieceId: pieceId
|
2015-08-12 13:34:41 +02:00
|
|
|
}}
|
|
|
|
createBlobRoutine={{
|
|
|
|
url: ApiUrls.blob_otherdatas,
|
2015-12-08 18:09:24 +01:00
|
|
|
pieceId: pieceId
|
2015-08-12 13:34:41 +02:00
|
|
|
}}
|
2015-09-16 15:14:08 +02:00
|
|
|
validation={AppConstants.fineUploader.validation.additionalData}
|
2015-12-08 18:09:24 +01:00
|
|
|
submitFile={submitFile}
|
|
|
|
setIsUploadReady={setIsUploadReady}
|
|
|
|
isReadyForFormSubmission={isReadyForFormSubmission}
|
2015-08-12 13:34:41 +02:00
|
|
|
session={{
|
|
|
|
endpoint: AppConstants.serverUrl + 'api/blob/otherdatas/fineuploader_session/',
|
|
|
|
customHeaders: {
|
|
|
|
'X-CSRFToken': getCookie(AppConstants.csrftoken)
|
|
|
|
},
|
|
|
|
params: {
|
2015-08-17 20:52:36 +02:00
|
|
|
'pk': otherDataIds
|
2015-08-12 13:34:41 +02:00
|
|
|
},
|
|
|
|
cors: {
|
|
|
|
expected: true,
|
|
|
|
sendCredentials: true
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
areAssetsDownloadable={true}
|
2015-12-08 18:22:11 +01:00
|
|
|
areAssetsEditable={editable}
|
|
|
|
multiple={multiple}
|
|
|
|
showErrorPrompt={showErrorPrompt} />
|
2015-08-12 13:34:41 +02:00
|
|
|
</Property>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-30 17:43:20 +01:00
|
|
|
export default FurtherDetailsFileuploader;
|