1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

Merge pull request #27 from ascribe/AD-812-cannot-reupload-video-without-refresh

Clear previously selected files from input element when upload fails
This commit is contained in:
Tim Daubenschütz 2015-11-16 16:24:28 +01:00
commit 2570890df2
3 changed files with 54 additions and 29 deletions

View File

@ -45,6 +45,10 @@ let FileDragAndDrop = React.createClass({
allowedExtensions: React.PropTypes.string allowedExtensions: React.PropTypes.string
}, },
clearSelection() {
this.refs.fileSelector.getDOMNode().value = '';
},
handleDragOver(event) { handleDragOver(event) {
event.preventDefault(); event.preventDefault();
@ -81,30 +85,30 @@ let FileDragAndDrop = React.createClass({
}, },
handleDeleteFile(fileId) { handleDeleteFile(fileId) {
// input's value is not change the second time someone // input's value is not changed the second time someone
// inputs the same file again, therefore we need to reset its value // inputs the same file again, therefore we need to reset its value
this.refs.fileinput.getDOMNode().value = ''; this.clearSelection();
this.props.handleDeleteFile(fileId); this.props.handleDeleteFile(fileId);
}, },
handleCancelFile(fileId) { handleCancelFile(fileId) {
// input's value is not change the second time someone // input's value is not changed the second time someone
// inputs the same file again, therefore we need to reset its value // inputs the same file again, therefore we need to reset its value
this.refs.fileinput.getDOMNode().value = ''; this.clearSelection();
this.props.handleCancelFile(fileId); this.props.handleCancelFile(fileId);
}, },
handlePauseFile(fileId) { handlePauseFile(fileId) {
// input's value is not change the second time someone // input's value is not changed the second time someone
// inputs the same file again, therefore we need to reset its value // inputs the same file again, therefore we need to reset its value
this.refs.fileinput.getDOMNode().value = ''; this.clearSelection();
this.props.handlePauseFile(fileId); this.props.handlePauseFile(fileId);
}, },
handleResumeFile(fileId) { handleResumeFile(fileId) {
// input's value is not change the second time someone // input's value is not changed the second time someone
// inputs the same file again, therefore we need to reset its value // inputs the same file again, therefore we need to reset its value
this.refs.fileinput.getDOMNode().value = ''; this.clearSelection();
this.props.handleResumeFile(fileId); this.props.handleResumeFile(fileId);
}, },
@ -133,7 +137,7 @@ let FileDragAndDrop = React.createClass({
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null); evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
} }
this.refs.fileinput.getDOMNode().dispatchEvent(evt); this.refs.fileSelector.getDOMNode().dispatchEvent(evt);
}, },
render: function () { render: function () {
@ -206,7 +210,7 @@ let FileDragAndDrop = React.createClass({
*/} */}
<input <input
multiple={multiple} multiple={multiple}
ref="fileinput" ref="fileSelector"
type="file" type="file"
style={{ style={{
visibility: 'hidden', visibility: 'hidden',

View File

@ -259,7 +259,7 @@ let ReactS3FineUploader = React.createClass({
// Resets the whole react fineuploader component to its initial state // Resets the whole react fineuploader component to its initial state
reset() { reset() {
// Cancel all currently ongoing uploads // Cancel all currently ongoing uploads
this.state.uploader.cancelAll(); this.cancelUploads();
// and reset component in general // and reset component in general
this.state.uploader.reset(); this.state.uploader.reset();
@ -271,6 +271,22 @@ let ReactS3FineUploader = React.createClass({
this.setState(this.getInitialState()); this.setState(this.getInitialState());
}, },
// Cancel uploads and clear previously selected files on the input element
cancelUploads(id) {
!!id ? this.state.uploader.cancel(id) : this.state.uploader.cancelAll();
// Reset the file input element to clear the previously selected files so that
// the user can reselect them again.
this.clearFileSelection();
},
clearFileSelection() {
const { fileInput } = this.refs;
if (fileInput && typeof fileInput.clearSelection === 'function') {
fileInput.clearSelection();
}
},
requestKey(fileId) { requestKey(fileId) {
let filename = this.state.uploader.getName(fileId); let filename = this.state.uploader.getName(fileId);
let uuid = this.state.uploader.getUuid(fileId); let uuid = this.state.uploader.getUuid(fileId);
@ -456,8 +472,9 @@ let ReactS3FineUploader = React.createClass({
files: this.state.filesToUpload, files: this.state.filesToUpload,
chunks: this.state.chunks chunks: this.state.chunks
}); });
this.props.setIsUploadReady(true); this.props.setIsUploadReady(true);
this.state.uploader.cancelAll(); this.cancelUploads();
let notification = new GlobalNotificationModel(errorReason || this.props.defaultErrorMessage, 'danger', 5000); let notification = new GlobalNotificationModel(errorReason || this.props.defaultErrorMessage, 'danger', 5000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
@ -600,7 +617,7 @@ let ReactS3FineUploader = React.createClass({
}, },
handleCancelFile(fileId) { handleCancelFile(fileId) {
this.state.uploader.cancel(fileId); this.cancelUploads(fileId);
}, },
handlePauseFile(fileId) { handlePauseFile(fileId) {
@ -627,6 +644,7 @@ let ReactS3FineUploader = React.createClass({
// If multiple set and user already uploaded its work, // If multiple set and user already uploaded its work,
// cancel upload // cancel upload
if(!this.props.multiple && this.state.filesToUpload.filter(displayValidFilesFilter).length > 0) { if(!this.props.multiple && this.state.filesToUpload.filter(displayValidFilesFilter).length > 0) {
this.clearFileSelection();
return; return;
} }
@ -856,19 +874,16 @@ let ReactS3FineUploader = React.createClass({
render() { render() {
const { const {
multiple, multiple,
areAssetsDownloadable, areAssetsDownloadable,
areAssetsEditable, areAssetsEditable,
onInactive, onInactive,
enableLocalHashing, enableLocalHashing,
uploadMethod, fileClassToUpload,
fileClassToUpload, fileInputElement: FileInputElement,
validation, uploadMethod } = this.props;
fileInputElement } = this.props;
// Here we initialize the template that has been either provided from the outside const props = {
// or the default input that is FileDragAndDrop.
return React.createElement(fileInputElement, {
multiple, multiple,
areAssetsDownloadable, areAssetsDownloadable,
areAssetsEditable, areAssetsEditable,
@ -886,10 +901,14 @@ let ReactS3FineUploader = React.createClass({
dropzoneInactive: this.isDropzoneInactive(), dropzoneInactive: this.isDropzoneInactive(),
hashingProgress: this.state.hashingProgress, hashingProgress: this.state.hashingProgress,
allowedExtensions: this.getAllowedExtensions() allowedExtensions: this.getAllowedExtensions()
}); };
}
return (
<FileInputElement
ref="fileInput"
{...props} />
);
}
}); });
export default ReactS3FineUploader; export default ReactS3FineUploader;

View File

@ -4399,7 +4399,9 @@ qq.UploadHandlerController = function(o, namespace) {
} }
) )
.done(function() { .done(function() {
handler.clearXhr(id, chunkIdx); if (handler._getFileState(id)) {
handler.clearXhr(id, chunkIdx);
}
}) ; }) ;
} }
} }