mirror of
https://github.com/WordPress/WordPress.git
synced 2024-08-31 10:09:46 +02:00
* The way that the JS modules for media are currently set up turns the existing global `wp.media` namespace into a read-only API, this is bad. * For the existing module implementation to work with plugins, those looking to override or extend a class would have to modify their own plugin to use `browserify` - we can't expect this to happen * Because the general way that plugins override media classes is via machete (resetting them to something else), we cannot use `require( 'module' )` in the internal code for media modules We CAN continue to use `require( 'fun/js' )` in the manifests for media. Future code/projects should carefully consider what is made to be public API. In 3.5, EVERYTHING was made public, so everything shall remain public. See #31684, #28510. Built from https://develop.svn.wordpress.org/trunk@31935 git-svn-id: http://core.svn.wordpress.org/trunk@31914 1a063a9b-81f0-0310-95a4-ce76da25c4cd
102 lines
5.1 KiB
JavaScript
102 lines
5.1 KiB
JavaScript
/*globals wp, _ */
|
|
|
|
/**
|
|
* wp.media.controller.CollectionAdd
|
|
*
|
|
* A state for adding attachments to a collection (e.g. video playlist).
|
|
*
|
|
* @class
|
|
* @augments wp.media.controller.Library
|
|
* @augments wp.media.controller.State
|
|
* @augments Backbone.Model
|
|
*
|
|
* @param {object} [attributes] The attributes hash passed to the state.
|
|
* @param {string} [attributes.id=library] Unique identifier.
|
|
* @param {string} attributes.title Title for the state. Displays in the frame's title region.
|
|
* @param {boolean} [attributes.multiple=add] Whether multi-select is enabled. @todo 'add' doesn't seem do anything special, and gets used as a boolean.
|
|
* @param {wp.media.model.Attachments} [attributes.library] The attachments collection to browse.
|
|
* If one is not supplied, a collection of attachments of the specified type will be created.
|
|
* @param {boolean|string} [attributes.filterable=uploaded] Whether the library is filterable, and if so what filters should be shown.
|
|
* Accepts 'all', 'uploaded', or 'unattached'.
|
|
* @param {string} [attributes.menu=gallery] Initial mode for the menu region.
|
|
* @param {string} [attributes.content=upload] Initial mode for the content region.
|
|
* Overridden by persistent user setting if 'contentUserSetting' is true.
|
|
* @param {string} [attributes.router=browse] Initial mode for the router region.
|
|
* @param {string} [attributes.toolbar=gallery-add] Initial mode for the toolbar region.
|
|
* @param {boolean} [attributes.searchable=true] Whether the library is searchable.
|
|
* @param {boolean} [attributes.sortable=true] Whether the Attachments should be sortable. Depends on the orderby property being set to menuOrder on the attachments collection.
|
|
* @param {boolean} [attributes.autoSelect=true] Whether an uploaded attachment should be automatically added to the selection.
|
|
* @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user.
|
|
* @param {int} [attributes.priority=100] The priority for the state link in the media menu.
|
|
* @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state.
|
|
* Defaults to false because for this state, because the library of the Edit Gallery state is the selection.
|
|
* @param {string} attributes.type The collection's media type. (e.g. 'video').
|
|
* @param {string} attributes.collectionType The collection type. (e.g. 'playlist').
|
|
*/
|
|
var Selection = wp.media.model.Selection,
|
|
Library = wp.media.controller.Library,
|
|
CollectionAdd;
|
|
|
|
CollectionAdd = Library.extend({
|
|
defaults: _.defaults( {
|
|
// Selection defaults. @see media.model.Selection
|
|
multiple: 'add',
|
|
// Attachments browser defaults. @see media.view.AttachmentsBrowser
|
|
filterable: 'uploaded',
|
|
|
|
priority: 100,
|
|
syncSelection: false
|
|
}, Library.prototype.defaults ),
|
|
|
|
/**
|
|
* @since 3.9.0
|
|
*/
|
|
initialize: function() {
|
|
var collectionType = this.get('collectionType');
|
|
|
|
if ( 'video' === this.get( 'type' ) ) {
|
|
collectionType = 'video-' + collectionType;
|
|
}
|
|
|
|
this.set( 'id', collectionType + '-library' );
|
|
this.set( 'toolbar', collectionType + '-add' );
|
|
this.set( 'menu', collectionType );
|
|
|
|
// If we haven't been provided a `library`, create a `Selection`.
|
|
if ( ! this.get('library') ) {
|
|
this.set( 'library', wp.media.query({ type: this.get('type') }) );
|
|
}
|
|
Library.prototype.initialize.apply( this, arguments );
|
|
},
|
|
|
|
/**
|
|
* @since 3.9.0
|
|
*/
|
|
activate: function() {
|
|
var library = this.get('library'),
|
|
editLibrary = this.get('editLibrary'),
|
|
edit = this.frame.state( this.get('collectionType') + '-edit' ).get('library');
|
|
|
|
if ( editLibrary && editLibrary !== edit ) {
|
|
library.unobserve( 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 ) && 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.set('editLibrary', edit);
|
|
|
|
Library.prototype.activate.apply( this, arguments );
|
|
}
|
|
});
|
|
|
|
module.exports = CollectionAdd;
|