From 495afb59adf47818215bb702a71ec5f79dfd4359 Mon Sep 17 00:00:00 2001 From: Stefan Aebischer Date: Wed, 20 Nov 2013 01:02:54 +0100 Subject: [PATCH] [BUGFIX] Improve confirmation dialog in drag'n'drop fileupload This patch introduces the following changes to the drag'n'drop fileuploader: * Only ask for confirmation to overwrite files, if at least one of the uploaded files will overwrite an existing file on the server * Display the files which will be overwritten in the confirmation dialog * If the user selects "Cancel", cancel the whole action, and don't upload any files. * If no files will be overwritten, just upload them without disturbing the user with a confirmation message. Resolves: #53776 Releases: 6.2 Change-Id: I415c2d31b5bf1248f8a865d225a81ddd96e47d78 Reviewed-on: https://review.typo3.org/25523 Reviewed-by: Wouter Wolters Tested-by: Wouter Wolters --- .../Public/JavaScript/DragUploader.js | 30 +++++++++++++++++-- typo3/sysext/filelist/Classes/FileList.php | 2 +- typo3/sysext/lang/locallang_core.xlf | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js b/typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js index 1f8a6c06d593..8c6e03155f80 100644 --- a/typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js +++ b/typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js @@ -33,6 +33,7 @@ define('TYPO3/CMS/Backend/DragUploader', ['jquery'], function($) { me.$progress = $('
').addClass('DragUpload-ProgressInformation').hide().appendTo(me.$body); me.uploadCompletedCount = 0; me.fileQueue = []; + me.filesOnServer = []; me.fileDenyPattern = new RegExp($('[data-file-deny-pattern]').attr('data-file-deny-pattern'), 'i'); me.maxFileSize = parseInt($('[data-max-file-size]').attr('data-max-file-size')); @@ -87,8 +88,27 @@ define('TYPO3/CMS/Backend/DragUploader', ['jquery'], function($) { } me.ignoreDrop(event); - // ask user if we should override files - var override = confirm(TYPO3.l10n.localize('file_upload.overwriteExistingFiles')); + // collect files which would be overridden + var filesToOverride = []; + $.each(event.dataTransfer.files, function(i, file) { + if($.inArray(file.name, me.filesOnServer) > -1) { + filesToOverride.push(file.name); + } + }); + + var override = false; + if (filesToOverride.length > 0) { + var message = TYPO3.l10n.localize('file_upload.overwriteExistingFiles') + + "\n\n" + filesToOverride.join("\n"); + + // ask user if we should override files + override = confirm(message); + + if (override === false) { + // user canceled upload, do not proceed + return false; + } + } // Add each file to queue and trigger upload $.each(event.dataTransfer.files, function(i, file) { @@ -125,6 +145,7 @@ define('TYPO3/CMS/Backend/DragUploader', ['jquery'], function($) { xhr.onload = function () { me.uploadCompletedCount++; me.updateProgress(); + me.filesOnServer.push(file.name); }; xhr.onerror = function() { TYPO3.Flashmessage.display( @@ -185,6 +206,11 @@ define('TYPO3/CMS/Backend/DragUploader', ['jquery'], function($) { } }); } + + // initialize the files which are already present on server + $('[data-file-name]').each(function(index, row) { + me.filesOnServer.push($(row).data('file-name')); + }); } diff --git a/typo3/sysext/filelist/Classes/FileList.php b/typo3/sysext/filelist/Classes/FileList.php index 7d16b8a8501a..5d8acae8b4db 100644 --- a/typo3/sysext/filelist/Classes/FileList.php +++ b/typo3/sysext/filelist/Classes/FileList.php @@ -631,7 +631,7 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList { $processedFile = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array()); if ($processedFile) { $thumbUrl = $processedFile->getPublicUrl(TRUE); - $theData[$field] .= '
'; + $theData[$field] .= '
'; } } break; diff --git a/typo3/sysext/lang/locallang_core.xlf b/typo3/sysext/lang/locallang_core.xlf index d18d9daa5e98..3ea57207c75f 100644 --- a/typo3/sysext/lang/locallang_core.xlf +++ b/typo3/sysext/lang/locallang_core.xlf @@ -467,7 +467,7 @@ Do you want to continue WITHOUT saving? Upload complete! Filelist reloading... - Shall existing files be overwritten? + The files below will be overwritten. Number of files: -- 2.20.1