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

View File

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

View File

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