Make WordPress Core

Changeset 29271


Ignore:
Timestamp:
07/22/2014 08:46:22 PM (11 years ago)
Author:
ocean90
Message:

Media Grid: Add a date filter.

props ericlewis.
fixes #28895.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r29206 r29271  
    21572157    $query = array_intersect_key( $query, array_flip( array(
    21582158        's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type',
    2159         'post_parent', 'post__in', 'post__not_in',
     2159        'post_parent', 'post__in', 'post__not_in', 'year', 'monthnum'
    21602160    ) ) );
    21612161
     
    27142714        $wp_scripts->done = array();
    27152715    }
    2716    
     2716
    27172717    if ( 'playlist' === $_REQUEST['type'] ) {
    27182718        wp_underscore_playlist_templates();
  • trunk/src/wp-includes/js/media-grid.js

    r29266 r29271  
    449449        /**
    450450         * Render the EditImage view into the frame's content region.
    451          * 
     451         *
    452452         * @param {Object} contentRegion Basic object with a `view` property, which
    453453         *                               should be set with the proper region view.
     
    650650    });
    651651
     652    /**
     653     * A filter dropdown for month/dates.
     654     */
     655    media.view.DateFilter = media.view.AttachmentFilters.extend({
     656        id: 'media-attachment-date-filters',
     657
     658        createFilters: function() {
     659            var filters = {};
     660            _.each( media.view.settings.months || {}, function( value, index ) {
     661                filters[ index ] = {
     662                    text: value.text,
     663                    props: {
     664                        year: value.year,
     665                        monthnum: value.month
     666                    }
     667                };
     668            });
     669            filters.all = {
     670                text:  l10n.allDates,
     671                props: {
     672                    monthnum: false,
     673                    year:  false
     674                },
     675                priority: 10
     676            };
     677            this.filters = filters;
     678        }
     679    });
     680
    652681}(jQuery, _, Backbone, wp));
  • trunk/src/wp-includes/js/media-views.js

    r29266 r29271  
    55075507        },
    55085508
     5509        /**
     5510         * @abstract
     5511         */
    55095512        createFilters: function() {
    55105513            this.filters = {};
    55115514        },
    55125515
     5516        /**
     5517         * When the selection changes, set the Query properties
     5518         * accordingly for the selected filter.
     5519         */
    55135520        change: function() {
    55145521            var filter = this.filters[ this.el.value ];
    5515 
    55165522            if ( filter ) {
    55175523                this.model.set( filter.props );
     
    57435749                }).render() );
    57445750
    5745                 this.toolbar.set( 'BulkSelection', new media.view.BulkSelection({
     5751                this.toolbar.set( 'bulkSelection', new media.view.BulkSelection({
    57465752                    controller: this.controller,
    57475753                    priority: -70
     5754                }).render() );
     5755                this.toolbar.set( 'dateFilter', new media.view.DateFilter({
     5756                    controller: this.controller,
     5757                    model:      this.collection.props,
     5758                    priority: -75
    57485759                }).render() );
    57495760            }
  • trunk/src/wp-includes/media.php

    r29212 r29271  
    27732773        return;
    27742774
    2775     global $content_width, $wpdb;
     2775    global $content_width, $wpdb, $wp_locale;
    27762776
    27772777    $defaults = array(
     
    28262826        LIMIT 1
    28272827    " );
     2828    $months = $wpdb->get_results( $wpdb->prepare( "
     2829        SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
     2830        FROM $wpdb->posts
     2831        WHERE post_type = %s
     2832        ORDER BY post_date DESC
     2833    ", 'attachment' ) );
     2834    foreach ( $months as $month_year ) {
     2835        $month_year->text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month_year->month ), $month_year->year );
     2836    }
    28282837
    28292838    $settings = array(
     
    28472856        'embedMimes'   => $ext_mimes,
    28482857        'contentWidth' => $content_width,
     2858        'months'       => $months,
    28492859    );
    28502860
     
    29052915        'allMediaItems'          => __( 'All media items' ),
    29062916        'allMediaTypes'          => __( 'All media types' ),
     2917        'allDates'               => __( 'All dates' ),
    29072918        'noItemsFound'           => __( 'No items found.' ),
    29082919        'insertIntoPost'         => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
Note: See TracChangeset for help on using the changeset viewer.