Skip to content

Commit 87364b0

Browse files
committed
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
1 parent baff296 commit 87364b0

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

src/wp-includes/js/media-views.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3956,7 +3956,9 @@ AttachmentsBrowser = View.extend({
39563956
controller: this.controller,
39573957
priority: -55,
39583958
click: function() {
3959-
var removed = [], selection = this.controller.state().get( 'selection' );
3959+
var removed = [],
3960+
destroy = [],
3961+
selection = this.controller.state().get( 'selection' );
39603962

39613963
if ( ! selection.length || ! window.confirm( l10n.warnBulkDelete ) ) {
39623964
return;
@@ -3968,11 +3970,20 @@ AttachmentsBrowser = View.extend({
39683970
return;
39693971
}
39703972

3971-
model.destroy();
3973+
destroy.push( model );
39723974
} );
39733975

3974-
selection.remove( removed );
3975-
this.controller.trigger( 'selection:action:done' );
3976+
if ( removed.length ) {
3977+
selection.remove( removed );
3978+
}
3979+
3980+
if ( destroy.length ) {
3981+
$.when.apply( null, destroy.map( function (item) {
3982+
return item.destroy();
3983+
} ) ).then( _.bind( function() {
3984+
this.controller.trigger( 'selection:action:done' );
3985+
}, this ) );
3986+
}
39763987
}
39773988
}).render() );
39783989
}

src/wp-includes/js/media/views/attachments/browser.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ AttachmentsBrowser = View.extend({
225225
controller: this.controller,
226226
priority: -55,
227227
click: function() {
228-
var removed = [], selection = this.controller.state().get( 'selection' );
228+
var removed = [],
229+
destroy = [],
230+
selection = this.controller.state().get( 'selection' );
229231

230232
if ( ! selection.length || ! window.confirm( l10n.warnBulkDelete ) ) {
231233
return;
@@ -237,11 +239,20 @@ AttachmentsBrowser = View.extend({
237239
return;
238240
}
239241

240-
model.destroy();
242+
destroy.push( model );
241243
} );
242244

243-
selection.remove( removed );
244-
this.controller.trigger( 'selection:action:done' );
245+
if ( removed.length ) {
246+
selection.remove( removed );
247+
}
248+
249+
if ( destroy.length ) {
250+
$.when.apply( null, destroy.map( function (item) {
251+
return item.destroy();
252+
} ) ).then( _.bind( function() {
253+
this.controller.trigger( 'selection:action:done' );
254+
}, this ) );
255+
}
245256
}
246257
}).render() );
247258
}

0 commit comments

Comments
 (0)