From 845f8c9cd363ec3f960cc9e67e62835fc4960bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 25 Jun 2015 11:12:40 +0200 Subject: [PATCH] fix issues related to multiple files upload --- .../ascribe_uploader/file_drag_and_drop.js | 20 +++++++++++--- .../react_s3_fine_uploader.js | 26 ++++++++++++++++++- sass/ascribe_uploader.scss | 8 ++++++ 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/js/components/ascribe_uploader/file_drag_and_drop.js b/js/components/ascribe_uploader/file_drag_and_drop.js index 2fb9f78f..126dd656 100644 --- a/js/components/ascribe_uploader/file_drag_and_drop.js +++ b/js/components/ascribe_uploader/file_drag_and_drop.js @@ -1,3 +1,5 @@ +'use strict'; + import React from 'react'; import FileDragAndDropPreviewIterator from './file_drag_and_drop_preview_iterator'; @@ -7,13 +9,16 @@ var FileDragAndDrop = React.createClass({ propTypes: { onDragStart: React.PropTypes.func, onDrop: React.PropTypes.func.isRequired, + onDrag: React.PropTypes.func, onDragEnter: React.PropTypes.func, onLeave: React.PropTypes.func, + onDragLeave: React.PropTypes.func, onDragOver: React.PropTypes.func, onDragEnd: React.PropTypes.func, filesToUpload: React.PropTypes.array, handleDeleteFile: React.PropTypes.func, - multiple: React.PropTypes.bool + multiple: React.PropTypes.bool, + dropzoneInactive: React.PropTypes.bool }, handleDragStart(event) { @@ -81,6 +86,12 @@ var FileDragAndDrop = React.createClass({ }, handleOnClick() { + // when multiple is set to false and the user already uploaded a piece, + // do not propagate event + if(this.props.dropzoneInactive) { + return; + } + // Simulate click on hidden file input var event = document.createEvent('HTMLEvents'); event.initEvent('click', false, true); @@ -88,11 +99,14 @@ var FileDragAndDrop = React.createClass({ }, render: function () { + console.log(this.props.dropzoneInactive); let hasFiles = this.props.filesToUpload.length > 0; + let className = hasFiles ? 'file-drag-and-drop has-files ' : 'file-drag-and-drop '; + className += this.props.dropzoneInactive ? 'inactive-dropzone' : 'active-dropzone'; return (
0) { + return; + } + + // if multiple is set to false and user drops multiple files into the dropzone, + // take the first one and notify user that only one file can be submitted + if(!this.props.multiple && files.length > 1) { + let tempFilesList = []; + tempFilesList.push(files[0]); + + // replace filelist with first-element file list + files = tempFilesList; + + let notification = new GlobalNotificationModel('Only one file allowed (took first one)', 'danger', 10000); + GlobalNotificationActions.appendGlobalNotification(notification); + } + this.state.uploader.addFiles(files); let oldFiles = this.state.filesToUpload; let oldAndNewFiles = this.state.uploader.getUploads(); @@ -297,7 +320,8 @@ var ReactS3FineUploader = React.createClass({ onDrop={this.handleUploadFile} filesToUpload={this.state.filesToUpload} handleDeleteFile={this.handleDeleteFile} - multiple={this.props.multiple}/> + multiple={this.props.multiple} + dropzoneInactive={!this.props.multiple && this.state.filesToUpload.length > 0} /> ); } diff --git a/sass/ascribe_uploader.scss b/sass/ascribe_uploader.scss index e6583313..487aa1b0 100644 --- a/sass/ascribe_uploader.scss +++ b/sass/ascribe_uploader.scss @@ -10,6 +10,14 @@ transition: .1s linear background-color; } +.inactive-dropzone { + cursor: default !important; +} + +.inactive-dropzone:hover { + background-color: #FAFAFA !important; +} + .file-drag-and-drop:hover { background-color: rgba(72, 218, 203, 0.2); }