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:
Daryl Koopersmith 2012-11-09 12:37:21 +00:00
parent adf0c7e1a7
commit b9ed8db596
2 changed files with 31 additions and 10 deletions

View File

@ -600,7 +600,7 @@ window.wp = window.wp || {};
attachments: function( shortcode, parent ) {
var shortcodeString = shortcode.string(),
result = galleries[ shortcodeString ],
attrs, args, query;
attrs, args, query, others;
delete galleries[ shortcodeString ];
@ -627,15 +627,25 @@ window.wp = window.wp || {};
if ( ! args.post__in )
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.props.set( _.pick( attrs, 'columns', 'link' ) );
query.gallery = new Backbone.Model( others );
return query;
},
shortcode: function( attachments ) {
var props = attachments.props.toJSON(),
attrs = _.pick( props, 'include', 'exclude', 'orderby', 'order', 'link', 'columns' ),
shortcode;
attrs = _.pick( props, 'include', 'exclude', 'orderby', 'order' ),
shortcode, clone;
if ( attachments.gallery )
_.extend( attrs, attachments.gallery.toJSON() );
attrs.ids = attachments.pluck('id');
@ -651,9 +661,11 @@ window.wp = window.wp || {};
});
// 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
});
clone.gallery = attachments.gallery;
galleries[ shortcode.string() ] = clone;
return shortcode;
}
@ -705,19 +717,24 @@ window.wp = window.wp || {};
},
edit: function() {
var selection;
if ( ! wp.media.view || this.frame )
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({
frame: 'post',
state: 'gallery-edit',
title: mceview.l10n.editGallery,
editing: true,
multiple: true,
selection: new wp.media.model.Selection( this.attachments.models, {
props: this.attachments.props.toJSON(),
multiple: true
})
selection: selection
});
// Create a single-use frame. If the frame is closed,

View File

@ -1031,10 +1031,14 @@
// Sidebars
onSidebarGallerySettings: function( options ) {
var library = this.state().get('library');
library.gallery = library.gallery || new Backbone.Model();
this.sidebar.view().add({
gallery: new media.view.Settings.Gallery({
controller: this,
model: this.state().get('library').props,
model: library.gallery,
priority: 40
}).render()
}, options );