[BUGFIX] Use Promises in Recycler 39/44039/4
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 14 Oct 2015 07:19:06 +0000 (09:19 +0200)
committerAlexander Opitz <opitz.alexander@googlemail.com>
Wed, 14 Oct 2015 14:55:31 +0000 (16:55 +0200)
Use Promise objects in Recycler to handle dependencies between multiple AJAX
requests. This drops the deprecated and blocking ``async: false`` setting.
Thus, the client side performance of the recycler is heavily increased.

Resolves: #70674
Releases: master
Change-Id: Idada49773e560793a6e8e1cc574b26a97d22c6ce
Reviewed-on: http://review.typo3.org/44039
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
typo3/sysext/recycler/Resources/Public/JavaScript/Recycler.js

index 90a2cf3..af92543 100644 (file)
@@ -93,8 +93,9 @@ define(['jquery', 'nprogress', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Backend/jqu
 
                // changing "depth"
                Recycler.elements.$depthSelector.on('change', function() {
-                       Recycler.loadAvailableTables();
-                       Recycler.loadDeletedElements();
+                       $.when(Recycler.loadAvailableTables()).done(function() {
+                               Recycler.loadDeletedElements();
+                       });
                });
 
                // changing "table"
@@ -111,8 +112,9 @@ define(['jquery', 'nprogress', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Backend/jqu
 
                Recycler.elements.$reloadAction.on('click', function(e) {
                        e.preventDefault();
-                       Recycler.loadAvailableTables();
-                       Recycler.loadDeletedElements();
+                       $.when(Recycler.loadAvailableTables()).done(function() {
+                               Recycler.loadDeletedElements();
+                       });
                });
 
                // clicking an action in the paginator
@@ -195,8 +197,9 @@ define(['jquery', 'nprogress', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Backend/jqu
                if (TYPO3.settings.Recycler.depthSelection > 0) {
                        Recycler.elements.$depthSelector.val(TYPO3.settings.Recycler.depthSelection).trigger('change');
                } else {
-                       Recycler.loadAvailableTables();
-                       Recycler.loadDeletedElements();
+                       $.when(Recycler.loadAvailableTables()).done(function() {
+                               Recycler.loadDeletedElements();
+                       });
                }
        };
 
@@ -249,14 +252,14 @@ define(['jquery', 'nprogress', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Backend/jqu
        };
 
        /**
-        * Loads all tables which contain deleted records. This call is not asynchronous
-        * due to settings the stored table before loading the deleted records.
+        * Loads all tables which contain deleted records.
+        *
+        * @returns {Promise}
         */
        Recycler.loadAvailableTables = function() {
-               $.ajax({
+               return $.ajax({
                        url: TYPO3.settings.ajaxUrls['recycler'],
                        dataType: 'json',
-                       async: false,
                        data: {
                                action: 'getTables',
                                startUid: TYPO3.settings.Recycler.startUid,
@@ -297,9 +300,11 @@ define(['jquery', 'nprogress', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Backend/jqu
 
        /**
         * Loads the deleted elements, based on the filters
+        *
+        * @returns {Promise}
         */
        Recycler.loadDeletedElements = function() {
-               $.ajax({
+               return $.ajax({
                        url: TYPO3.settings.ajaxUrls['recycler'],
                        dataType: 'json',
                        data: {
@@ -447,19 +452,20 @@ define(['jquery', 'nprogress', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/Backend/jqu
 
                                // reload recycler data
                                Recycler.paging.currentPage = 1;
-                               Recycler.loadAvailableTables();
-                               Recycler.loadDeletedElements();
 
-                               if (isMassAction) {
-                                       Recycler.resetMassActionButtons();
-                               }
+                               $.when(Recycler.loadAvailableTables()).done(function() {
+                                       Recycler.loadDeletedElements();
+                                       if (isMassAction) {
+                                               Recycler.resetMassActionButtons();
+                                       }
 
-                               if (reloadPageTree) {
-                                       Recycler.refreshPageTree();
-                               }
+                                       if (reloadPageTree) {
+                                               Recycler.refreshPageTree();
+                                       }
 
-                               // Reset toggle state
-                               Recycler.allToggled = false;
+                                       // Reset toggle state
+                                       Recycler.allToggled = false;
+                               });
                        },
                        complete: function() {
                                Modal.dismiss();