[BUGFIX] Improve confirmation dialog in drag'n'drop fileupload 23/25523/4
authorStefan Aebischer <typo3@pixtron.ch>
Wed, 20 Nov 2013 00:02:54 +0000 (01:02 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 20 Nov 2013 17:32:21 +0000 (18:32 +0100)
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
typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js
typo3/sysext/filelist/Classes/FileList.php
typo3/sysext/lang/locallang_core.xlf

index 1f8a6c0..8c6e031 100644 (file)
@@ -33,6 +33,7 @@ define('TYPO3/CMS/Backend/DragUploader', ['jquery'], function($) {
                me.$progress = $('<div />').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'));
+                       });
                }
 
 
index 7d16b8a..5d8acae 100644 (file)
@@ -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] .= '<br /><img src="' . $thumbUrl . '" hspace="2" title="' . htmlspecialchars($fileName) . '" alt="" />';
+                                                                       $theData[$field] .= '<br /><img src="' . $thumbUrl . '" hspace="2" data-file-name="' . htmlspecialchars($fileName) . '" title="' . htmlspecialchars($fileName) . '" alt="" />';
                                                                }
                                                        }
                                                        break;
index d18d9da..3ea5720 100644 (file)
@@ -467,7 +467,7 @@ Do you want to continue WITHOUT saving?</source>
                                <source>Upload complete! Filelist reloading...</source>
                        </trans-unit>
                        <trans-unit id="file_upload.overwriteExistingFiles" xml:space="preserve">
-                               <source>Shall existing files be overwritten?</source>
+                               <source>The files below will be overwritten.</source>
                        </trans-unit>
                        <trans-unit id="file_upload.php.number_of_files" xml:space="preserve">
                                <source>Number of files:</source>