- * @class
- * @augments wp.media.view.MediaFrame.Select
- * @augments wp.media.view.MediaFrame
- * @augments wp.media.view.Frame
- * @augments wp.media.View
- * @augments wp.Backbone.View
- * @augments Backbone.View
- * @mixes wp.media.controller.StateMachine
- */
- media.view.MediaFrame.Post = media.view.MediaFrame.Select.extend({
- initialize: function() {
- this.counts = {
- audio: {
- count: media.view.settings.attachmentCounts.audio,
- state: 'playlist'
- },
- video: {
- count: media.view.settings.attachmentCounts.video,
- state: 'video-playlist'
- }
- };
-
- _.defaults( this.options, {
- multiple: true,
- editing: false,
- state: 'insert',
- metadata: {}
- });
-
- // Call 'initialize' directly on the parent class.
- media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments );
- this.createIframeStates();
-
- },
-
- /**
- * Create the default states.
- */
- createStates: function() {
- var options = this.options;
-
- this.states.add([
- // Main states.
- new media.controller.Library({
- id: 'insert',
- title: l10n.insertMediaTitle,
- priority: 20,
- toolbar: 'main-insert',
- filterable: 'all',
- library: media.query( options.library ),
- multiple: options.multiple ? 'reset' : false,
- editable: true,
-
- // If the user isn't allowed to edit fields,
- // can they still edit it locally?
- allowLocalEdits: true,
-
- // Show the attachment display settings.
- displaySettings: true,
- // Update user settings when users adjust the
- // attachment display settings.
- displayUserSettings: true
- }),
-
- new media.controller.Library({
- id: 'gallery',
- title: l10n.createGalleryTitle,
- priority: 40,
- toolbar: 'main-gallery',
- filterable: 'uploaded',
- multiple: 'add',
- editable: false,
-
- library: media.query( _.defaults({
- type: 'image'
- }, options.library ) )
- }),
-
- // Embed states.
- new media.controller.Embed( { metadata: options.metadata } ),
-
- new media.controller.EditImage( { model: options.editImage } ),
-
- // Gallery states.
- new media.controller.GalleryEdit({
- library: options.selection,
- editing: options.editing,
- menu: 'gallery'
- }),
-
- new media.controller.GalleryAdd(),
-
- new media.controller.Library({
- id: 'playlist',
- title: l10n.createPlaylistTitle,
- priority: 60,
- toolbar: 'main-playlist',
- filterable: 'uploaded',
- multiple: 'add',
- editable: false,
-
- library: media.query( _.defaults({
- type: 'audio'
- }, options.library ) )
- }),
-
- // Playlist states.
- 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({
- type: 'audio',
- collectionType: 'playlist',
- title: l10n.addToPlaylistTitle
- }),
-
- new media.controller.Library({
- id: 'video-playlist',
- title: l10n.createVideoPlaylistTitle,
- priority: 60,
- toolbar: 'main-video-playlist',
- filterable: 'uploaded',
- multiple: 'add',
- editable: false,
-
- library: media.query( _.defaults({
- type: 'video'
- }, options.library ) )
- }),
-
- new media.controller.CollectionEdit({
- type: 'video',
- collectionType: '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({
- type: 'video',
- collectionType: 'playlist',
- title: l10n.addToVideoPlaylistTitle
- })
- ]);
-
- if ( media.view.settings.post.featuredImageId ) {
- this.states.add( new media.controller.FeaturedImage() );
- }
- },
-
- bindHandlers: function() {
- var handlers, checkCounts;
-
- media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments );
-
- this.on( 'activate', this.activate, this );
-
- // Only bother checking media type counts if one of the counts is zero
- checkCounts = _.find( this.counts, function( type ) {
- return type.count === 0;
- } );
-
- if ( typeof checkCounts !== 'undefined' ) {
- this.listenTo( media.model.Attachments.all, 'change:type', this.mediaTypeCounts );
- }
-
- this.on( 'menu:create:gallery', this.createMenu, this );
- this.on( 'menu:create:playlist', this.createMenu, this );
- this.on( 'menu:create:video-playlist', this.createMenu, this );
- this.on( 'toolbar:create:main-insert', this.createToolbar, this );
- this.on( 'toolbar:create:main-gallery', this.createToolbar, this );
- this.on( 'toolbar:create:main-playlist', this.createToolbar, this );
- this.on( 'toolbar:create:main-video-playlist', this.createToolbar, this );
- this.on( 'toolbar:create:featured-image', this.featuredImageToolbar, this );
- this.on( 'toolbar:create:main-embed', this.mainEmbedToolbar, this );
-
- handlers = {
- menu: {
- 'default': 'mainMenu',
- 'gallery': 'galleryMenu',
- 'playlist': 'playlistMenu',
- 'video-playlist': 'videoPlaylistMenu'
- },
-
- content: {
- 'embed': 'embedContent',
- 'edit-image': 'editImageContent',
- 'edit-selection': 'editSelectionContent'
- },
-
- toolbar: {
- 'main-insert': 'mainInsertToolbar',
- 'main-gallery': 'mainGalleryToolbar',
- 'gallery-edit': 'galleryEditToolbar',
- 'gallery-add': 'galleryAddToolbar',
- 'main-playlist': 'mainPlaylistToolbar',
- 'playlist-edit': 'playlistEditToolbar',
- 'playlist-add': 'playlistAddToolbar',
- 'main-video-playlist': 'mainVideoPlaylistToolbar',
- 'video-playlist-edit': 'videoPlaylistEditToolbar',
- 'video-playlist-add': 'videoPlaylistAddToolbar'
- }
- };
-
- _.each( handlers, function( regionHandlers, region ) {
- _.each( regionHandlers, function( callback, handler ) {
- this.on( region + ':render:' + handler, this[ callback ], this );
- }, this );
- }, this );
- },
-
- activate: function() {
- // Hide menu items for states tied to particular media types if there are no items
- _.each( this.counts, function( type ) {
- if ( type.count < 1 ) {
- this.menuItemVisibility( type.state, 'hide' );
- }
- }, this );
- },
-
- mediaTypeCounts: function( model, attr ) {
- if ( typeof this.counts[ attr ] !== 'undefined' && this.counts[ attr ].count < 1 ) {
- this.counts[ attr ].count++;
- this.menuItemVisibility( this.counts[ attr ].state, 'show' );
- }
- },
-
- // Menus
- /**
- * @param {wp.Backbone.View} view
- */
- mainMenu: function( view ) {
- view.set({
- 'library-separator': new media.View({
- className: 'separator',
- priority: 100
- })
- });
- },
-
- menuItemVisibility: function( state, visibility ) {
- var menu = this.menu.get();
- if ( visibility === 'hide' ) {
- menu.hide( state );
- } else if ( visibility === 'show' ) {
- menu.show( state );
- }
- },
- /**
- * @param {wp.Backbone.View} view
- */
- galleryMenu: function( view ) {
- var lastState = this.lastState(),
- previous = lastState && lastState.id,
- frame = this;
-
- view.set({
- cancel: {
- text: l10n.cancelGalleryTitle,
- priority: 20,
- click: function() {
- if ( previous ) {
- frame.setState( previous );
- } else {
- frame.close();
- }
-
- // Keep focus inside media modal
- // after canceling a gallery
- this.controller.modal.focusManager.focus();
- }
- },
- separateCancel: new media.View({
- className: 'separator',
- priority: 40
- })
- });
- },
-
- playlistMenu: function( view ) {
- var lastState = this.lastState(),
- previous = lastState && lastState.id,
- frame = this;
-
- view.set({
- cancel: {
- text: l10n.cancelPlaylistTitle,
- priority: 20,
- click: function() {
- if ( previous ) {
- frame.setState( previous );
- } else {
- frame.close();
- }
- }
- },
- separateCancel: new media.View({
- className: 'separator',
- priority: 40
- })
- });
- },
-
- videoPlaylistMenu: function( view ) {
- var lastState = this.lastState(),
- previous = lastState && lastState.id,
- frame = this;
-
- view.set({
- cancel: {
- text: l10n.cancelVideoPlaylistTitle,
- priority: 20,
- click: function() {
- if ( previous ) {
- frame.setState( previous );
- } else {
- frame.close();
- }
- }
- },
- separateCancel: new media.View({
- className: 'separator',
- priority: 40
- })
- });
- },
-
- // Content
- embedContent: function() {
- var view = new media.view.Embed({
- controller: this,
- model: this.state()
- }).render();