diff --git a/js/components/ascribe_buttons/upload_file_button.js b/js/components/ascribe_buttons/upload_file_button.js index 7f76f2ef..1f576064 100644 --- a/js/components/ascribe_buttons/upload_file_button.js +++ b/js/components/ascribe_buttons/upload_file_button.js @@ -2,6 +2,8 @@ import React from 'react'; +import Glyphicon from 'react-bootstrap/lib/Glyphicon'; + import ReactS3FineUploader from '../ascribe_uploader/react_s3_fine_uploader'; import UploadButton from '../ascribe_uploader/ascribe_upload_button/upload_button'; @@ -29,24 +31,41 @@ const UploadFileButton = React.createClass({ fileClassToUpload: shape({ singular: string, plural: string - }).isRequired + }).isRequired, + createBlobRoutine: shape({ + url: string, + pieceId: number + }) }, - submitFile(file) { - console.log(file); + getInitialState() { + return { + file: null + }; + }, + + handleSubmitFile(file) { + this.setState({ + file + }); + }, + + createBlobRoutine() { + const { fineuploader } = this.refs; + const { file } = this.state; + + fineuploader.createBlob(file); }, render() { - - const { fileClassToUpload, validation, keyRoutine } = this.props; + const { fileClassToUpload, validation, keyRoutine, createBlobRoutine } = this.props; return ( {/* So that ReactS3FineUploader is not complaining */}} signature={{ @@ -65,9 +84,9 @@ const UploadFileButton = React.createClass({ }} fileClassToUpload={fileClassToUpload} isReadyForFormSubmission={formSubmissionValidation.atLeastOneUploadedFile} - submitFile={this.submitFile} + submitFile={this.handleSubmitFile} location={this.props.location}/> - ); + ); } }); diff --git a/js/components/ascribe_uploader/ascribe_upload_button/upload_button.js b/js/components/ascribe_uploader/ascribe_upload_button/upload_button.js index 1547272e..5b08636c 100644 --- a/js/components/ascribe_uploader/ascribe_upload_button/upload_button.js +++ b/js/components/ascribe_uploader/ascribe_upload_button/upload_button.js @@ -2,8 +2,11 @@ import React from 'react'; +import Glyphicon from 'react-bootstrap/lib/Glyphicon'; + import { displayValidProgressFilesFilter } from '../react_s3_fine_uploader_utils'; import { getLangText } from '../../../utils/lang_utils'; +import { truncateTextAtCharIndex } from '../../../utils/general_utils'; let UploadButton = React.createClass({ @@ -37,6 +40,10 @@ let UploadButton = React.createClass({ return this.props.filesToUpload.filter((file) => file.status === 'uploading'); }, + getUploadedFile() { + return this.props.filesToUpload.filter((file) => file.status === 'upload successful')[0]; + }, + handleOnClick() { let uploadingFiles = this.getUploadingFiles(); @@ -57,14 +64,22 @@ let UploadButton = React.createClass({ }, getButtonLabel() { + const uploadedFile = this.getUploadedFile(); let { filesToUpload, fileClassToUpload } = this.props; // filter invalid files that might have been deleted or canceled... filesToUpload = filesToUpload.filter(displayValidProgressFilesFilter); - // Depending on wether there is an upload going on or not we - // display the progress - if(filesToUpload.length > 0) { + // Depending on whether there is an upload going on or not we + // display the progress or the successfully uploaded file's name + if(uploadedFile) { + return ( + + + {' ' + truncateTextAtCharIndex(uploadedFile.name, 20)} + + ); + } else if(filesToUpload.length > 0) { return getLangText('Upload progress') + ': ' + Math.ceil(filesToUpload[0].progress) + '%'; } else { return fileClassToUpload.singular; @@ -74,7 +89,6 @@ let UploadButton = React.createClass({ render() { let { multiple, - fileClassToUpload, allowedExtensions } = this.props; @@ -82,7 +96,7 @@ let UploadButton = React.createClass({