From 87364b05862632e4e1b85d6955d467af514cb7a8 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 8 Feb 2017 19:43:58 +0000 Subject: [PATCH] Media: in `wp.media.view.DeleteSelectedPermanentlyButton`, move destructive async operations outside of the `selection` loop. Fixes #39780. git-svn-id: https://develop.svn.wordpress.org/trunk@40051 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-views.js | 19 +++++++++++++++---- .../js/media/views/attachments/browser.js | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index ae9ea8e1d0..96d46880cf 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -3956,7 +3956,9 @@ AttachmentsBrowser = View.extend({ controller: this.controller, priority: -55, click: function() { - var removed = [], selection = this.controller.state().get( 'selection' ); + var removed = [], + destroy = [], + selection = this.controller.state().get( 'selection' ); if ( ! selection.length || ! window.confirm( l10n.warnBulkDelete ) ) { return; @@ -3968,11 +3970,20 @@ AttachmentsBrowser = View.extend({ return; } - model.destroy(); + destroy.push( model ); } ); - selection.remove( removed ); - this.controller.trigger( 'selection:action:done' ); + if ( removed.length ) { + selection.remove( removed ); + } + + if ( destroy.length ) { + $.when.apply( null, destroy.map( function (item) { + return item.destroy(); + } ) ).then( _.bind( function() { + this.controller.trigger( 'selection:action:done' ); + }, this ) ); + } } }).render() ); } diff --git a/src/wp-includes/js/media/views/attachments/browser.js b/src/wp-includes/js/media/views/attachments/browser.js index bd83278afc..6bb61e252e 100644 --- a/src/wp-includes/js/media/views/attachments/browser.js +++ b/src/wp-includes/js/media/views/attachments/browser.js @@ -225,7 +225,9 @@ AttachmentsBrowser = View.extend({ controller: this.controller, priority: -55, click: function() { - var removed = [], selection = this.controller.state().get( 'selection' ); + var removed = [], + destroy = [], + selection = this.controller.state().get( 'selection' ); if ( ! selection.length || ! window.confirm( l10n.warnBulkDelete ) ) { return; @@ -237,11 +239,20 @@ AttachmentsBrowser = View.extend({ return; } - model.destroy(); + destroy.push( model ); } ); - selection.remove( removed ); - this.controller.trigger( 'selection:action:done' ); + if ( removed.length ) { + selection.remove( removed ); + } + + if ( destroy.length ) { + $.when.apply( null, destroy.map( function (item) { + return item.destroy(); + } ) ).then( _.bind( function() { + this.controller.trigger( 'selection:action:done' ); + }, this ) ); + } } }).render() ); }