Media Grid: Don't attempt to delete an attachment that can't be deleted.

Merges [29755] to the 4.0 branch.

props wonderboymusic.
fixes #29597.

Built from https://develop.svn.wordpress.org/branches/4.0@30409


git-svn-id: http://core.svn.wordpress.org/branches/4.0@30404 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2014-11-20 11:09:32 +00:00
parent e2cf18d5b9
commit 3a108f5bce
2 changed files with 13 additions and 7 deletions

View File

@ -5850,7 +5850,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' );
@ -5869,22 +5869,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' );

File diff suppressed because one or more lines are too long