Changeset 23589 for trunk/wp-includes/js/media-models.js
- Timestamp:
- 03/03/2013 07:04:06 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/media-models.js
r23092 r23589 2 2 3 3 (function($){ 4 var Attachment, Attachments, Query, compare, l10n, media ;4 var Attachment, Attachments, Query, compare, l10n, media, bindSyncEvents; 5 5 6 6 /** … … 66 66 else 67 67 return a > b ? -1 : 1; 68 }; 69 70 // Ensures the 'sync' and 'error' events are always 71 // correctly triggered when overloading `Backbone.sync`. 72 bindSyncEvents = function( model, options ) { 73 var success = options.success, 74 error = options.error; 75 76 options.success = function( resp ) { 77 if ( success ) 78 success( model, resp, options ); 79 model.trigger( 'sync', model, resp, options ); 80 }; 81 82 options.error = function( xhr ) { 83 if ( error ) 84 error( model, xhr, options ); 85 model.trigger( 'error', model, xhr, options ); 86 }; 87 88 return options; 68 89 }; 69 90 … … 242 263 id: this.id 243 264 }); 265 bindSyncEvents( model, options ); 244 266 return media.ajax( options ); 245 267 … … 262 284 263 285 // Record the values of the changed attributes. 264 if ( options.changes ) { 265 _.each( options.changes, function( value, key ) { 266 options.changes[ key ] = this.get( key ); 286 if ( model.hasChanged() ) { 287 options.data.changes = {}; 288 289 _.each( model.changed, function( value, key ) { 290 options.data.changes[ key ] = this.get( key ); 267 291 }, this ); 268 269 options.data.changes = options.changes;270 delete options.changes;271 292 } 272 293 294 bindSyncEvents( model, options ); 273 295 return media.ajax( options ); 274 296 … … 288 310 }); 289 311 312 bindSyncEvents( model, options ); 290 313 return media.ajax( options ).done( function() { 291 314 this.destroyed = true; … … 293 316 this.destroyed = false; 294 317 }); 318 319 // Otherwise, fall back to `Backbone.sync()`. 320 } else { 321 return Backbone.Model.prototype.sync.apply( this, arguments ); 295 322 } 296 323 }, … … 393 420 return; 394 421 395 var changed = _.chain( options.changes).map( function( t, prop ) {422 var changed = _.chain( model.changed ).map( function( t, prop ) { 396 423 var filter = Attachments.filters[ prop ], 397 424 term = model.get( prop ); … … 435 462 validate: function( attachment, options ) { 436 463 var valid = this.validator( attachment ), 437 hasAttachment = !! this.get ByCid( attachment.cid );464 hasAttachment = !! this.get( attachment.cid ); 438 465 439 466 if ( ! valid && hasAttachment ) … … 747 774 748 775 options.data.query = args; 776 bindSyncEvents( model, options ); 749 777 return media.ajax( options ); 750 778 … … 877 905 878 906 // If the single model isn't in the selection, remove it. 879 if ( this._single && ! this.get ByCid( this._single.cid ) )907 if ( this._single && ! this.get( this._single.cid ) ) 880 908 delete this._single; 881 909 … … 889 917 // If the model was already removed, trigger the collection 890 918 // event manually. 891 if ( ! this.get ByCid( previous.cid ) )919 if ( ! this.get( previous.cid ) ) 892 920 this.trigger( 'selection:unsingle', previous, this ); 893 921 }
Note: See TracChangeset
for help on using the changeset viewer.