[BUGFIX] Timeout processing of media URL to avoid race condition 69/43369/3
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 16 Sep 2015 09:17:56 +0000 (11:17 +0200)
committerBenni Mack <benni@typo3.org>
Sat, 19 Sep 2015 20:19:30 +0000 (22:19 +0200)
The new "Add media by URL" button opens a modal with a textfield
for an URL. If processing the URL fails, an error modal is displayed.
However, because of a race condition the error dialog is not closable.
Add a timeout of 200ms before processing the URL to workaround the
race condition.

Resolves: #69868
Related: #61799
Releases: master
Change-Id: I7a8f1450b73b4923a1ae9c2e0346e2571475b92e
Reviewed-on: http://review.typo3.org/43369
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/backend/Resources/Public/JavaScript/OnlineMedia.js

index f48f8ec..2de7b6b 100644 (file)
@@ -70,10 +70,11 @@ define('TYPO3/CMS/Backend/OnlineMedia', ['jquery', 'nprogress', 'TYPO3/CMS/Lang/
                // Bind key press enter event
                me.$btn.on('click', function(evt) {
                        evt.preventDefault();
+
                        var $modal = top.TYPO3.Modal.show(
                                me.$btn.attr('title'),
                                '<div class="form-control-wrap">' +
-                               '<input type="text" class="form-control online-media-url" placeholder="' + me.placeholder + '" />' +
+                                       '<input type="text" class="form-control online-media-url" placeholder="' + me.placeholder + '" />' +
                                '</div>',
                                top.TYPO3.Severity.notice,
                                [{
@@ -84,7 +85,11 @@ define('TYPO3/CMS/Backend/OnlineMedia', ['jquery', 'nprogress', 'TYPO3/CMS/Lang/
                                                var url = $modal.find('input.online-media-url').val();
                                                if (url) {
                                                        $modal.trigger('modal-dismiss');
-                                                       me.addOnlineMedia(url);
+
+                                                       // Avoid a race condition between dismissing the current modal and creating a new one
+                                                       window.setTimeout(function() {
+                                                               me.addOnlineMedia(url);
+                                                       }, 200);
                                                }
                                        }
                                }]