1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 01:25:17 +01:00

refactor contract creation form

This commit is contained in:
Tim Daubenschütz 2015-09-11 10:11:07 +02:00
parent 535b2904b6
commit c8ece4c532
3 changed files with 35 additions and 51 deletions

View File

@ -11,38 +11,23 @@ import GlobalNotificationActions from '../../actions/global_notification_actions
import ContractListActions from '../../actions/contract_list_actions';
import ReactS3FineUploader from '../ascribe_uploader/react_s3_fine_uploader';
import AppConstants from '../../constants/application_constants';
import ApiUrls from '../../constants/api_urls';
import InputFineUploader from './input_fineuploader';
import { getLangText } from '../../utils/lang_utils';
import { getCookie } from '../../utils/fetch_api_utils';
import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils';
let CreateContractForm = React.createClass({
getInitialState() {
return {
contractKey: null,
isUploadReady: false
};
},
getFormData(){
return {
blob: this.state.contractKey
};
},
submitKey(key) {
this.setState({
contractKey: key
});
},
setIsUploadReady(isReady) {
this.setState({
isUploadReady: isReady
@ -62,7 +47,6 @@ let CreateContractForm = React.createClass({
<Form
ref='form'
url={ApiUrls.ownership_contract_list}
getFormData={this.getFormData}
handleSuccess={this.handleCreateSuccess}
buttons={
<button
@ -78,9 +62,9 @@ let CreateContractForm = React.createClass({
</span>
}>
<Property
name="blob"
label="Contract file">
<ReactS3FineUploader
ref='uploader'
<InputFineUploader
keyRoutine={{
url: AppConstants.serverUrl + 's3/key/',
fileClass: 'contract'
@ -92,32 +76,18 @@ let CreateContractForm = React.createClass({
itemLimit: 100000,
sizeLimit: '50000000'
}}
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}
areAssetsEditable={true}
submitKey={this.submitKey}
setIsUploadReady={this.setIsUploadReady}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}/>
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile} />
</Property>
<Property
name='name'
label={getLangText('Contract name')}>
<input
type="text"
placeholder="(e.g. Contract - Loan agreement #1)"
placeholder={getLangText('(e.g. Contract - Loan agreement #1)')}
required/>
</Property>
<Property
@ -126,7 +96,7 @@ let CreateContractForm = React.createClass({
style={{paddingBottom: 0}}>
<InputCheckbox>
<span>
Make contract public (this will replace the current public contract)
{getLangText('Make contract public (this will replace the current public contract')}
</span>
</InputCheckbox>
</Property>

View File

@ -10,10 +10,11 @@ import Property from './property';
import InputFineUploader from './input_fineuploader';
import ApiUrls from '../../constants/api_urls';
import AppConstants from '../../constants/application_constants';
import { getLangText } from '../../utils/lang_utils';
import { mergeOptions } from '../../utils/general_utils';
import { isReadyForFormSubmission } from '../ascribe_uploader/react_s3_fine_uploader_utils';
import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uploader_utils';
let RegisterPieceForm = React.createClass({
@ -99,8 +100,19 @@ let RegisterPieceForm = React.createClass({
name="digital_work_key"
ignoreFocus={true}>
<InputFineUploader
keyRoutine={{
url: AppConstants.serverUrl + 's3/key/',
fileClass: 'digitalwork'
}}
createBlobRoutine={{
url: ApiUrls.blob_digitalworks
}}
validation={{
itemLimit: 100000,
sizeLimit: '25000000000'
}}
setIsUploadReady={this.setIsUploadReady}
isReadyForFormSubmission={isReadyForFormSubmission}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
isFineUploaderActive={this.props.isFineUploaderActive}
onLoggedOut={this.props.onLoggedOut}
editable={this.props.isFineUploaderEditable}

View File

@ -5,7 +5,6 @@ import React from 'react';
import ReactS3FineUploader from '../ascribe_uploader/react_s3_fine_uploader';
import AppConstants from '../../constants/application_constants';
import ApiUrls from '../../constants/api_urls';
import { getCookie } from '../../utils/fetch_api_utils';
@ -14,6 +13,17 @@ let InputFileUploader = React.createClass({
setIsUploadReady: React.PropTypes.func,
isReadyForFormSubmission: React.PropTypes.func,
onClick: React.PropTypes.func,
keyRoutine: React.PropTypes.shape({
url: React.PropTypes.string,
fileClass: React.PropTypes.string
}),
createBlobRoutine: React.PropTypes.shape({
url: React.PropTypes.string
}),
validation: React.PropTypes.shape({
itemLimit: React.PropTypes.number,
sizeLimit: React.PropTypes.string
}),
// isFineUploaderActive is used to lock react fine uploader in case
// a user is actually not logged in already to prevent him from droping files
@ -56,18 +66,10 @@ let InputFileUploader = React.createClass({
<ReactS3FineUploader
ref="fineuploader"
onClick={this.props.onClick}
keyRoutine={{
url: AppConstants.serverUrl + 's3/key/',
fileClass: 'digitalwork'
}}
createBlobRoutine={{
url: ApiUrls.blob_digitalworks
}}
keyRoutine={this.props.keyRoutine}
createBlobRoutine={this.props.createBlobRoutine}
validation={this.props.validation}
submitKey={this.submitKey}
validation={{
itemLimit: 100000,
sizeLimit: '25000000000'
}}
setIsUploadReady={this.props.setIsUploadReady}
isReadyForFormSubmission={this.props.isReadyForFormSubmission}
areAssetsDownloadable={false}