Media: Add batch insertion workflow. see #21390.

git-svn-id: https://develop.svn.wordpress.org/trunk@22480 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Daryl Koopersmith 2012-11-09 01:44:02 +00:00
parent c4556dce6b
commit b9a5374e64
3 changed files with 143 additions and 33 deletions

View File

@ -107,11 +107,12 @@ var tb_position;
multiple: true multiple: true
} ) ); } ) );
workflow.on( 'insert', function() { workflow.on( 'insert', function( selection ) {
var state = workflow.state(), var state = workflow.state(),
selection = state.get('selection'),
details = state.get('details'); details = state.get('details');
selection = selection || state.get('selection');
if ( ! selection || ! details ) if ( ! selection || ! details )
return; return;

View File

@ -700,7 +700,7 @@
createStates: function() { createStates: function() {
var options = this.options, var options = this.options,
main, gallery; main, gallery, batch;
main = { main = {
multiple: this.options.multiple, multiple: this.options.multiple,
@ -713,13 +713,22 @@
}; };
gallery = { gallery = {
multiple: true, multiple: true,
menu: 'gallery', menu: 'gallery',
toolbar: 'gallery-add' toolbar: 'gallery-add',
excludeState: 'gallery-edit'
};
batch = {
multiple: true,
menu: 'batch',
toolbar: 'batch-add',
excludeState: 'batch-edit'
}; };
// Add the default states. // Add the default states.
this.states.add([ this.states.add([
// Main states.
new media.controller.Library( _.defaults({ new media.controller.Library( _.defaults({
selection: options.selection, selection: options.selection,
library: media.query( options.library ) library: media.query( options.library )
@ -727,6 +736,7 @@
new media.controller.Upload( main ), new media.controller.Upload( main ),
// Gallery states.
new media.controller.Gallery({ new media.controller.Gallery({
editing: options.editing, editing: options.editing,
menu: 'gallery' menu: 'gallery'
@ -734,14 +744,33 @@
new media.controller.Library( _.defaults({ new media.controller.Library( _.defaults({
id: 'gallery-library', id: 'gallery-library',
library: media.query({ type: 'image' }), library: media.query({ type: 'image' })
excludeState: 'gallery-edit'
}, gallery ) ), }, gallery ) ),
new media.controller.Upload( _.defaults({ new media.controller.Upload( _.defaults({
id: 'gallery-upload', id: 'gallery-upload'
excludeState: 'gallery-edit' }, gallery ) ),
}, gallery ) )
// Batch states.
new media.controller.Library({
id: 'batch-edit',
multiple: false,
describe: true,
edge: 199,
sortable: true,
menu: 'batch',
toolbar: 'batch-edit',
sidebar: 'attachment-settings'
}),
new media.controller.Library( _.defaults({
id: 'batch-library',
library: media.query({ type: 'image' })
}, batch ) ),
new media.controller.Upload( _.defaults({
id: 'batch-upload'
}, batch ) )
]); ]);
// Set the default state. // Set the default state.
@ -773,7 +802,42 @@
}) ); }) );
}, },
batchMenu: function() {}, batchMenu: function() {
var previous = this.previous(),
frame = this;
this.menu.view( new media.view.Menu({
controller: this,
views: {
cancel: {
text: l10n.cancelBatchTitle,
priority: 20,
click: function() {
if ( previous )
frame.state( previous );
else
frame.close();
}
},
separateCancel: new Backbone.View({
className: 'separator',
priority: 40
}),
'batch-edit': {
text: l10n.editBatchTitle,
priority: 60
},
'batch-upload': {
text: l10n.uploadFilesTitle,
priority: 80
},
'batch-library': {
text: l10n.mediaLibraryTitle,
priority: 100
}
}
}) );
},
galleryMenu: function() { galleryMenu: function() {
var previous = this.previous(), var previous = this.previous(),
@ -810,7 +874,6 @@
} }
} }
}) ); }) );
}, },
// Content // Content
@ -900,8 +963,54 @@
}, },
mainEmbedToolbar: function() {}, mainEmbedToolbar: function() {},
batchEditToolbar: function() {},
batchAddToolbar: function() {}, batchEditToolbar: function() {
this.toolbar.view( new media.view.Toolbar({
controller: this,
items: {
insert: {
style: 'primary',
text: l10n.insertIntoPost,
priority: 80,
click: function() {
var controller = this.controller,
state = controller.state();
controller.close();
state.trigger( 'insert', state.get('library') );
controller.reset();
// @todo: Make the state activated dynamic (instead of hardcoded).
controller.state('upload');
}
}
}
}) );
},
batchAddToolbar: function() {
this.toolbar.view( new media.view.Toolbar({
controller: this,
items: {
insert: {
style: 'primary',
text: l10n.addToBatch,
priority: 80,
click: function() {
var controller = this.controller,
state = controller.state(),
edit = controller.get('batch-edit');
edit.get('library').add( state.get('selection').models );
state.trigger('reset');
controller.state('batch-edit');
}
}
}
}) );
},
galleryEditToolbar: function() { galleryEditToolbar: function() {
var editing = this.state().get('editing'); var editing = this.state().get('editing');
@ -1292,32 +1401,32 @@
// --------------------------------- // ---------------------------------
media.view.Toolbar.Insert.Post = media.view.Toolbar.Insert.extend({ media.view.Toolbar.Insert.Post = media.view.Toolbar.Insert.extend({
initialize: function() { initialize: function() {
this.options.items = _.defaults( this.options.items || {}, { var selectionToLibrary = function( state ) {
gallery: { return function() {
text: l10n.createNewGallery,
priority: 40,
click: function() {
var controller = this.controller, var controller = this.controller,
selection = controller.state().get('selection'), selection = controller.state().get('selection'),
edit = controller.get('gallery-edit'); edit = controller.get( state );
edit.set( 'library', new media.model.Selection( selection.models, { edit.set( 'library', new media.model.Selection( selection.models, {
props: selection.props.toJSON(), props: selection.props.toJSON(),
multiple: true multiple: true
}) ); }) );
this.controller.state('gallery-edit'); this.controller.state( state );
} };
};
this.options.items = _.defaults( this.options.items || {}, {
gallery: {
text: l10n.createNewGallery,
priority: 40,
click: selectionToLibrary('gallery-edit')
}, },
batch: { batch: {
text: l10n.batchInsert, text: l10n.batchInsert,
priority: 60, priority: 60,
click: selectionToLibrary('batch-edit')
click: function() {
this.controller.state('batch-edit');
}
} }
}); });
@ -1337,12 +1446,10 @@
}) ); }) );
// Batch insert shows for multiple selected attachments. // Batch insert shows for multiple selected attachments.
// Temporarily disabled with `false &&`. this.get('batch').$el.toggle( count > 1 );
this.get('batch').$el.toggle( false && count > 1 );
// Insert only shows for single attachments. // Insert only shows for single attachments.
// Temporarily disabled. this.get('insert').$el.toggle( count <= 1 );
// this.get('insert').$el.toggle( count <= 1 );
} }
}); });

View File

@ -338,7 +338,6 @@ function wp_default_scripts( &$scripts ) {
'mediaLibraryTitle' => __( 'Media Library' ), 'mediaLibraryTitle' => __( 'Media Library' ),
'createNewGallery' => __( 'Create a new gallery' ), 'createNewGallery' => __( 'Create a new gallery' ),
'insertIntoPost' => __( 'Insert into post' ), 'insertIntoPost' => __( 'Insert into post' ),
'addToGallery' => __( 'Add to gallery' ),
// Embed // Embed
'embedFromUrlTitle' => __( 'Embed From URL' ), 'embedFromUrlTitle' => __( 'Embed From URL' ),
@ -346,6 +345,8 @@ function wp_default_scripts( &$scripts ) {
// Batch // Batch
'batchInsert' => __( 'Batch insert' ), 'batchInsert' => __( 'Batch insert' ),
'cancelBatchTitle' => __( '&#8592; Cancel Batch' ), 'cancelBatchTitle' => __( '&#8592; Cancel Batch' ),
'editBatchTitle' => __( 'Edit Batch' ),
'addToBatch' => __( 'Add to batch' ),
// Gallery // Gallery
'createGalleryTitle' => __( 'Create Gallery' ), 'createGalleryTitle' => __( 'Create Gallery' ),
@ -354,6 +355,7 @@ function wp_default_scripts( &$scripts ) {
'insertGallery' => __( 'Insert gallery' ), 'insertGallery' => __( 'Insert gallery' ),
'updateGallery' => __( 'Update gallery' ), 'updateGallery' => __( 'Update gallery' ),
'continueEditing' => __( 'Continue editing' ), 'continueEditing' => __( 'Continue editing' ),
'addToGallery' => __( 'Add to gallery' ),
) ); ) );
$scripts->add( 'shortcode', "/wp-includes/js/shortcode$suffix.js", array( 'underscore' ), false, 1 ); $scripts->add( 'shortcode', "/wp-includes/js/shortcode$suffix.js", array( 'underscore' ), false, 1 );