Register wp.media.controller.GalleryEdit
and wp.media.controller.GalleryAdd
using the new wp.media.controller.Collection*
abstraction code.
See #26631. git-svn-id: https://develop.svn.wordpress.org/trunk@27215 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
fc5a96502f
commit
2b06a387fe
@ -923,161 +923,24 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// wp.media.controller.GalleryEdit
|
||||||
* wp.media.controller.GalleryEdit
|
// -------------------------------
|
||||||
*
|
media.controller.GalleryEdit = media.controller.CollectionEdit( 'gallery', {
|
||||||
* @constructor
|
type: 'image',
|
||||||
* @augments wp.media.controller.Library
|
settings: 'Gallery',
|
||||||
* @augments wp.media.controller.State
|
|
||||||
* @augments Backbone.Model
|
|
||||||
*/
|
|
||||||
media.controller.GalleryEdit = media.controller.Library.extend({
|
|
||||||
defaults: {
|
defaults: {
|
||||||
id: 'gallery-edit',
|
title: l10n.editGalleryTitle
|
||||||
multiple: false,
|
|
||||||
describe: true,
|
|
||||||
edge: 199,
|
|
||||||
editing: false,
|
|
||||||
sortable: true,
|
|
||||||
searchable: false,
|
|
||||||
toolbar: 'gallery-edit',
|
|
||||||
content: 'browse',
|
|
||||||
title: l10n.editGalleryTitle,
|
|
||||||
priority: 60,
|
|
||||||
dragInfo: true,
|
|
||||||
|
|
||||||
// Don't sync the selection, as the Edit Gallery 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 );
|
|
||||||
},
|
|
||||||
|
|
||||||
activate: function() {
|
|
||||||
var library = this.get('library');
|
|
||||||
|
|
||||||
// Limit the library to images only.
|
|
||||||
library.props.set( 'type', 'image' );
|
|
||||||
|
|
||||||
// Watch for uploaded attachments.
|
|
||||||
this.get('library').observe( wp.Uploader.queue );
|
|
||||||
|
|
||||||
this.frame.on( 'content:render:browse', this.gallerySettings, 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.gallerySettings, this );
|
|
||||||
|
|
||||||
media.controller.Library.prototype.deactivate.apply( this, arguments );
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Object} browser
|
|
||||||
*/
|
|
||||||
gallerySettings: function( browser ) {
|
|
||||||
var library = this.get('library');
|
|
||||||
|
|
||||||
if ( ! library || ! browser ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
library.gallery = library.gallery || new Backbone.Model();
|
|
||||||
|
|
||||||
browser.sidebar.set({
|
|
||||||
gallery: new media.view.Settings.Gallery({
|
|
||||||
controller: this,
|
|
||||||
model: library.gallery,
|
|
||||||
priority: 40
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
browser.toolbar.set( 'reverse', {
|
|
||||||
text: l10n.reverseOrder,
|
|
||||||
priority: 80,
|
|
||||||
|
|
||||||
click: function() {
|
|
||||||
library.reset( library.toArray().reverse() );
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
// wp.media.controller.GalleryAdd
|
||||||
* wp.media.controller.GalleryAdd
|
// ---------------------------------
|
||||||
*
|
media.controller.GalleryAdd = media.controller.CollectionAdd( 'gallery', {
|
||||||
* @constructor
|
type: 'image',
|
||||||
* @augments wp.media.controller.Library
|
defaults: {
|
||||||
* @augments wp.media.controller.State
|
title: l10n.addToGalleryTitle
|
||||||
* @augments Backbone.Model
|
|
||||||
*/
|
|
||||||
media.controller.GalleryAdd = media.controller.Library.extend({
|
|
||||||
defaults: _.defaults({
|
|
||||||
id: 'gallery-library',
|
|
||||||
filterable: 'uploaded',
|
|
||||||
multiple: 'add',
|
|
||||||
menu: 'gallery',
|
|
||||||
toolbar: 'gallery-add',
|
|
||||||
title: l10n.addToGalleryTitle,
|
|
||||||
priority: 100,
|
|
||||||
|
|
||||||
// Don't sync the selection, as the Edit Gallery library
|
|
||||||
// *is* the selection.
|
|
||||||
syncSelection: false
|
|
||||||
}, media.controller.Library.prototype.defaults ),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If we haven't been provided a `library`, create a `Selection`.
|
|
||||||
*/
|
|
||||||
initialize: function() {
|
|
||||||
if ( ! this.get('library') ) {
|
|
||||||
this.set( 'library', media.query({ type: 'image' }) );
|
|
||||||
}
|
|
||||||
media.controller.Library.prototype.initialize.apply( this, arguments );
|
|
||||||
},
|
|
||||||
|
|
||||||
activate: function() {
|
|
||||||
var library = this.get('library'),
|
|
||||||
edit = this.frame.state('gallery-edit').get('library');
|
|
||||||
|
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wp.media.controller.FeaturedImage
|
* wp.media.controller.FeaturedImage
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user