From 32c1d55d1f35f4cdb81e054cb6b8d05b053af337 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sun, 21 Sep 2014 18:51:41 +0000 Subject: [PATCH] Media Grid: * In Bulk Edit mode, don't attempt to delete or trash an attachment that doesn't have a `delete` nonce. The subsequent `_requery()` will then properly display the attachment still present in the library. * Remove all updated models from the selection at the same time to avoid async race conditions. The selection is reset when the grid's `select` mode is deactivated, but this allows this view instance to be more portable. This fix allows users to set caps on individual attachments without confusing the grid's library. This issue was present for bulk actions in general, had nothing to do with `MEDIA_TRASH` specifically. Fixes #29597. git-svn-id: https://develop.svn.wordpress.org/trunk@29755 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-views.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index 3be94766f9..3655c0337d 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -6029,7 +6029,7 @@ controller: this.controller, priority: -60, click: function() { - var model, changed = [], self = this, + var changed = [], removed = [], self = this, selection = this.controller.state().get( 'selection' ), library = this.controller.state().get( 'library' ); @@ -6048,22 +6048,28 @@ return; } - while ( selection.length > 0 ) { - model = selection.at( 0 ); + selection.each( function( model ) { + if ( ! model.get( 'nonces' )['delete'] ) { + removed.push( model ); + return; + } + if ( media.view.settings.mediaTrash && 'trash' === model.get( 'status' ) ) { model.set( 'status', 'inherit' ); changed.push( model.save() ); - selection.remove( model ); + removed.push( model ); } else if ( media.view.settings.mediaTrash ) { model.set( 'status', 'trash' ); changed.push( model.save() ); - selection.remove( model ); + removed.push( model ); } else { model.destroy(); } - } + } ); if ( changed.length ) { + selection.remove( removed ); + $.when.apply( null, changed ).then( function() { library._requery( true ); self.controller.trigger( 'selection:action:done' );