WordPress.org

Make WordPress Core

Changeset 22021


Ignore:
Timestamp:
09/26/2012 08:50:13 PM (7 years ago)
Author:
koopersmith
Message:

Media JS: Add support for filtering Attachment collections by mime type. see #21390, #21776, #21809.

Location:
trunk
Files:
2 edited

Legend:

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

    r21914 r22021  
    18031803function wp_ajax_query_attachments() {
    18041804    $query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
    1805     $query = array_intersect_key( $query, array_flip( array( 's', 'order', 'orderby', 'posts_per_page', 'paged' ) ) );
     1805    $query = array_intersect_key( $query, array_flip( array( 's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type' ) ) );
    18061806
    18071807    $query['post_type'] = 'attachment';
  • trunk/wp-includes/js/media-models.js

    r22013 r22021  
    225225            this.props.on( 'change:query',   this._changeQuery,   this );
    226226            this.props.on( 'change:search',  this._changeSearch,  this );
     227            this.props.on( 'change:type',    this._changeType,    this );
    227228
    228229            // Set the `props` model and fill the default property values.
     
    265266        },
    266267
    267         _changeSearch: function( model, term ) {
     268        _changeFilteredProp: function( prop, model, term ) {
    268269            // Bail if we're currently searching for the same term.
    269             if ( this.props.get('search') === term )
     270            if ( this.props.get( prop ) === term )
    270271                return;
    271272
    272             if ( term && ! this.filters.search )
    273                 this.filters.search = Attachments.filters.search;
    274             else if ( ! term && this.filters.search === Attachments.filters.search )
    275                 delete this.filters.search;
     273            if ( term && ! this.filters[ prop ] )
     274                this.filters[ prop ] = Attachments.filters[ prop ];
     275            else if ( ! term && this.filters[ prop ] === Attachments.filters[ prop ] )
     276                delete this.filters[ prop ];
    276277
    277278            // If no `Attachments` model is provided to source the searches
     
    282283
    283284            this.reset( this.props.get('source').filter( this.validator ) );
     285        },
     286
     287        _changeSearch: function( model, term ) {
     288            return this._changeFilteredProp( 'search', model, term );
     289        },
     290
     291        _changeType: function( model, term ) {
     292            return this._changeFilteredProp( 'type', model, term );
    284293        },
    285294
     
    381390                    return value && -1 !== value.search( this.props.get('search') );
    382391                }, this );
     392            },
     393
     394            type: function( attachment ) {
     395                var type = this.props.get('type');
     396                if ( ! type )
     397                    return true;
     398
     399                return -1 !== type.indexOf( attachment.get('type') );
    383400            }
    384401        }
     
    498515
    499516        propmap: {
    500             'search': 's'
     517            'search': 's',
     518            'type':   'post_mime_type'
    501519        },
    502520
Note: See TracChangeset for help on using the changeset viewer.