From c3b71b5398fab9841a9aefb4ab114f9499f19b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 10 Sep 2015 10:51:47 +0200 Subject: [PATCH] WIP: make fineuploader an input --- .../further_details_fileuploader.js | 2 +- js/components/ascribe_forms/form.js | 17 +-- .../ascribe_forms/form_register_piece.js | 105 +++--------------- .../ascribe_forms/input_fineuploader.js | 93 ++++++++++++++++ 4 files changed, 118 insertions(+), 99 deletions(-) create mode 100644 js/components/ascribe_forms/input_fineuploader.js diff --git a/js/components/ascribe_detail/further_details_fileuploader.js b/js/components/ascribe_detail/further_details_fileuploader.js index fa1df933..f03339a5 100644 --- a/js/components/ascribe_detail/further_details_fileuploader.js +++ b/js/components/ascribe_detail/further_details_fileuploader.js @@ -39,7 +39,7 @@ let FurtherDetailsFileuploader = React.createClass({ return null; } - let otherDataIds = this.props.otherData ? this.props.otherData.map((data)=>{return data.id; }).join() : null; + let otherDataIds = this.props.otherData ? this.props.otherData.map((data) => data.id).join() : null; return ( { + return ReactAddons.Children.map(this.props.children, (child, i) => { if (child) { return ReactAddons.addons.cloneWithProps(child, { handleChange: this.handleChangeChild, @@ -251,6 +253,7 @@ let Form = React.createClass({ role="form" className={className} onSubmit={this.submit} + onReset={this.reset} autoComplete={this.props.autoComplete}> {this.getFakeAutocompletableInputs()} {this.getErrors()} diff --git a/js/components/ascribe_forms/form_register_piece.js b/js/components/ascribe_forms/form_register_piece.js index 3519c976..e9b3df57 100644 --- a/js/components/ascribe_forms/form_register_piece.js +++ b/js/components/ascribe_forms/form_register_piece.js @@ -7,13 +7,10 @@ import UserActions from '../../actions/user_actions'; import Form from './form'; import Property from './property'; +import InputFineUploader from './input_fineuploader'; -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'; import { getLangText } from '../../utils/lang_utils'; import { mergeOptions } from '../../utils/general_utils'; import { isReadyForFormSubmission } from '../ascribe_uploader/react_s3_fine_uploader_utils'; @@ -45,7 +42,6 @@ let RegisterPieceForm = React.createClass({ getInitialState(){ return mergeOptions( { - digitalWorkKey: null, isUploadReady: false }, UserStore.getState() @@ -65,18 +61,6 @@ let RegisterPieceForm = React.createClass({ this.setState(state); }, - getFormData(){ - return { - digital_work_key: this.state.digitalWorkKey - }; - }, - - submitKey(key){ - this.setState({ - digitalWorkKey: key - }); - }, - setIsUploadReady(isReady) { this.setState({ isUploadReady: isReady @@ -94,14 +78,22 @@ let RegisterPieceForm = React.createClass({ className="ascribe-form-bordered" ref='form' url={ApiUrls.pieces_list} - getFormData={this.getFormData} handleSuccess={this.props.handleSuccess} - buttons={} + + + + } spinner={ @@ -111,9 +103,9 @@ let RegisterPieceForm = React.createClass({

{this.props.headerMessage}

- - ); - } -}); - export default RegisterPieceForm; diff --git a/js/components/ascribe_forms/input_fineuploader.js b/js/components/ascribe_forms/input_fineuploader.js new file mode 100644 index 00000000..2867b46e --- /dev/null +++ b/js/components/ascribe_forms/input_fineuploader.js @@ -0,0 +1,93 @@ +'use strict'; + +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'; + +let InputFileUploader = React.createClass({ + propTypes: { + setIsUploadReady: React.PropTypes.func, + isReadyForFormSubmission: React.PropTypes.func, + onClick: React.PropTypes.func, + + // isFineUploaderActive is used to lock react fine uploader in case + // a user is actually not logged in already to prevent him from droping files + // before login in + isFineUploaderActive: React.PropTypes.bool, + onLoggedOut: React.PropTypes.func, + editable: React.PropTypes.bool, + enableLocalHashing: React.PropTypes.bool, + + // provided by Property + disabled: React.PropTypes.bool + }, + + getInitialState() { + return { + value: null + + }; + }, + + submitKey(key){ + this.setState({ + value: key + }); + }, + + render() { + + let editable = this.props.isFineUploaderActive; + + // if disabled is actually set by property, we want to override + // isFineUploaderActive + if(typeof this.props.disabled !== 'undefined') { + editable = !this.props.disabled; + } + + + return ( + + ); + } +}); + +export default InputFileUploader; \ No newline at end of file