Media: Update total attachment count when media added or removed.

Add handlers to increment the total attachments count for the media collection when an item is added or removed.

props adamsilverstein.
Fixes #53171.

git-svn-id: https://develop.svn.wordpress.org/trunk@51191 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe Dolson 2021-06-21 20:44:41 +00:00
parent d0e8b81cd8
commit 422d301ac0

View File

@ -212,6 +212,8 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen
this.observers.push( attachments );
attachments.on( 'add change remove', this._validateHandler, this );
attachments.on( 'add', this._addToTotalAttachments, this );
attachments.on( 'remove', this._removeFromTotalAttachments, this );
attachments.on( 'reset', this._validateAllHandler, this );
this.validateAll( attachments );
return this;
@ -236,6 +238,30 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen
return this;
},
/**
* Update total attachment count when items are added to a collection.
*
* @access private
*
* @since 5.8.0
*/
_removeFromTotalAttachments: function() {
if ( this.mirroring ) {
this.mirroring.totalAttachments = this.mirroring.totalAttachments - 1;
}
},
/**
* Update total attachment count when items are added to a collection.
*
* @access private
*
* @since 5.8.0
*/
_addToTotalAttachments: function() {
if ( this.mirroring ) {
this.mirroring.totalAttachments = this.mirroring.totalAttachments + 1;
}
},
/**
* @access private
*