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

112 lines
3.8 KiB
JavaScript
Raw Normal View History

'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';
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
import { getLangText } from '../../utils/lang_utils';
import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils';
2015-09-11 10:11:07 +02:00
let CreateContractForm = React.createClass({
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
})
},
getInitialState() {
return {
2015-09-14 16:15:01 +02:00
isUploadReady: false,
contractName: ''
};
},
setIsUploadReady(isReady) {
this.setState({
isUploadReady: isReady
});
},
2015-09-02 16:34:43 +02:00
handleCreateSuccess(response) {
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);
this.refs.form.reset();
2015-09-02 16:34:43 +02:00
},
submitFile({ originalName }) {
2015-09-14 16:15:01 +02:00
this.setState({
contractName: originalName
2015-09-14 16:15:01 +02:00
});
this.refs.form.submit();
},
2015-09-02 16:34:43 +02:00
render() {
return (
<Form
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}>
<Property
2015-09-11 10:11:07 +02:00
name="blob"
label={getLangText('Contract file (*.pdf only, max. 50MB per contract)')}>
2015-09-11 10:11:07 +02:00
<InputFineUploader
submitFile={this.submitFile}
keyRoutine={{
url: AppConstants.serverUrl + 's3/key/',
fileClass: 'contract'
}}
createBlobRoutine={{
url: ApiUrls.blob_contracts
}}
validation={{
itemLimit: AppConstants.fineUploader.validation.additionalData.itemLimit,
sizeLimit: AppConstants.fineUploader.validation.additionalData.sizeLimit,
2015-09-14 16:15:01 +02:00
allowedExtensions: ['pdf']
}}
areAssetsDownloadable={true}
areAssetsEditable={true}
setIsUploadReady={this.setIsUploadReady}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
fileClassToUpload={this.props.fileClassToUpload} />
</Property>
<Property
2015-09-02 16:34:43 +02:00
name='name'
2015-09-14 16:15:01 +02:00
label={getLangText('Contract name')}
expanded={false}>
<input
type="text"
2015-09-14 16:15:01 +02:00
value={this.state.contractName}/>
2015-09-01 16:57:12 +02:00
</Property>
<Property
name="is_public"
expanded={false}>
<input
type="checkbox"
value={this.props.isPublic} />
</Property>
</Form>
);
}
});
export default CreateContractForm;