From 14621b5b388532e447511b277aed93102e37132a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 17 Nov 2015 11:22:24 +0100 Subject: [PATCH] Generalize UploadButton styling --- .../ascribe_forms/form_register_piece.js | 2 +- .../contract_settings_update_button.js | 2 +- .../ascribe_upload_button/upload_button.js | 217 +++++++++--------- .../pr_forms/pr_register_piece_form.js | 8 +- 4 files changed, 116 insertions(+), 113 deletions(-) diff --git a/js/components/ascribe_forms/form_register_piece.js b/js/components/ascribe_forms/form_register_piece.js index da19ea96..37712c16 100644 --- a/js/components/ascribe_forms/form_register_piece.js +++ b/js/components/ascribe_forms/form_register_piece.js @@ -145,7 +145,7 @@ let RegisterPieceForm = React.createClass({ file.status === 'uploading'); - }, + if(typeof this.props.onDrop === 'function' && files) { + this.props.onDrop(files); + } - getUploadedFile() { - return this.props.filesToUpload.filter((file) => file.status === 'upload successful')[0]; - }, + }, - handleOnClick() { - const uploadingFiles = this.getUploadingFiles(); - const uploadedFile = this.getUploadedFile(); + getUploadingFiles() { + return this.props.filesToUpload.filter((file) => file.status === 'uploading'); + }, - if(uploadedFile) { - this.props.handleCancelFile(uploadedFile.id); - } - if(uploadingFiles.length === 0) { - // We only want the button to be clickable if there are no files currently uploading + getUploadedFile() { + return this.props.filesToUpload.filter((file) => file.status === 'upload successful')[0]; + }, - // Firefox only recognizes the simulated mouse click if bubbles is set to true, - // but since Google Chrome propagates the event much further than needed, we - // need to stop propagation as soon as the event is created - var evt = new MouseEvent('click', { - view: window, - bubbles: true, - cancelable: true - }); + handleOnClick() { + const uploadingFiles = this.getUploadingFiles(); + const uploadedFile = this.getUploadedFile(); - evt.stopPropagation(); - this.refs.fileinput.getDOMNode().dispatchEvent(evt); - } - }, + if(uploadedFile) { + this.props.handleCancelFile(uploadedFile.id); + } + if(uploadingFiles.length === 0) { + // We only want the button to be clickable if there are no files currently uploading - getButtonLabel() { - let { filesToUpload, fileClassToUpload } = this.props; + // Firefox only recognizes the simulated mouse click if bubbles is set to true, + // but since Google Chrome propagates the event much further than needed, we + // need to stop propagation as soon as the event is created + var evt = new MouseEvent('click', { + view: window, + bubbles: true, + cancelable: true + }); - // filter invalid files that might have been deleted or canceled... - filesToUpload = filesToUpload.filter(displayValidProgressFilesFilter); + evt.stopPropagation(); + this.refs.fileinput.getDOMNode().dispatchEvent(evt); + } + }, - if(this.getUploadingFiles().length !== 0) { - return getLangText('Upload progress') + ': ' + Math.ceil(filesToUpload[0].progress) + '%'; - } else { - return fileClassToUpload.singular; - } - }, + getButtonLabel() { + let { filesToUpload, fileClassToUpload } = this.props; - getUploadedFileLabel() { - const uploadedFile = this.getUploadedFile(); + // filter invalid files that might have been deleted or canceled... + filesToUpload = filesToUpload.filter(displayValidProgressFilesFilter); - if(uploadedFile) { + if(this.getUploadingFiles().length !== 0) { + return getLangText('Upload progress') + ': ' + Math.ceil(filesToUpload[0].progress) + '%'; + } else { + return fileClassToUpload.singular; + } + }, + + getUploadedFileLabel() { + const uploadedFile = this.getUploadedFile(); + + if(uploadedFile) { + return ( + + + {' ' + truncateTextAtCharIndex(uploadedFile.name, 40)} + + ); + } else { + return ( + {getLangText('No file chosen')} + ); + } + }, + + render() { + let { multiple, + allowedExtensions } = this.props; + + /* + * We do not want a button that submits here. + * As UploadButton could be used in forms that want to be submitted independent + * of clicking the selector. + * Therefore the wrapping component needs to be an `anchor` tag instead of a `button` + */ return ( - - - {' ' + truncateTextAtCharIndex(uploadedFile.name, 40)} - - ); - } else { - return ( - {getLangText('No file chosen')} +
+ + {this.getButtonLabel()} + + + {this.getUploadedFileLabel()} +
); } - }, - - render() { - let { multiple, - allowedExtensions } = this.props; - - /* - * We do not want a button that submits here. - * As UploadButton could be used in forms that want to be submitted independent - * of clicking the selector. - * Therefore the wrapping component needs to be an `anchor` tag instead of a `button` - */ - return ( -
- - {this.getButtonLabel()} - - - {this.getUploadedFileLabel()} -
- ); - } -}); - -export default UploadButton; \ No newline at end of file + }); +} \ No newline at end of file diff --git a/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js b/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js index 0c293b15..41f2c25a 100644 --- a/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js +++ b/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js @@ -253,7 +253,7 @@ const PRRegisterPieceForm = React.createClass({ name="digitalWorkKey" label={getLangText('Select the PDF with your work')}>