[BUGFIX] Flash messages are not shown with AJAX requests 00/28200/4
authorXavier Perseguers <xavier@typo3.org>
Sun, 9 Mar 2014 16:56:21 +0000 (17:56 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Tue, 11 Mar 2014 09:48:31 +0000 (10:48 +0100)
Due to the use of DragUploader to upload files, flash messages
are not shown immediately but after manually reloading the page.

Change-Id: Ia2e8750792bd04209b5a1f2ce0e2a63f970ba3a8
Fixes: #56561
Releases: 6.2
Reviewed-on: https://review.typo3.org/28200
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/backend/Classes/Form/Element/InlineElement.php
typo3/sysext/backend/Classes/Template/DocumentTemplate.php
typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js
typo3/sysext/core/Configuration/DefaultConfiguration.php
typo3/sysext/filelist/Classes/Controller/FileListController.php

index 7180605..c06229d 100644 (file)
@@ -939,6 +939,7 @@ class InlineElement {
                $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileListLocalisation');
                $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DragUploader');
                $pageRenderer->addInlineSetting('DragUploader', 'ajaxUrl', BackendUtility::getAjaxUrl('TYPO3_tcefile::process'));
+               $pageRenderer->addInlineSetting('DragUploader', 'ajaxFlashMessagesUrl', BackendUtility::getAjaxUrl('DocumentTemplate::getFlashMessages'));
                $pageRenderer->addInlineLanguagelabelFile(
                        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('lang') . 'locallang_core.xlf',
                        'file_upload'
index e326a69..1894cee 100644 (file)
@@ -1962,6 +1962,18 @@ function jumpToUrl(URL) {
        }
 
        /**
+        * Renders the FlashMessages from queue and returns them as AJAX.
+        *
+        * @param array $params Always empty.
+        * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The AjaxRequestHandler object used to return content and set content types
+        * @return void
+        */
+       public function renderFlashMessages(array $params, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj) {
+               $ajaxObj->addContent('result', $this->getFlashMessages());
+               $ajaxObj->setContentFormat('html');
+       }
+
+       /**
         * Fill the button lists with the defined HTML
         *
         * @param array $buttons HTML for all buttons
index 2f0aab2..55343d9 100644 (file)
@@ -94,6 +94,7 @@ define('TYPO3/CMS/Backend/DragUploader', ['jquery'], function($) {
                };
 
                me.processFiles = function (files) {
+                       me.queueLength = 0;
 
                        // ask user if we should override files
                        var override = confirm(TYPO3.l10n.localize('file_upload.overwriteExistingFiles'));
@@ -102,6 +103,7 @@ define('TYPO3/CMS/Backend/DragUploader', ['jquery'], function($) {
                        }
                        // Add each file to queue and start upload
                        $.each(files, function(i, file) {
+                               me.queueLength++;
                                new FileQueueItem(me, file, override);
                        });
                };
@@ -155,6 +157,26 @@ define('TYPO3/CMS/Backend/DragUploader', ['jquery'], function($) {
 
                        me.bindUploadButton(me.$trigger.length ? me.$trigger : me.$element);
                }
+
+               me.decrementQueueLength = function() {
+                       if (me.queueLength > 0) {
+                               me.queueLength--;
+                               if (me.queueLength == 0) {
+                                       $.ajax({
+                                               url: TYPO3.settings.DragUploader.ajaxFlashMessagesUrl,
+                                               cache: false,
+                                               success: function(data) {
+                                                       var messages = $('#typo3-messages');
+                                                       if (messages.length == 0) {
+                                                               $('#typo3-inner-docbody').prepend(data);
+                                                       } else {
+                                                               messages.replaceWith(data);
+                                                       }
+                                               }
+                                       });
+                               }
+                       }
+               }
        };
 
        var FileQueueItem = function(dragUploader, file, override) {
@@ -198,6 +220,7 @@ define('TYPO3/CMS/Backend/DragUploader', ['jquery'], function($) {
                                me.$progressPercentage.text('(' + response.statusText + ')');
                        }
                        me.$row.addClass('error');
+                       dragUploader.decrementQueueLength();
                };
 
                me.updateProgress = function(event) {
@@ -208,6 +231,7 @@ define('TYPO3/CMS/Backend/DragUploader', ['jquery'], function($) {
 
                me.uploadComplete = function(data) {
                        if (data.result.upload) {
+                               me.dragUploader.decrementQueueLength();
                                me.$row.removeClass('uploading');
                                me.$fileName.text(data.result.upload[0].name);
                                me.$progressPercentage.text('');
index c235c5d..ba510a6 100644 (file)
@@ -708,6 +708,10 @@ return array(
                                // All ExtJS calls are CSRF protected with another token
                                'csrfTokenCheck' => FALSE
                        ),
+                       'DocumentTemplate::getFlashMessages' => array(
+                               'callbackMethod' => 'TYPO3\\CMS\\Backend\\Template\\DocumentTemplate->renderFlashMessages',
+                               'csrfTokenCheck' => TRUE
+                       ),
                ),
                'XCLASS' => array()
        ),
index 53411e0..2d83d5e 100644 (file)
@@ -326,6 +326,7 @@ class FileListController {
                        ) {
                                $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DragUploader');
                                $pageRenderer->addInlineSetting('DragUploader', 'ajaxUrl', BackendUtility::getAjaxUrl('TYPO3_tcefile::process'));
+                               $pageRenderer->addInlineSetting('DragUploader', 'ajaxFlashMessagesUrl', BackendUtility::getAjaxUrl('DocumentTemplate::getFlashMessages'));
                                $pageRenderer->addInlineLanguagelabelFile(
                                        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('lang') . 'locallang_core.xlf',
                                        'file_upload'