2015-09-01 14:42:09 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import Form from '../ascribe_forms/form';
|
|
|
|
import Property from '../ascribe_forms/property';
|
|
|
|
|
2015-09-02 16:34:43 +02:00
|
|
|
import GlobalNotificationModel from '../../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
|
|
|
|
2015-09-08 11:53:09 +02:00
|
|
|
import ContractListActions from '../../actions/contract_list_actions';
|
2015-09-08 11:19:11 +02:00
|
|
|
|
2015-09-01 14:42:09 +02:00
|
|
|
import AppConstants from '../../constants/application_constants';
|
|
|
|
import ApiUrls from '../../constants/api_urls';
|
|
|
|
|
2015-09-11 10:11:07 +02:00
|
|
|
import InputFineUploader from './input_fineuploader';
|
2015-09-08 11:53:09 +02:00
|
|
|
|
2015-09-01 14:42:09 +02:00
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
|
|
|
import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils';
|
|
|
|
|
2015-09-11 10:11:07 +02:00
|
|
|
|
2015-09-01 14:42:09 +02:00
|
|
|
let CreateContractForm = React.createClass({
|
2015-09-14 17:02:47 +02:00
|
|
|
propTypes: {
|
|
|
|
isPublic: 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-10-30 17:43:20 +01:00
|
|
|
})
|
2015-09-14 17:02:47 +02:00
|
|
|
},
|
2015-09-01 14:42:09 +02:00
|
|
|
|
|
|
|
getInitialState() {
|
|
|
|
return {
|
2015-09-14 16:15:01 +02:00
|
|
|
isUploadReady: false,
|
|
|
|
contractName: ''
|
2015-09-01 14:42:09 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
setIsUploadReady(isReady) {
|
|
|
|
this.setState({
|
|
|
|
isUploadReady: isReady
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-09-02 16:34:43 +02:00
|
|
|
handleCreateSuccess(response) {
|
2015-09-15 17:18:38 +02:00
|
|
|
ContractListActions.fetchContractList(true);
|
2015-09-02 16:34:43 +02:00
|
|
|
let notification = new GlobalNotificationModel(getLangText('Contract %s successfully created', response.name), 'success', 5000);
|
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
2015-09-09 19:29:58 +02:00
|
|
|
this.refs.form.reset();
|
2015-09-02 16:34:43 +02:00
|
|
|
},
|
|
|
|
|
2015-09-14 16:15:01 +02:00
|
|
|
submitFileName(fileName) {
|
|
|
|
this.setState({
|
|
|
|
contractName: fileName
|
|
|
|
});
|
|
|
|
|
|
|
|
this.refs.form.submit();
|
|
|
|
},
|
2015-09-02 16:34:43 +02:00
|
|
|
|
2015-09-01 14:42:09 +02:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Form
|
2015-09-09 19:29:58 +02:00
|
|
|
ref='form'
|
2015-09-03 15:53:02 +02:00
|
|
|
url={ApiUrls.ownership_contract_list}
|
2015-09-14 16:15:01 +02:00
|
|
|
handleSuccess={this.handleCreateSuccess}>
|
2015-09-01 14:42:09 +02:00
|
|
|
<Property
|
2015-09-11 10:11:07 +02:00
|
|
|
name="blob"
|
2015-09-15 10:15:56 +02:00
|
|
|
label={getLangText('Contract file (*.pdf only, max. 50MB per contract)')}>
|
2015-09-11 10:11:07 +02:00
|
|
|
<InputFineUploader
|
2015-09-14 16:15:01 +02:00
|
|
|
submitFileName={this.submitFileName}
|
2015-09-01 14:42:09 +02:00
|
|
|
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.additionalData.itemLimit,
|
|
|
|
sizeLimit: AppConstants.fineUploader.validation.additionalData.sizeLimit,
|
2015-09-14 16:15:01 +02:00
|
|
|
allowedExtensions: ['pdf']
|
2015-09-01 14:42:09 +02:00
|
|
|
}}
|
|
|
|
areAssetsDownloadable={true}
|
|
|
|
areAssetsEditable={true}
|
|
|
|
setIsUploadReady={this.setIsUploadReady}
|
2015-09-14 16:33:32 +02:00
|
|
|
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
|
2015-10-30 17:43:20 +01:00
|
|
|
fileClassToUpload={this.props.fileClassToUpload} />
|
2015-09-01 14:42:09 +02:00
|
|
|
</Property>
|
|
|
|
<Property
|
2015-09-02 16:34:43 +02:00
|
|
|
name='name'
|
2015-09-14 16:15:01 +02:00
|
|
|
label={getLangText('Contract name')}
|
2015-12-03 20:26:53 +01:00
|
|
|
expanded={false}>
|
2015-09-01 14:42:09 +02:00
|
|
|
<input
|
|
|
|
type="text"
|
2015-09-14 16:15:01 +02:00
|
|
|
value={this.state.contractName}/>
|
2015-09-01 16:57:12 +02:00
|
|
|
</Property>
|
2015-09-14 17:02:47 +02:00
|
|
|
<Property
|
|
|
|
name="is_public"
|
2015-12-03 20:26:53 +01:00
|
|
|
expanded={false}>
|
2015-09-14 17:02:47 +02:00
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
value={this.props.isPublic} />
|
|
|
|
</Property>
|
2015-09-01 14:42:09 +02:00
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-30 17:43:20 +01:00
|
|
|
export default CreateContractForm;
|