Ticket #24716: 24716.28.diff
File 24716.28.diff, 3.6 KB (added by , 10 years ago) |
---|
-
src/wp-includes/js/media-grid.js
213 213 214 214 // Handle a frame-level event for editing an attachment. 215 215 this.on( 'edit:attachment', this.editAttachment, this ); 216 this.on( 'edit:attachment:next', this.editNextAttachment, this );217 this.on( 'edit:attachment:previous', this.editPreviousAttachment, this );218 216 }, 219 217 220 editPreviousAttachment: function( currentModel ) {221 var library = this.state().get('library'),222 currentModelIndex = library.indexOf( currentModel );223 this.trigger( 'edit:attachment', library.at( currentModelIndex - 1 ) );224 },225 226 editNextAttachment: function( currentModel ) {227 var library = this.state().get('library'),228 currentModelIndex = library.indexOf( currentModel );229 this.trigger( 'edit:attachment', library.at( currentModelIndex + 1 ) );230 },231 232 218 /** 233 219 * Open the Edit Attachment modal. 234 220 */ 235 221 editAttachment: function( model ) { 236 var library = this.state().get('library'), hasPrevious, hasNext; 237 if ( library.indexOf( model ) > 0 ) { 238 hasPrevious = true; 239 } 240 else { 241 hasPrevious = false; 242 } 243 if ( library.indexOf( model ) < library.length - 1 ) { 244 hasNext = true; 245 } 246 else { 247 hasNext = false; 248 } 249 250 new media.view.Frame.EditAttachment({ 251 hasPrevious: hasPrevious, 252 hasNext: hasNext, 253 model: model, 254 gridController: this 222 // Create a new EditAttachment frame, passing along the library. 223 this.editAttachmentFrame = new media.view.Frame.EditAttachments({ 224 library: this.state().get('library'), 225 model: model 255 226 }); 256 227 }, 257 228 … … 330 301 * 331 302 * Requires an attachment model to be passed in the options hash under `model`. 332 303 */ 333 media.view.Frame.EditAttachment = media.view.Frame.extend({304 media.view.Frame.EditAttachments = media.view.Frame.extend({ 334 305 335 306 className: 'edit-attachment-frame', 336 307 template: media.template( 'edit-attachment-frame' ), … … 352 323 state: 'edit-attachment' 353 324 }); 354 325 326 this.library = this.options.library; 327 if ( this.options.model ) { 328 this.model = this.options.model; 329 } else { 330 this.model = this.library.at( 0 ); 331 } 332 355 333 this.createStates(); 356 334 357 335 this.on( 'content:render:edit-metadata', this.editMetadataContent, this ); … … 464 442 }); 465 443 }, 466 444 445 getCurrentIndex: function() { 446 return this.library.indexOf( this.model ); 447 }, 448 449 hasNext: function() { 450 return ( this.getCurrentIndex() + 1 ) < this.library.length; 451 }, 452 453 hasPrevious: function() { 454 return ( this.getCurrentIndex() - 1 ) > -1; 455 }, 456 467 457 /** 468 458 * Click handler to switch to the previous media item. 469 459 */ 470 460 previousMediaItem: function() { 471 if ( ! this. options.hasPrevious )461 if ( ! this.hasPrevious() ) { 472 462 return; 473 this.modal.close(); 474 this.options.gridController.trigger( 'edit:attachment:previous', this.model ); 463 } 464 this.model = this.library.at( this.getCurrentIndex() - 1 ); 465 this.editMetadataContent(); 475 466 }, 476 467 477 468 /** … … 478 469 * Click handler to switch to the next media item. 479 470 */ 480 471 nextMediaItem: function() { 481 if ( ! this. options.hasNext )472 if ( ! this.hasNext() ) { 482 473 return; 483 this.modal.close(); 484 this.options.gridController.trigger( 'edit:attachment:next', this.model ); 474 } 475 this.model = this.library.at( this.getCurrentIndex() + 1 ); 476 this.editMetadataContent(); 485 477 } 486 487 478 }); 488 479 489 480 media.view.GridFieldOptions = media.View.extend({