1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

extend fileClassToUpload functionality and implement it in contract settings

This commit is contained in:
Tim Daubenschütz 2015-09-14 17:02:47 +02:00
parent d47ead1bff
commit 209d141939
4 changed files with 42 additions and 16 deletions

View File

@ -4,7 +4,6 @@ import React from 'react';
import Form from '../ascribe_forms/form'; import Form from '../ascribe_forms/form';
import Property from '../ascribe_forms/property'; import Property from '../ascribe_forms/property';
import InputCheckbox from '../ascribe_forms/input_checkbox';
import GlobalNotificationModel from '../../models/global_notification_model'; import GlobalNotificationModel from '../../models/global_notification_model';
import GlobalNotificationActions from '../../actions/global_notification_actions'; import GlobalNotificationActions from '../../actions/global_notification_actions';
@ -21,6 +20,16 @@ import { formSubmissionValidation } from '../ascribe_uploader/react_s3_fine_uplo
let CreateContractForm = React.createClass({ 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() { getInitialState() {
return { return {
@ -58,7 +67,7 @@ let CreateContractForm = React.createClass({
handleSuccess={this.handleCreateSuccess}> handleSuccess={this.handleCreateSuccess}>
<Property <Property
name="blob" name="blob"
label="Contract file (*.pdf)"> label="Contract file (*.pdf only)">
<InputFineUploader <InputFineUploader
submitFileName={this.submitFileName} submitFileName={this.submitFileName}
keyRoutine={{ keyRoutine={{
@ -78,10 +87,7 @@ let CreateContractForm = React.createClass({
submitFile={this.submitFile} submitFile={this.submitFile}
setIsUploadReady={this.setIsUploadReady} setIsUploadReady={this.setIsUploadReady}
isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile} isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile}
fileClassToUpload={{ fileClassToUpload={this.props.fileClassToUpload}/>
singular: 'contract',
plural: 'contracts'
}}/>
</Property> </Property>
<Property <Property
name='name' name='name'
@ -91,6 +97,13 @@ let CreateContractForm = React.createClass({
type="text" type="text"
value={this.state.contractName}/> value={this.state.contractName}/>
</Property> </Property>
<Property
name="is_public"
hidden={true}>
<input
type="checkbox"
value={this.props.isPublic} />
</Property>
</Form> </Form>
); );
} }

View File

@ -103,7 +103,7 @@ let InputFileUploader = React.createClass({
} }
}} }}
onInactive={this.props.onLoggedOut} onInactive={this.props.onLoggedOut}
enableLocalHashing={this.props.enableLocalHashing} enableLocalHashing={this.props.enableLocalHashing}
fileClassToUpload={this.props.fileClassToUpload}/> fileClassToUpload={this.props.fileClassToUpload}/>
); );
} }

View File

@ -80,6 +80,18 @@ let ContractSettings = React.createClass({
render() { render() {
let publicContracts = this.getPublicContracts(); let publicContracts = this.getPublicContracts();
let privateContracts = this.getPrivateContracts(); let privateContracts = this.getPrivateContracts();
let createPublicContractForm = null;
if(publicContracts.length === 0) {
createPublicContractForm = (
<CreateContractForm
isPublic={true}
fileClassToUpload={{
singular: 'new public contract',
plural: 'new public contracts'
}}/>
);
}
return ( return (
<CollapsibleParagraph <CollapsibleParagraph
@ -94,6 +106,7 @@ let ContractSettings = React.createClass({
title={getLangText('Public Contracts')} title={getLangText('Public Contracts')}
show={true} show={true}
defaultExpanded={true}> defaultExpanded={true}>
{createPublicContractForm}
{publicContracts.map((contract, i) => { {publicContracts.map((contract, i) => {
return ( return (
<ActionPanel <ActionPanel
@ -109,7 +122,7 @@ let ContractSettings = React.createClass({
className="btn btn-default btn-sm margin-left-2px" className="btn btn-default btn-sm margin-left-2px"
href={contract.blob.url_safe} href={contract.blob.url_safe}
target="_blank"> target="_blank">
DOWNLOAD PREVIEW
</a> </a>
<button <button
className="btn btn-default btn-sm margin-left-2px" className="btn btn-default btn-sm margin-left-2px"
@ -127,6 +140,12 @@ let ContractSettings = React.createClass({
title={getLangText('Private Contracts')} title={getLangText('Private Contracts')}
show={true} show={true}
defaultExpanded={true}> defaultExpanded={true}>
<CreateContractForm
isPublic={false}
fileClassToUpload={{
singular: 'new private contract',
plural: 'new private contracts'
}}/>
{privateContracts.map((contract, i) => { {privateContracts.map((contract, i) => {
return ( return (
<ActionPanel <ActionPanel
@ -147,7 +166,7 @@ let ContractSettings = React.createClass({
className="btn btn-default btn-sm margin-left-2px" className="btn btn-default btn-sm margin-left-2px"
href={contract.blob.url_safe} href={contract.blob.url_safe}
target="_blank"> target="_blank">
DOWNLOAD PREVIEW
</a> </a>
<button <button
className="btn btn-default btn-sm margin-left-2px" className="btn btn-default btn-sm margin-left-2px"
@ -162,12 +181,6 @@ let ContractSettings = React.createClass({
})} })}
</CollapsibleParagraph> </CollapsibleParagraph>
</CollapsibleParagraph> </CollapsibleParagraph>
<CollapsibleParagraph
title={getLangText('Create Contract')}
show={true}
defaultExpanded={true}>
<CreateContractForm />
</CollapsibleParagraph>
</CollapsibleParagraph> </CollapsibleParagraph>
); );
} }

View File

@ -74,7 +74,7 @@ let FileDragAndDropDialog = React.createClass({
</span> </span>
); );
} else { } else {
let dialog = queryParams.method === 'hash' ? getLangText('choose a %s to hash', this.props.fileClassToUpload.singular) : getLangText('choose a file to upload'); let dialog = queryParams.method === 'hash' ? getLangText('choose a %s to hash', this.props.fileClassToUpload.singular) : getLangText('choose a %s to upload', this.props.fileClassToUpload.singular);
return ( return (
<span className="file-drag-and-drop-dialog"> <span className="file-drag-and-drop-dialog">