Media JS: Add support for filtering Attachment collections by mime type. see #21390, #21776, #21809.
git-svn-id: https://develop.svn.wordpress.org/trunk@22021 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5453d7d84d
commit
4a90e0541a
@ -1802,7 +1802,7 @@ function wp_ajax_get_attachment() {
|
|||||||
*/
|
*/
|
||||||
function wp_ajax_query_attachments() {
|
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( 's', 'order', 'orderby', 'posts_per_page', 'paged' ) ) );
|
$query = array_intersect_key( $query, array_flip( array( 's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type' ) ) );
|
||||||
|
|
||||||
$query['post_type'] = 'attachment';
|
$query['post_type'] = 'attachment';
|
||||||
$query['post_status'] = 'inherit';
|
$query['post_status'] = 'inherit';
|
||||||
|
@ -224,6 +224,7 @@ if ( typeof wp === 'undefined' )
|
|||||||
this.props.on( 'change:orderby', this._changeOrderby, this );
|
this.props.on( 'change:orderby', this._changeOrderby, this );
|
||||||
this.props.on( 'change:query', this._changeQuery, this );
|
this.props.on( 'change:query', this._changeQuery, this );
|
||||||
this.props.on( 'change:search', this._changeSearch, this );
|
this.props.on( 'change:search', this._changeSearch, this );
|
||||||
|
this.props.on( 'change:type', this._changeType, this );
|
||||||
|
|
||||||
// Set the `props` model and fill the default property values.
|
// Set the `props` model and fill the default property values.
|
||||||
this.props.set( _.defaults( options.props || {}, {
|
this.props.set( _.defaults( options.props || {}, {
|
||||||
@ -264,15 +265,15 @@ if ( typeof wp === 'undefined' )
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_changeSearch: function( model, term ) {
|
_changeFilteredProp: function( prop, model, term ) {
|
||||||
// Bail if we're currently searching for the same term.
|
// Bail if we're currently searching for the same term.
|
||||||
if ( this.props.get('search') === term )
|
if ( this.props.get( prop ) === term )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( term && ! this.filters.search )
|
if ( term && ! this.filters[ prop ] )
|
||||||
this.filters.search = Attachments.filters.search;
|
this.filters[ prop ] = Attachments.filters[ prop ];
|
||||||
else if ( ! term && this.filters.search === Attachments.filters.search )
|
else if ( ! term && this.filters[ prop ] === Attachments.filters[ prop ] )
|
||||||
delete this.filters.search;
|
delete this.filters[ prop ];
|
||||||
|
|
||||||
// If no `Attachments` model is provided to source the searches
|
// If no `Attachments` model is provided to source the searches
|
||||||
// from, then automatically generate a source from the existing
|
// from, then automatically generate a source from the existing
|
||||||
@ -283,6 +284,14 @@ if ( typeof wp === 'undefined' )
|
|||||||
this.reset( this.props.get('source').filter( this.validator ) );
|
this.reset( this.props.get('source').filter( this.validator ) );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_changeSearch: function( model, term ) {
|
||||||
|
return this._changeFilteredProp( 'search', model, term );
|
||||||
|
},
|
||||||
|
|
||||||
|
_changeType: function( model, term ) {
|
||||||
|
return this._changeFilteredProp( 'type', model, term );
|
||||||
|
},
|
||||||
|
|
||||||
validator: function( attachment ) {
|
validator: function( attachment ) {
|
||||||
return _.all( this.filters, function( filter, key ) {
|
return _.all( this.filters, function( filter, key ) {
|
||||||
return !! filter.call( this, attachment );
|
return !! filter.call( this, attachment );
|
||||||
@ -380,6 +389,14 @@ if ( typeof wp === 'undefined' )
|
|||||||
var value = attachment.get( key );
|
var value = attachment.get( key );
|
||||||
return value && -1 !== value.search( this.props.get('search') );
|
return value && -1 !== value.search( this.props.get('search') );
|
||||||
}, this );
|
}, this );
|
||||||
|
},
|
||||||
|
|
||||||
|
type: function( attachment ) {
|
||||||
|
var type = this.props.get('type');
|
||||||
|
if ( ! type )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return -1 !== type.indexOf( attachment.get('type') );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -497,7 +514,8 @@ if ( typeof wp === 'undefined' )
|
|||||||
},
|
},
|
||||||
|
|
||||||
propmap: {
|
propmap: {
|
||||||
'search': 's'
|
'search': 's',
|
||||||
|
'type': 'post_mime_type'
|
||||||
},
|
},
|
||||||
|
|
||||||
// Caches query objects so queries can be easily reused.
|
// Caches query objects so queries can be easily reused.
|
||||||
|
Loading…
Reference in New Issue
Block a user