Media Grid: on page load with ?item= in the URL, if the model is not in the library: fetch it. Defer the triggering of edit:attachment until the model has been fetched.

Fixes #29052.


git-svn-id: https://develop.svn.wordpress.org/trunk@29525 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-08-18 02:13:01 +00:00
parent 27cd1b4f92
commit 48d83dcc66

View File

@ -306,10 +306,20 @@
// Show the modal with a specific item
showItem: function( query ) {
var library = media.frame.state().get('library');
var library = media.frame.state().get('library'), item;
// Trigger the media frame to open the correct item
media.frame.trigger( 'edit:attachment', library.findWhere( { id: parseInt( query, 10 ) } ) );
item = library.findWhere( { id: parseInt( query, 10 ) } );
if ( item ) {
media.frame.trigger( 'edit:attachment', item );
} else {
item = media.attachment( query );
media.frame.listenTo( item, 'change', function( model ) {
media.frame.stopListening( item );
media.frame.trigger( 'edit:attachment', model );
} );
item.fetch();
}
}
});
@ -373,9 +383,6 @@
if ( this.options.model ) {
this.model = this.options.model;
} else {
// this is a hack
this.model = this.library.at( 0 );
}
this.bindHandlers();