Fix a media regression in [24110] that could cause duplicate models.
Props garyc40. Fixes #24753. See #24094, #23830. git-svn-id: https://develop.svn.wordpress.org/trunk@24771 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
a0df1d139a
commit
43902fb740
@ -1,7 +1,7 @@
|
|||||||
window.wp = window.wp || {};
|
window.wp = window.wp || {};
|
||||||
|
|
||||||
(function($){
|
(function($){
|
||||||
var Attachment, Attachments, Query, compare, l10n, media, bindSyncEvents;
|
var Attachment, Attachments, Query, compare, l10n, media;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wp.media( attributes )
|
* wp.media( attributes )
|
||||||
@ -67,27 +67,6 @@ window.wp = window.wp || {};
|
|||||||
return a > b ? -1 : 1;
|
return a > b ? -1 : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Ensures the 'sync' and 'error' events are always
|
|
||||||
// correctly triggered when overloading `Backbone.sync`.
|
|
||||||
bindSyncEvents = function( model, options ) {
|
|
||||||
var success = options.success,
|
|
||||||
error = options.error;
|
|
||||||
|
|
||||||
options.success = function( resp ) {
|
|
||||||
if ( success )
|
|
||||||
success( resp );
|
|
||||||
model.trigger( 'sync', model, resp, options );
|
|
||||||
};
|
|
||||||
|
|
||||||
options.error = function( xhr ) {
|
|
||||||
if ( error )
|
|
||||||
error( xhr );
|
|
||||||
model.trigger( 'error', model, xhr, options );
|
|
||||||
};
|
|
||||||
|
|
||||||
return options;
|
|
||||||
};
|
|
||||||
|
|
||||||
_.extend( media, {
|
_.extend( media, {
|
||||||
/**
|
/**
|
||||||
* media.template( id )
|
* media.template( id )
|
||||||
@ -197,7 +176,6 @@ window.wp = window.wp || {};
|
|||||||
action: 'get-attachment',
|
action: 'get-attachment',
|
||||||
id: this.id
|
id: this.id
|
||||||
});
|
});
|
||||||
bindSyncEvents( model, options );
|
|
||||||
return media.ajax( options );
|
return media.ajax( options );
|
||||||
|
|
||||||
// Overload the `update` request so properties can be saved.
|
// Overload the `update` request so properties can be saved.
|
||||||
@ -226,7 +204,6 @@ window.wp = window.wp || {};
|
|||||||
}, this );
|
}, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
bindSyncEvents( model, options );
|
|
||||||
return media.ajax( options );
|
return media.ajax( options );
|
||||||
|
|
||||||
// Overload the `delete` request so attachments can be removed.
|
// Overload the `delete` request so attachments can be removed.
|
||||||
@ -244,7 +221,6 @@ window.wp = window.wp || {};
|
|||||||
_wpnonce: this.get('nonces')['delete']
|
_wpnonce: this.get('nonces')['delete']
|
||||||
});
|
});
|
||||||
|
|
||||||
bindSyncEvents( model, options );
|
|
||||||
return media.ajax( options ).done( function() {
|
return media.ajax( options ).done( function() {
|
||||||
this.destroyed = true;
|
this.destroyed = true;
|
||||||
}).fail( function() {
|
}).fail( function() {
|
||||||
@ -506,6 +482,27 @@ window.wp = window.wp || {};
|
|||||||
return this.mirroring ? this.mirroring.hasMore() : false;
|
return this.mirroring ? this.mirroring.hasMore() : false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
parse: function( resp, xhr ) {
|
||||||
|
if ( ! _.isArray( resp ) )
|
||||||
|
resp = [resp];
|
||||||
|
|
||||||
|
return _.map( resp, function( attrs ) {
|
||||||
|
var id, attachment;
|
||||||
|
if ( attrs instanceof Backbone.Model ) {
|
||||||
|
id = attrs.get( 'id' );
|
||||||
|
attrs = attrs.attributes;
|
||||||
|
} else {
|
||||||
|
id = attrs.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
attachment = Attachment.get( attrs.id );
|
||||||
|
if ( ! _.isEqual( attachment.attributes, attrs ) )
|
||||||
|
attachment.set( attachment.parse( attrs, xhr ) );
|
||||||
|
|
||||||
|
return attachment;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
_requery: function() {
|
_requery: function() {
|
||||||
if ( this.props.get('query') )
|
if ( this.props.get('query') )
|
||||||
this.mirror( Query.get( this.props.toJSON() ) );
|
this.mirror( Query.get( this.props.toJSON() ) );
|
||||||
@ -701,7 +698,6 @@ window.wp = window.wp || {};
|
|||||||
args.paged = Math.floor( this.length / args.posts_per_page ) + 1;
|
args.paged = Math.floor( this.length / args.posts_per_page ) + 1;
|
||||||
|
|
||||||
options.data.query = args;
|
options.data.query = args;
|
||||||
bindSyncEvents( model, options );
|
|
||||||
return media.ajax( options );
|
return media.ajax( options );
|
||||||
|
|
||||||
// Otherwise, fall back to Backbone.sync()
|
// Otherwise, fall back to Backbone.sync()
|
||||||
|
Loading…
Reference in New Issue
Block a user