Media Grid: Add a date filter.

props ericlewis.
fixes #28895.

git-svn-id: https://develop.svn.wordpress.org/trunk@29271 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90) 2014-07-22 20:46:22 +00:00
parent 60732933f3
commit cce3bdf920
4 changed files with 57 additions and 6 deletions

View File

@ -2156,7 +2156,7 @@ function wp_ajax_query_attachments() {
$query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
$query = array_intersect_key( $query, array_flip( array(
's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type',
'post_parent', 'post__in', 'post__not_in',
'post_parent', 'post__in', 'post__not_in', 'year', 'monthnum'
) ) );
$query['post_type'] = 'attachment';
@ -2713,7 +2713,7 @@ function wp_ajax_parse_media_shortcode() {
if ( ! empty( $wp_scripts ) ) {
$wp_scripts->done = array();
}
if ( 'playlist' === $_REQUEST['type'] ) {
wp_underscore_playlist_templates();

View File

@ -448,7 +448,7 @@
/**
* Render the EditImage view into the frame's content region.
*
*
* @param {Object} contentRegion Basic object with a `view` property, which
* should be set with the proper region view.
*/
@ -649,4 +649,33 @@
}
});
/**
* A filter dropdown for month/dates.
*/
media.view.DateFilter = media.view.AttachmentFilters.extend({
id: 'media-attachment-date-filters',
createFilters: function() {
var filters = {};
_.each( media.view.settings.months || {}, function( value, index ) {
filters[ index ] = {
text: value.text,
props: {
year: value.year,
monthnum: value.month
}
};
});
filters.all = {
text: l10n.allDates,
props: {
monthnum: false,
year: false
},
priority: 10
};
this.filters = filters;
}
});
}(jQuery, _, Backbone, wp));

View File

@ -5506,13 +5506,19 @@
this.select();
},
/**
* @abstract
*/
createFilters: function() {
this.filters = {};
},
/**
* When the selection changes, set the Query properties
* accordingly for the selected filter.
*/
change: function() {
var filter = this.filters[ this.el.value ];
if ( filter ) {
this.model.set( filter.props );
}
@ -5742,10 +5748,15 @@
priority: -90
}).render() );
this.toolbar.set( 'BulkSelection', new media.view.BulkSelection({
this.toolbar.set( 'bulkSelection', new media.view.BulkSelection({
controller: this.controller,
priority: -70
}).render() );
this.toolbar.set( 'dateFilter', new media.view.DateFilter({
controller: this.controller,
model: this.collection.props,
priority: -75
}).render() );
}
filters = this.options.filters;

View File

@ -2772,7 +2772,7 @@ function wp_enqueue_media( $args = array() ) {
if ( did_action( 'wp_enqueue_media' ) )
return;
global $content_width, $wpdb;
global $content_width, $wpdb, $wp_locale;
$defaults = array(
'post' => null,
@ -2825,6 +2825,15 @@ function wp_enqueue_media( $args = array() ) {
AND post_mime_type LIKE 'video%'
LIMIT 1
" );
$months = $wpdb->get_results( $wpdb->prepare( "
SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
FROM $wpdb->posts
WHERE post_type = %s
ORDER BY post_date DESC
", 'attachment' ) );
foreach ( $months as $month_year ) {
$month_year->text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month_year->month ), $month_year->year );
}
$settings = array(
'tabs' => $tabs,
@ -2846,6 +2855,7 @@ function wp_enqueue_media( $args = array() ) {
'embedExts' => $exts,
'embedMimes' => $ext_mimes,
'contentWidth' => $content_width,
'months' => $months,
);
$post = null;
@ -2904,6 +2914,7 @@ function wp_enqueue_media( $args = array() ) {
'returnToLibrary' => __( '← Return to library' ),
'allMediaItems' => __( 'All media items' ),
'allMediaTypes' => __( 'All media types' ),
'allDates' => __( 'All dates' ),
'noItemsFound' => __( 'No items found.' ),
'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ),