2015-02-22 07:56:27 +01:00
|
|
|
/*globals wp, _ */
|
|
|
|
|
2015-02-09 01:43:50 +01:00
|
|
|
/**
|
2015-02-22 08:25:27 +01:00
|
|
|
* wp.media.controller.GalleryAdd
|
|
|
|
*
|
2015-02-09 01:43:50 +01:00
|
|
|
* A state for selecting more images to add to a gallery.
|
|
|
|
*
|
|
|
|
* @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=gallery-library] Unique identifier.
|
|
|
|
* @param {string} [attributes.title=Add to Gallery] 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 all images 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.
|
|
|
|
*/
|
2015-02-09 05:14:26 +01:00
|
|
|
var Selection = wp.media.model.Selection,
|
2015-02-09 01:43:50 +01:00
|
|
|
Library = require( './library.js' ),
|
|
|
|
l10n = wp.media.view.l10n,
|
|
|
|
GalleryAdd;
|
|
|
|
|
|
|
|
GalleryAdd = Library.extend({
|
|
|
|
defaults: _.defaults({
|
|
|
|
id: 'gallery-library',
|
|
|
|
title: l10n.addToGalleryTitle,
|
|
|
|
multiple: 'add',
|
|
|
|
filterable: 'uploaded',
|
|
|
|
menu: 'gallery',
|
|
|
|
toolbar: 'gallery-add',
|
|
|
|
priority: 100,
|
|
|
|
syncSelection: false
|
|
|
|
}, Library.prototype.defaults ),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 3.5.0
|
|
|
|
*/
|
|
|
|
initialize: function() {
|
|
|
|
// If a library wasn't supplied, create a library of images.
|
2015-02-09 17:01:29 +01:00
|
|
|
if ( ! this.get('library') ) {
|
2015-02-09 01:43:50 +01:00
|
|
|
this.set( 'library', wp.media.query({ type: 'image' }) );
|
2015-02-09 17:01:29 +01:00
|
|
|
}
|
2015-02-09 01:43:50 +01:00
|
|
|
|
|
|
|
Library.prototype.initialize.apply( this, arguments );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 3.5.0
|
|
|
|
*/
|
|
|
|
activate: function() {
|
|
|
|
var library = this.get('library'),
|
|
|
|
edit = this.frame.state('gallery-edit').get('library');
|
|
|
|
|
2015-02-09 17:01:29 +01:00
|
|
|
if ( this.editLibrary && this.editLibrary !== edit ) {
|
2015-02-09 01:43:50 +01:00
|
|
|
library.unobserve( this.editLibrary );
|
2015-02-09 17:01:29 +01:00
|
|
|
}
|
2015-02-09 01:43:50 +01:00
|
|
|
|
|
|
|
// 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.editLibrary = edit;
|
|
|
|
|
|
|
|
Library.prototype.activate.apply( this, arguments );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-02-09 17:01:29 +01:00
|
|
|
module.exports = GalleryAdd;
|