2015-09-15 11:50:23 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
2015-09-15 16:35:45 +02: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';
|
|
|
|
|
2015-09-16 09:47:22 +02:00
|
|
|
import ContractListActions from '../../actions/contract_list_actions';
|
|
|
|
|
|
|
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
|
|
|
|
2015-09-15 16:35:45 +02:00
|
|
|
import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils';
|
|
|
|
import { getCookie } from '../../utils/fetch_api_utils';
|
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
|
|
|
|
2015-09-15 11:50:23 +02:00
|
|
|
|
|
|
|
let ContractSettingsUpdateButton = React.createClass({
|
2015-09-16 09:47:22 +02:00
|
|
|
propTypes: {
|
2015-10-30 17:43:20 +01:00
|
|
|
contract: React.PropTypes.object
|
2015-09-15 16:35:45 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
submitFile(file) {
|
2015-09-16 09:47:22 +02:00
|
|
|
let contract = this.props.contract;
|
|
|
|
|
|
|
|
// override the blob with the key's value
|
|
|
|
contract.blob = file.key;
|
|
|
|
|
|
|
|
// send it to the server
|
|
|
|
ContractListActions
|
|
|
|
.changeContract(contract)
|
|
|
|
.then((res) => {
|
2015-09-16 14:07:55 +02:00
|
|
|
|
|
|
|
// Display feedback to the user
|
2015-09-16 09:47:22 +02:00
|
|
|
let notification = new GlobalNotificationModel(getLangText('Contract %s successfully updated', res.name), 'success', 5000);
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
|
2015-09-16 14:07:55 +02:00
|
|
|
// and refresh the contract list to get the updated contracs
|
2015-09-16 09:47:22 +02:00
|
|
|
return ContractListActions.fetchContractList(true);
|
|
|
|
})
|
|
|
|
.then(() => {
|
2015-09-16 14:07:55 +02:00
|
|
|
// Also, reset the fineuploader component so that the user can again 'update' his contract
|
2015-09-16 09:47:22 +02:00
|
|
|
this.refs.fineuploader.reset();
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.logGlobal(err);
|
|
|
|
let notification = new GlobalNotificationModel(getLangText('Contract could not be updated'), 'success', 5000);
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
});
|
2015-09-15 16:35:45 +02:00
|
|
|
},
|
|
|
|
|
2015-09-15 11:50:23 +02:00
|
|
|
render() {
|
|
|
|
return (
|
2015-09-15 16:35:45 +02:00
|
|
|
<ReactS3FineUploader
|
2015-09-16 09:47:22 +02:00
|
|
|
ref="fineuploader"
|
2015-09-15 16:35:45 +02:00
|
|
|
fileInputElement={UploadButton}
|
|
|
|
keyRoutine={{
|
|
|
|
url: AppConstants.serverUrl + 's3/key/',
|
|
|
|
fileClass: 'contract'
|
|
|
|
}}
|
|
|
|
createBlobRoutine={{
|
|
|
|
url: ApiUrls.blob_contracts
|
|
|
|
}}
|
|
|
|
validation={{
|
2015-09-16 15:14:08 +02:00
|
|
|
itemLimit: AppConstants.fineUploader.validation.registerWork.itemLimit,
|
|
|
|
sizeLimit: AppConstants.fineUploader.validation.additionalData.sizeLimit,
|
2015-09-15 16:35:45 +02:00
|
|
|
allowedExtensions: ['pdf']
|
|
|
|
}}
|
2015-09-16 09:47:22 +02:00
|
|
|
setIsUploadReady={() =>{/* So that ReactS3FineUploader is not complaining */}}
|
2015-09-15 16:35:45 +02:00
|
|
|
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={{
|
|
|
|
singular: getLangText('UPDATE'),
|
|
|
|
plural: getLangText('UPDATE')
|
|
|
|
}}
|
|
|
|
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
|
2015-10-30 17:43:20 +01:00
|
|
|
submitFile={this.submitFile} />
|
2015-09-15 11:50:23 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-30 17:43:20 +01:00
|
|
|
export default ContractSettingsUpdateButton;
|