From ad8be7e34aa01a10b3ad996ac79ff844bf256de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 18 Aug 2015 13:15:22 +0200 Subject: [PATCH] separate pre-sending form submission functionality --- js/components/ascribe_detail/further_details.js | 13 +++---------- .../ascribe_forms/form_register_piece.js | 13 +++---------- .../ascribe_slides_container/slides_container.js | 5 ++++- .../ascribe_uploader/react_s3_fine_uploader.js | 2 +- .../react_s3_fine_uploader_utils.js | 16 ++++++++++++++++ .../ascribe_forms/cyland_additional_data_form.js | 12 ++++++++++-- 6 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 js/components/ascribe_uploader/react_s3_fine_uploader_utils.js diff --git a/js/components/ascribe_detail/further_details.js b/js/components/ascribe_detail/further_details.js index 57c6ebe1..36e79811 100644 --- a/js/components/ascribe_detail/further_details.js +++ b/js/components/ascribe_detail/further_details.js @@ -15,6 +15,8 @@ import GlobalNotificationActions from '../../actions/global_notification_actions import FurtherDetailsFileuploader from './further_details_fileuploader'; +import { isReadyForFormSubmission } from '../ascribe_uploader/react_s3_fine_uploader_utils'; + let FurtherDetails = React.createClass({ propTypes: { editable: React.PropTypes.bool, @@ -48,15 +50,6 @@ let FurtherDetails = React.createClass({ }); }, - isReadyForFormSubmission(files) { - files = files.filter((file) => file.status !== 'deleted' && file.status !== 'canceled'); - if(files.length > 0 && files[0].status === 'upload successful') { - return true; - } else { - return false; - } - }, - render() { //return (); return ( @@ -88,7 +81,7 @@ let FurtherDetails = React.createClass({ file.status !== 'deleted' && file.status !== 'canceled'); - if (files.length > 0 && files[0].status === 'upload successful') { - return true; - } else { - return false; - } - }, - render() { let currentUser = this.state.currentUser; let enableLocalHashing = currentUser && currentUser.profile ? currentUser.profile.hash_locally : false; @@ -117,7 +110,7 @@ let RegisterPieceForm = React.createClass({ {this.props.breadcrumbs.map((breadcrumb, i) => { return ( - +
{this.props.breadcrumbs[i]} diff --git a/js/components/ascribe_uploader/react_s3_fine_uploader.js b/js/components/ascribe_uploader/react_s3_fine_uploader.js index 7780ceae..90c76667 100644 --- a/js/components/ascribe_uploader/react_s3_fine_uploader.js +++ b/js/components/ascribe_uploader/react_s3_fine_uploader.js @@ -160,7 +160,7 @@ var ReactS3FineUploader = React.createClass({ } return name; }, - multiple: true, + multiple: false, defaultErrorMessage: getLangText('Unexpected error. Please contact us if this happens repeatedly.') }; }, diff --git a/js/components/ascribe_uploader/react_s3_fine_uploader_utils.js b/js/components/ascribe_uploader/react_s3_fine_uploader_utils.js new file mode 100644 index 00000000..dbf62619 --- /dev/null +++ b/js/components/ascribe_uploader/react_s3_fine_uploader_utils.js @@ -0,0 +1,16 @@ +'use strict'; + +/** + * Returns a boolean if there has been at least one file uploaded + * successfully without it being deleted or canceled. + * @param {array of files} files provided by react fine uploader + * @return {Boolean} + */ +export function isReadyForFormSubmission(files) { + files = files.filter((file) => file.status !== 'deleted' && file.status !== 'canceled'); + if (files.length > 0 && files[0].status === 'upload successful') { + return true; + } else { + return false; + } +} \ No newline at end of file diff --git a/js/components/whitelabel/wallet/components/cyland/ascribe_forms/cyland_additional_data_form.js b/js/components/whitelabel/wallet/components/cyland/ascribe_forms/cyland_additional_data_form.js index 364360c8..cddabb0c 100644 --- a/js/components/whitelabel/wallet/components/cyland/ascribe_forms/cyland_additional_data_form.js +++ b/js/components/whitelabel/wallet/components/cyland/ascribe_forms/cyland_additional_data_form.js @@ -43,6 +43,7 @@ let CylandAdditionalDataForm = React.createClass({ extradata: extradata, piece_id: this.props.piece.id }; + }, setIsUploadReady(isReady) { @@ -51,8 +52,15 @@ let CylandAdditionalDataForm = React.createClass({ }); }, - isReadyForFormSubmission() { - return true; + isReadyForFormSubmission(files) { + let uploadedFiles = files.filter((file) => file.status === 'upload successful'); + let uploadingFiles = files.filter((file) => file.status === 'submitting'); + + if (uploadedFiles.length > 0 && uploadingFiles.length === 0) { + return true; + } else { + return false; + } }, render() {