Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/js/media/models/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,62 @@ var Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachmen
}

return status === attachment.get('status');
},
/**
* @static
* @param {wp.media.model.Attachment} attachment
*
* @this wp.media.model.Attachments
*
* @return {boolean}
*/
year: function( attachment ) {
var year = this.props.get('year'),
date;

if ( _.isUndefined( year ) || false === year ) {
return true;
}

// If uploading, we don't have the date yet, so allow it through.
if ( attachment.get('uploading') ) {
return true;
}

date = attachment.get('date') || attachment.get('modified');
if ( date ) {
return year === new Date( date ).getFullYear();
}

return false;
},
/**
* @static
* @param {wp.media.model.Attachment} attachment
*
* @this wp.media.model.Attachments
*
* @return {boolean}
*/
monthnum: function( attachment ) {
var monthnum = this.props.get('monthnum'),
date;

if ( _.isUndefined( monthnum ) || false === monthnum ) {
return true;
}

// If uploading, we don't have the date yet, so allow it through.
if ( attachment.get('uploading') ) {
return true;
}

date = attachment.get('date') || attachment.get('modified');
if ( date ) {
return monthnum === ( new Date( date ).getMonth() + 1 );
}

return false;
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/js/media/models/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{
* are no filters for other properties, so observing will result in
* false positives in those queries.
*/
allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ];
allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author', 'year', 'monthnum' ];
if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) {
this.observe( wp.Uploader.queue );
}
Expand Down
Loading