Media: Keep track of gallery display properties in a separate model instead of mixed in with the query parameters. This allows for arbitrary gallery arguments and a more flexible data structure. see #21390.
git-svn-id: http://core.svn.wordpress.org/trunk@22508 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
adf0c7e1a7
commit
b9ed8db596
|
@ -600,7 +600,7 @@ window.wp = window.wp || {};
|
||||||
attachments: function( shortcode, parent ) {
|
attachments: function( shortcode, parent ) {
|
||||||
var shortcodeString = shortcode.string(),
|
var shortcodeString = shortcode.string(),
|
||||||
result = galleries[ shortcodeString ],
|
result = galleries[ shortcodeString ],
|
||||||
attrs, args, query;
|
attrs, args, query, others;
|
||||||
|
|
||||||
delete galleries[ shortcodeString ];
|
delete galleries[ shortcodeString ];
|
||||||
|
|
||||||
|
@ -627,15 +627,25 @@ window.wp = window.wp || {};
|
||||||
if ( ! args.post__in )
|
if ( ! args.post__in )
|
||||||
args.parent = attrs.id || parent;
|
args.parent = attrs.id || parent;
|
||||||
|
|
||||||
|
// Collect the attributes that were not included in `args`.
|
||||||
|
others = {};
|
||||||
|
_.filter( attrs, function( value, key ) {
|
||||||
|
if ( _.isUndefined( args[ key ] ) )
|
||||||
|
others[ key ] = value;
|
||||||
|
});
|
||||||
|
|
||||||
query = media.query( args );
|
query = media.query( args );
|
||||||
query.props.set( _.pick( attrs, 'columns', 'link' ) );
|
query.gallery = new Backbone.Model( others );
|
||||||
return query;
|
return query;
|
||||||
},
|
},
|
||||||
|
|
||||||
shortcode: function( attachments ) {
|
shortcode: function( attachments ) {
|
||||||
var props = attachments.props.toJSON(),
|
var props = attachments.props.toJSON(),
|
||||||
attrs = _.pick( props, 'include', 'exclude', 'orderby', 'order', 'link', 'columns' ),
|
attrs = _.pick( props, 'include', 'exclude', 'orderby', 'order' ),
|
||||||
shortcode;
|
shortcode, clone;
|
||||||
|
|
||||||
|
if ( attachments.gallery )
|
||||||
|
_.extend( attrs, attachments.gallery.toJSON() );
|
||||||
|
|
||||||
attrs.ids = attachments.pluck('id');
|
attrs.ids = attachments.pluck('id');
|
||||||
|
|
||||||
|
@ -651,9 +661,11 @@ window.wp = window.wp || {};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Use a cloned version of the gallery.
|
// Use a cloned version of the gallery.
|
||||||
galleries[ shortcode.string() ] = new wp.media.model.Attachments( attachments.models, {
|
clone = new wp.media.model.Attachments( attachments.models, {
|
||||||
props: props
|
props: props
|
||||||
});
|
});
|
||||||
|
clone.gallery = attachments.gallery;
|
||||||
|
galleries[ shortcode.string() ] = clone;
|
||||||
|
|
||||||
return shortcode;
|
return shortcode;
|
||||||
}
|
}
|
||||||
|
@ -705,19 +717,24 @@ window.wp = window.wp || {};
|
||||||
},
|
},
|
||||||
|
|
||||||
edit: function() {
|
edit: function() {
|
||||||
|
var selection;
|
||||||
|
|
||||||
if ( ! wp.media.view || this.frame )
|
if ( ! wp.media.view || this.frame )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
selection = new wp.media.model.Selection( this.attachments.models, {
|
||||||
|
props: this.attachments.props.toJSON(),
|
||||||
|
multiple: true
|
||||||
|
});
|
||||||
|
selection.gallery = this.attachments.gallery;
|
||||||
|
|
||||||
this.frame = wp.media({
|
this.frame = wp.media({
|
||||||
frame: 'post',
|
frame: 'post',
|
||||||
state: 'gallery-edit',
|
state: 'gallery-edit',
|
||||||
title: mceview.l10n.editGallery,
|
title: mceview.l10n.editGallery,
|
||||||
editing: true,
|
editing: true,
|
||||||
multiple: true,
|
multiple: true,
|
||||||
selection: new wp.media.model.Selection( this.attachments.models, {
|
selection: selection
|
||||||
props: this.attachments.props.toJSON(),
|
|
||||||
multiple: true
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create a single-use frame. If the frame is closed,
|
// Create a single-use frame. If the frame is closed,
|
||||||
|
|
|
@ -1031,10 +1031,14 @@
|
||||||
|
|
||||||
// Sidebars
|
// Sidebars
|
||||||
onSidebarGallerySettings: function( options ) {
|
onSidebarGallerySettings: function( options ) {
|
||||||
|
var library = this.state().get('library');
|
||||||
|
|
||||||
|
library.gallery = library.gallery || new Backbone.Model();
|
||||||
|
|
||||||
this.sidebar.view().add({
|
this.sidebar.view().add({
|
||||||
gallery: new media.view.Settings.Gallery({
|
gallery: new media.view.Settings.Gallery({
|
||||||
controller: this,
|
controller: this,
|
||||||
model: this.state().get('library').props,
|
model: library.gallery,
|
||||||
priority: 40
|
priority: 40
|
||||||
}).render()
|
}).render()
|
||||||
}, options );
|
}, options );
|
||||||
|
|
Loading…
Reference in New Issue