Make WordPress Core

Changeset 22745


Ignore:
Timestamp:
11/21/2012 11:04:23 AM (12 years ago)
Author:
koopersmith
Message:

Media: Add filters for image-only libraries. see #22514, #21390.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/meta-boxes.php

    r22667 r22745  
    10561056            frame = wp.media( options );
    10571057
     1058            frame.get('library').set( 'filterable', 'uploaded' );
     1059
    10581060            frame.toolbar.on( 'activate:select', function() {
    10591061                frame.toolbar.view().set({
  • trunk/wp-includes/js/media-views.js

    r22743 r22745  
    13691369                    library:    media.query( options.library ),
    13701370                    editable:   true,
    1371                     filterable: true
     1371                    filterable: 'all'
    13721372                }, main ) ),
    13731373
     
    13851385
    13861386                new media.controller.Library( _.defaults({
    1387                     id:      'gallery-library',
    1388                     library: media.query({ type: 'image' })
     1387                    id:         'gallery-library',
     1388                    library:    media.query({ type: 'image' }),
     1389                    filterable: 'uploaded'
    13891390                }, gallery ) ),
    13901391
     
    27672768        },
    27682769
     2770        filters: {},
     2771        keys: [],
     2772
     2773        initialize: function() {
     2774            // Build `<option>` elements.
     2775            this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
     2776                return {
     2777                    el: this.make( 'option', { value: value }, filter.text ),
     2778                    priority: filter.priority || 50
     2779                };
     2780            }, this ).sortBy('priority').pluck('el').value() );
     2781
     2782            this.model.on( 'change', this.select, this );
     2783            this.select();
     2784        },
     2785
     2786        change: function( event ) {
     2787            var filter = this.filters[ this.el.value ];
     2788
     2789            if ( filter )
     2790                this.model.set( filter.props );
     2791        },
     2792
     2793        select: function() {
     2794            var model = this.model,
     2795                value = 'all',
     2796                props = model.toJSON();
     2797
     2798            _.find( this.filters, function( filter, id ) {
     2799                var equal = _.all( filter.props, function( prop, key ) {
     2800                    return prop === ( _.isUndefined( props[ key ] ) ? null : props[ key ] );
     2801                });
     2802
     2803                if ( equal )
     2804                    return value = id;
     2805            });
     2806
     2807            this.$el.val( value );
     2808        }
     2809    });
     2810
     2811    media.view.AttachmentFilters.Uploaded = media.view.AttachmentFilters.extend({
     2812        filters: {
     2813            all: {
     2814                text:  l10n.allMediaItems,
     2815                props: {
     2816                    parent: null
     2817                },
     2818                priority: 10
     2819            },
     2820
     2821            uploaded: {
     2822                text:  l10n.uploadedToThisPost,
     2823                props: {
     2824                    parent: media.view.settings.postId
     2825                },
     2826                priority: 20
     2827            }
     2828        }
     2829    });
     2830
     2831    media.view.AttachmentFilters.All = media.view.AttachmentFilters.extend({
    27692832        filters: (function() {
    27702833            var filters = {};
     
    27992862
    28002863            return filters;
    2801         }()),
    2802 
    2803         initialize: function() {
    2804             // Build `<option>` elements.
    2805             this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
    2806                 return {
    2807                     el: this.make( 'option', { value: value }, filter.text ),
    2808                     priority: filter.priority || 50
    2809                 };
    2810             }, this ).sortBy('priority').pluck('el').value() );
    2811 
    2812             this.model.on( 'change', this.select, this );
    2813             this.select();
    2814         },
    2815 
    2816         change: function( event ) {
    2817             var filter = this.filters[ this.el.value ];
    2818 
    2819             if ( filter )
    2820                 this.model.set( filter.props );
    2821         },
    2822 
    2823         select: function() {
    2824             var model = this.model,
    2825                 value = 'all',
    2826                 type = model.get('type'),
    2827                 parent = model.get('parent'),
    2828                 props = {
    2829                     parent: _.isUndefined( parent ) ? null : parent,
    2830                     type:   _.isUndefined( type ) ? null : type
    2831                 };
    2832 
    2833             _.find( this.filters, function( filter, key ) {
    2834                 if ( _.isEqual( filter.props, props ) )
    2835                     return value = key;
    2836             });
    2837 
    2838             this.$el.val( value );
    2839         }
     2864        }())
    28402865    });
    28412866
     
    28502875
    28512876        initialize: function() {
     2877            var filters, FiltersConstructor;
     2878
    28522879            this.controller = this.options.controller;
    28532880
     
    28642891            });
    28652892
    2866             if ( this.options.filters ) {
    2867                 this.toolbar.set( 'filters', new media.view.AttachmentFilters({
     2893            filters = this.options.filters;
     2894            if ( 'uploaded' === filters )
     2895                FiltersConstructor = media.view.AttachmentFilters.Uploaded;
     2896            else if ( 'all' === filters )
     2897                FiltersConstructor = media.view.AttachmentFilters.All;
     2898
     2899            if ( FiltersConstructor ) {
     2900                this.toolbar.set( 'filters', new FiltersConstructor({
    28682901                    controller: this.controller,
    28692902                    model:      this.collection.props,
Note: See TracChangeset for help on using the changeset viewer.