Media Grid: Add a date filter.

props ericlewis.
fixes #28895.
Built from https://develop.svn.wordpress.org/trunk@29271


git-svn-id: http://core.svn.wordpress.org/trunk@29053 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2014-07-22 20:47:15 +00:00
parent de8961d631
commit 270a57075c
6 changed files with 59 additions and 8 deletions

View File

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

View File

@ -448,7 +448,7 @@
/** /**
* Render the EditImage view into the frame's content region. * Render the EditImage view into the frame's content region.
* *
* @param {Object} contentRegion Basic object with a `view` property, which * @param {Object} contentRegion Basic object with a `view` property, which
* should be set with the proper region view. * 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)); }(jQuery, _, Backbone, wp));

File diff suppressed because one or more lines are too long

View File

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

File diff suppressed because one or more lines are too long

View File

@ -2772,7 +2772,7 @@ function wp_enqueue_media( $args = array() ) {
if ( did_action( 'wp_enqueue_media' ) ) if ( did_action( 'wp_enqueue_media' ) )
return; return;
global $content_width, $wpdb; global $content_width, $wpdb, $wp_locale;
$defaults = array( $defaults = array(
'post' => null, 'post' => null,
@ -2825,6 +2825,15 @@ function wp_enqueue_media( $args = array() ) {
AND post_mime_type LIKE 'video%' AND post_mime_type LIKE 'video%'
LIMIT 1 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( $settings = array(
'tabs' => $tabs, 'tabs' => $tabs,
@ -2846,6 +2855,7 @@ function wp_enqueue_media( $args = array() ) {
'embedExts' => $exts, 'embedExts' => $exts,
'embedMimes' => $ext_mimes, 'embedMimes' => $ext_mimes,
'contentWidth' => $content_width, 'contentWidth' => $content_width,
'months' => $months,
); );
$post = null; $post = null;
@ -2904,6 +2914,7 @@ function wp_enqueue_media( $args = array() ) {
'returnToLibrary' => __( '← Return to library' ), 'returnToLibrary' => __( '← Return to library' ),
'allMediaItems' => __( 'All media items' ), 'allMediaItems' => __( 'All media items' ),
'allMediaTypes' => __( 'All media types' ), 'allMediaTypes' => __( 'All media types' ),
'allDates' => __( 'All dates' ),
'noItemsFound' => __( 'No items found.' ), 'noItemsFound' => __( 'No items found.' ),
'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ), 'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ), 'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ),