Make `CollectionEdit` and `CollectionAdd` less dynamically quirky. Rename some instance properties for disambiguation. Pass some properties from `options` when creating instances in `wp.media.view.MediaFrame.Post`.
See #26631. Props gcorne. Built from https://develop.svn.wordpress.org/trunk@27362 git-svn-id: http://core.svn.wordpress.org/trunk@27212 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
330f27f095
commit
c0a9ee8452
|
@ -762,107 +762,107 @@
|
|||
/**
|
||||
* wp.media.controller.CollectionEdit
|
||||
*
|
||||
* @static
|
||||
* @param {string} prop The shortcode slug
|
||||
* @param {object} args
|
||||
* @returns {wp.media.controller.Library}
|
||||
* @constructor
|
||||
* @augments wp.media.controller.Library
|
||||
* @augments wp.media.controller.State
|
||||
* @augments Backbone.Model
|
||||
*/
|
||||
media.controller.CollectionEdit = function ( prop, args ) {
|
||||
/**
|
||||
* @constructor
|
||||
* @augments wp.media.controller.Library
|
||||
* @augments wp.media.controller.State
|
||||
* @augments Backbone.Model
|
||||
*/
|
||||
return media.controller.Library.extend({
|
||||
defaults : _.defaults(args.defaults || {}, {
|
||||
id: prop + '-edit',
|
||||
toolbar: prop + '-edit',
|
||||
multiple: false,
|
||||
describe: true,
|
||||
edge: 199,
|
||||
editing: false,
|
||||
sortable: true,
|
||||
searchable: false,
|
||||
content: 'browse',
|
||||
priority: 60,
|
||||
dragInfo: true,
|
||||
media.controller.CollectionEdit = media.controller.Library.extend({
|
||||
defaults: {
|
||||
multiple: false,
|
||||
describe: true,
|
||||
edge: 199,
|
||||
editing: false,
|
||||
sortable: true,
|
||||
searchable: false,
|
||||
content: 'browse',
|
||||
priority: 60,
|
||||
dragInfo: true,
|
||||
SettingsView: false,
|
||||
|
||||
// Don't sync the selection, as the Edit {Collection} library
|
||||
// *is* the selection.
|
||||
syncSelection: false
|
||||
}),
|
||||
// Don't sync the selection, as the Edit {Collection} library
|
||||
// *is* the selection.
|
||||
syncSelection: false
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
// If we haven't been provided a `library`, create a `Selection`.
|
||||
if ( ! this.get('library') ) {
|
||||
this.set( 'library', new media.model.Selection() );
|
||||
}
|
||||
// The single `Attachment` view to be used in the `Attachments` view.
|
||||
if ( ! this.get('AttachmentView') ) {
|
||||
this.set( 'AttachmentView', media.view.Attachment.EditLibrary );
|
||||
}
|
||||
media.controller.Library.prototype.initialize.apply( this, arguments );
|
||||
},
|
||||
initialize: function() {
|
||||
var collectionType = this.get('collectionType');
|
||||
|
||||
activate: function() {
|
||||
var library = this.get('library');
|
||||
this.set( 'id', collectionType + '-edit' );
|
||||
this.set( 'toolbar', collectionType + '-edit' );
|
||||
|
||||
// Limit the library to images only.
|
||||
library.props.set( 'type', args.type );
|
||||
|
||||
// Watch for uploaded attachments.
|
||||
this.get('library').observe( wp.Uploader.queue );
|
||||
|
||||
this.frame.on( 'content:render:browse', this.settings, this );
|
||||
|
||||
media.controller.Library.prototype.activate.apply( this, arguments );
|
||||
},
|
||||
|
||||
deactivate: function() {
|
||||
// Stop watching for uploaded attachments.
|
||||
this.get('library').unobserve( wp.Uploader.queue );
|
||||
|
||||
this.frame.off( 'content:render:browse', this.settings, this );
|
||||
|
||||
media.controller.Library.prototype.deactivate.apply( this, arguments );
|
||||
},
|
||||
|
||||
settings: function( browser ) {
|
||||
var library = this.get('library'), obj = {};
|
||||
|
||||
if ( ! library || ! browser ) {
|
||||
return;
|
||||
}
|
||||
|
||||
library[ prop ] = library[ prop ] || new Backbone.Model();
|
||||
|
||||
obj[ prop ] = new media.view.Settings[ args.settings ]({
|
||||
controller: this,
|
||||
model: library[ prop ],
|
||||
priority: 40
|
||||
});
|
||||
|
||||
browser.sidebar.set( obj );
|
||||
|
||||
if ( args.dragInfoText ) {
|
||||
browser.toolbar.set( 'dragInfo', new media.View({
|
||||
el: $( '<div class="instructions">' + args.dragInfoText + '</div>' )[0],
|
||||
priority: -40
|
||||
}) );
|
||||
}
|
||||
|
||||
browser.toolbar.set( 'reverse', {
|
||||
text: l10n.reverseOrder,
|
||||
priority: 80,
|
||||
|
||||
click: function() {
|
||||
library.reset( library.toArray().reverse() );
|
||||
}
|
||||
});
|
||||
// If we haven't been provided a `library`, create a `Selection`.
|
||||
if ( ! this.get('library') ) {
|
||||
this.set( 'library', new media.model.Selection() );
|
||||
}
|
||||
});
|
||||
};
|
||||
// The single `Attachment` view to be used in the `Attachments` view.
|
||||
if ( ! this.get('AttachmentView') ) {
|
||||
this.set( 'AttachmentView', media.view.Attachment.EditLibrary );
|
||||
}
|
||||
media.controller.Library.prototype.initialize.apply( this, arguments );
|
||||
},
|
||||
|
||||
activate: function() {
|
||||
var library = this.get('library');
|
||||
|
||||
// Limit the library to images only.
|
||||
library.props.set( 'type', this.get( 'type' ) );
|
||||
|
||||
// Watch for uploaded attachments.
|
||||
this.get('library').observe( wp.Uploader.queue );
|
||||
|
||||
this.frame.on( 'content:render:browse', this.renderSettings, this );
|
||||
|
||||
media.controller.Library.prototype.activate.apply( this, arguments );
|
||||
},
|
||||
|
||||
deactivate: function() {
|
||||
// Stop watching for uploaded attachments.
|
||||
this.get('library').unobserve( wp.Uploader.queue );
|
||||
|
||||
this.frame.off( 'content:render:browse', this.renderSettings, this );
|
||||
|
||||
media.controller.Library.prototype.deactivate.apply( this, arguments );
|
||||
},
|
||||
|
||||
renderSettings: function( browser ) {
|
||||
var library = this.get('library'),
|
||||
collectionType = this.get('collectionType'),
|
||||
dragInfoText = this.get('dragInfoText'),
|
||||
SettingsView = this.get('SettingsView'),
|
||||
obj = {};
|
||||
|
||||
if ( ! library || ! browser ) {
|
||||
return;
|
||||
}
|
||||
|
||||
library[ collectionType ] = library[ collectionType ] || new Backbone.Model();
|
||||
|
||||
obj[ collectionType ] = new SettingsView({
|
||||
controller: this,
|
||||
model: library[ collectionType ],
|
||||
priority: 40
|
||||
});
|
||||
|
||||
browser.sidebar.set( obj );
|
||||
|
||||
if ( dragInfoText ) {
|
||||
browser.toolbar.set( 'dragInfo', new media.View({
|
||||
el: $( '<div class="instructions">' + dragInfoText + '</div>' )[0],
|
||||
priority: -40
|
||||
}) );
|
||||
}
|
||||
|
||||
browser.toolbar.set( 'reverse', {
|
||||
text: l10n.reverseOrder,
|
||||
priority: 80,
|
||||
|
||||
click: function() {
|
||||
library.reset( library.toArray().reverse() );
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* wp.media.controller.CollectionAdd
|
||||
|
@ -872,87 +872,51 @@
|
|||
* @augments wp.media.controller.State
|
||||
* @augments Backbone.Model
|
||||
*/
|
||||
media.controller.CollectionAdd = function (attributes) {
|
||||
var ExtendedLibrary, extended = _.extend( attributes, {
|
||||
defaults: _.defaults( {
|
||||
id: attributes.tag + '-library',
|
||||
title: attributes.title,
|
||||
menu: attributes.tag,
|
||||
toolbar: attributes.tag + '-add',
|
||||
filterable: 'uploaded',
|
||||
multiple: 'add',
|
||||
priority: 100,
|
||||
syncSelection: false
|
||||
}, media.controller.Library.prototype.defaults ),
|
||||
media.controller.CollectionAdd = media.controller.Library.extend({
|
||||
defaults: _.defaults( {
|
||||
filterable: 'uploaded',
|
||||
multiple: 'add',
|
||||
priority: 100,
|
||||
syncSelection: false
|
||||
}, media.controller.Library.prototype.defaults ),
|
||||
|
||||
initialize: function() {
|
||||
// If we haven't been provided a `library`, create a `Selection`.
|
||||
if ( ! this.get('library') ) {
|
||||
this.set( 'library', media.query({ type: this.type }) );
|
||||
}
|
||||
media.controller.Library.prototype.initialize.apply( this, arguments );
|
||||
},
|
||||
initialize: function() {
|
||||
var collectionType = this.get('collectionType');
|
||||
|
||||
activate: function() {
|
||||
var library = this.get('library'),
|
||||
edit = this.frame.state( this.tag + '-edit' ).get('library');
|
||||
this.set( 'id', collectionType + '-library' );
|
||||
this.set( 'toolbar', collectionType + '-add' );
|
||||
this.set( 'menu', collectionType );
|
||||
|
||||
if ( this.editLibrary && this.editLibrary !== edit ) {
|
||||
library.unobserve( this.editLibrary );
|
||||
}
|
||||
|
||||
// Accepts attachments that exist in the original library and
|
||||
// that do not exist in gallery's library.
|
||||
library.validator = function( attachment ) {
|
||||
return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && media.model.Selection.prototype.validator.apply( this, arguments );
|
||||
};
|
||||
|
||||
// Reset the library to ensure that all attachments are re-added
|
||||
// to the collection. Do so silently, as calling `observe` will
|
||||
// trigger the `reset` event.
|
||||
library.reset( library.mirroring.models, { silent: true });
|
||||
library.observe( edit );
|
||||
this.editLibrary = edit;
|
||||
|
||||
media.controller.Library.prototype.activate.apply( this, arguments );
|
||||
// If we haven't been provided a `library`, create a `Selection`.
|
||||
if ( ! this.get('library') ) {
|
||||
this.set( 'library', media.query({ type: this.get('type') }) );
|
||||
}
|
||||
} );
|
||||
ExtendedLibrary = media.controller.Library.extend( extended );
|
||||
media.controller.Library.prototype.initialize.apply( this, arguments );
|
||||
},
|
||||
|
||||
return new ExtendedLibrary();
|
||||
};
|
||||
activate: function() {
|
||||
var library = this.get('library'),
|
||||
editLibrary = this.get('editLibrary'),
|
||||
edit = this.frame.state( this.get('collectionType') + '-edit' ).get('library');
|
||||
|
||||
// wp.media.controller.GalleryEdit
|
||||
// -------------------------------
|
||||
media.controller.GalleryEdit = media.controller.CollectionEdit( 'gallery', {
|
||||
type: 'image',
|
||||
settings: 'Gallery',
|
||||
defaults: {
|
||||
title: l10n.editGalleryTitle
|
||||
}
|
||||
});
|
||||
if ( editLibrary && editLibrary !== edit ) {
|
||||
library.unobserve( editLibrary );
|
||||
}
|
||||
|
||||
// wp.media.controller.PlaylistEdit
|
||||
// -------------------------------
|
||||
media.controller.PlaylistEdit = media.controller.CollectionEdit( 'playlist', {
|
||||
type: 'audio',
|
||||
settings: 'Playlist',
|
||||
dragInfoText: l10n.playlistDragInfo,
|
||||
defaults: {
|
||||
title: l10n.editPlaylistTitle,
|
||||
dragInfo : false
|
||||
}
|
||||
});
|
||||
// Accepts attachments that exist in the original library and
|
||||
// that do not exist in gallery's library.
|
||||
library.validator = function( attachment ) {
|
||||
return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && media.model.Selection.prototype.validator.apply( this, arguments );
|
||||
};
|
||||
|
||||
// wp.media.controller.VideoPlaylistEdit
|
||||
// -------------------------------
|
||||
media.controller.VideoPlaylistEdit = media.controller.CollectionEdit( 'video-playlist', {
|
||||
type: 'video',
|
||||
settings: 'Playlist',
|
||||
dragInfoText: l10n.videoPlaylistDragInfo,
|
||||
defaults: {
|
||||
title: l10n.editVideoPlaylistTitle,
|
||||
dragInfo : false
|
||||
// Reset the library to ensure that all attachments are re-added
|
||||
// to the collection. Do so silently, as calling `observe` will
|
||||
// trigger the `reset` event.
|
||||
library.reset( library.mirroring.models, { silent: true });
|
||||
library.observe( edit );
|
||||
this.set('editLibrary', edit);
|
||||
|
||||
media.controller.Library.prototype.activate.apply( this, arguments );
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1776,16 +1740,20 @@
|
|||
new media.controller.Embed(),
|
||||
|
||||
// Gallery states.
|
||||
new media.controller.GalleryEdit({
|
||||
library: options.selection,
|
||||
editing: options.editing,
|
||||
menu: 'gallery'
|
||||
new media.controller.CollectionEdit({
|
||||
type: 'image',
|
||||
collectionType: 'gallery',
|
||||
title: l10n.editGalleryTitle,
|
||||
SettingsView: media.view.Settings.Gallery,
|
||||
library: options.selection,
|
||||
editing: options.editing,
|
||||
menu: 'gallery'
|
||||
}),
|
||||
|
||||
new media.controller.CollectionAdd({
|
||||
tag: 'gallery',
|
||||
type: 'image',
|
||||
title: l10n.addToGalleryTitle
|
||||
type: 'image',
|
||||
collectionType: 'gallery',
|
||||
title: l10n.addToGalleryTitle
|
||||
}),
|
||||
|
||||
new media.controller.Library({
|
||||
|
@ -1803,15 +1771,21 @@
|
|||
}),
|
||||
|
||||
// Playlist states.
|
||||
new media.controller.PlaylistEdit({
|
||||
library: options.selection,
|
||||
editing: options.editing,
|
||||
menu: 'playlist'
|
||||
new media.controller.CollectionEdit({
|
||||
type: 'audio',
|
||||
collectionType: 'playlist',
|
||||
title: l10n.editPlaylistTitle,
|
||||
SettingsView: media.view.Settings.Playlist,
|
||||
library: options.selection,
|
||||
editing: options.editing,
|
||||
menu: 'playlist',
|
||||
dragInfoText: l10n.playlistDragInfo,
|
||||
dragInfo: false
|
||||
}),
|
||||
|
||||
new media.controller.CollectionAdd({
|
||||
tag: 'playlist',
|
||||
type: 'audio',
|
||||
collectionType: 'playlist',
|
||||
title: l10n.addToPlaylistTitle
|
||||
}),
|
||||
|
||||
|
@ -1830,16 +1804,22 @@
|
|||
}),
|
||||
|
||||
// Video Playlist states.
|
||||
new media.controller.VideoPlaylistEdit({
|
||||
library: options.selection,
|
||||
editing: options.editing,
|
||||
menu: 'video-playlist'
|
||||
new media.controller.CollectionEdit({
|
||||
type: 'video',
|
||||
collectionType: 'video-playlist',
|
||||
title: l10n.editVideoPlaylistTitle,
|
||||
SettingsView: media.view.Settings.Playlist,
|
||||
library: options.selection,
|
||||
editing: options.editing,
|
||||
menu: 'video-playlist',
|
||||
dragInfoText: l10n.videoPlaylistDragInfo,
|
||||
dragInfo: false
|
||||
}),
|
||||
|
||||
new media.controller.CollectionAdd({
|
||||
tag: 'video-playlist',
|
||||
type: 'video',
|
||||
title: l10n.addToVideoPlaylistTitle
|
||||
type: 'video',
|
||||
collectionType: 'video-playlist',
|
||||
title: l10n.addToVideoPlaylistTitle
|
||||
})
|
||||
]);
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue