Media Grid:

Instead of a separate bulk selection mode, persistently show a checkbox for each item. Restores the more familiar bulk actions dropdown + action button.

props ericlewis. see #28842.


Built from https://develop.svn.wordpress.org/trunk@29212


git-svn-id: http://core.svn.wordpress.org/trunk@28996 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Helen Hou-Sandí 2014-07-17 20:42:15 +00:00
parent 4361a40427
commit 06f5b5a490
10 changed files with 179 additions and 118 deletions

View File

@ -913,7 +913,7 @@
} }
.attachment.details .check, .attachment.details .check,
.media-grid-view .attachment .check { .media-grid-view .attachment.selected .check {
background-color: #1e8cbe; background-color: #1e8cbe;
-webkit-box-shadow: 0 0 0 1px #fff, -webkit-box-shadow: 0 0 0 1px #fff,
0 0 0 2px #1e8cbe; 0 0 0 2px #1e8cbe;
@ -921,13 +921,21 @@
0 0 0 2px #1e8cbe; 0 0 0 2px #1e8cbe;
} }
.attachment.details .check div, .media-grid-view .attachment .check {
display: block;
}
.media-grid-view .attachment .check div { .media-grid-view .attachment .check div {
background-position: 21px 0;
}
.attachment.details .check div,
.media-grid-view .attachment.selected .check div {
background-position: -21px 0; background-position: -21px 0;
} }
.attachment.details .check:hover div, .attachment.details .check:hover div,
.media-grid-view .attachment .check:hover div { .media-grid-view .attachment.selected .check:hover div {
background-position: -60px 0; background-position: -60px 0;
} }
@ -1051,7 +1059,7 @@
display: inline-block; display: inline-block;
} }
.attachment:hover .inline-toolbar { .attachment-preview:hover ~ .inline-toolbar {
display: block; display: block;
} }
@ -2600,12 +2608,21 @@ video#inline-media-node {
margin-top: 0; margin-top: 0;
} }
.media-grid-view .media-toolbar select {
margin-top: 1px;
font-size: inherit;
}
.media-grid-view .attachments-browser .bulk-select {
display: inline-block;
}
/** /**
* Copied styles from the Add theme toolbar. * Copied styles from the Add theme toolbar.
* *
* This should be OOCSS'd so both use a shared selector. * This should be OOCSS'd so both use a shared selector.
*/ */
.media-grid-view .media-toolbar { .media-grid-view .attachments-browser .media-toolbar {
background: #fff; background: #fff;
-webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1); -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1); box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
@ -2643,7 +2660,7 @@ video#inline-media-node {
margin: 0 0 0 20px; margin: 0 0 0 20px;
} }
.media-grid-view select.attachment-filters { .media-grid-view select {
margin: 0 0 0 10px; margin: 0 0 0 10px;
} }
@ -2729,7 +2746,7 @@ video#inline-media-node {
font-weight: 300; font-weight: 300;
} }
.media-frame.mode-bulk-edit .attachment:hover .inline-toolbar { .media-frame.mode-bulk-edit .attachment-preview:hover ~ .inline-toolbar {
display: none; display: none;
} }
@ -2911,9 +2928,13 @@ video#inline-media-node {
margin-top: 3px; margin-top: 3px;
} }
/**
* Media queries for media grid.
*/
@media only screen and (max-width: 1120px) { @media only screen and (max-width: 1120px) {
.media-grid-view .media-toolbar-primary, .media-grid-view .attachments-browser .media-toolbar-primary,
.media-grid-view .media-toolbar-secondary { .media-grid-view .attachments-browser .media-toolbar-secondary {
float: none; float: none;
} }
@ -2924,4 +2945,3 @@ video#inline-media-node {
max-width: none !important; max-width: none !important;
} }
} }

File diff suppressed because one or more lines are too long

View File

@ -913,7 +913,7 @@
} }
.attachment.details .check, .attachment.details .check,
.media-grid-view .attachment .check { .media-grid-view .attachment.selected .check {
background-color: #1e8cbe; background-color: #1e8cbe;
-webkit-box-shadow: 0 0 0 1px #fff, -webkit-box-shadow: 0 0 0 1px #fff,
0 0 0 2px #1e8cbe; 0 0 0 2px #1e8cbe;
@ -921,13 +921,21 @@
0 0 0 2px #1e8cbe; 0 0 0 2px #1e8cbe;
} }
.attachment.details .check div, .media-grid-view .attachment .check {
display: block;
}
.media-grid-view .attachment .check div { .media-grid-view .attachment .check div {
background-position: 21px 0;
}
.attachment.details .check div,
.media-grid-view .attachment.selected .check div {
background-position: -21px 0; background-position: -21px 0;
} }
.attachment.details .check:hover div, .attachment.details .check:hover div,
.media-grid-view .attachment .check:hover div { .media-grid-view .attachment.selected .check:hover div {
background-position: -60px 0; background-position: -60px 0;
} }
@ -1051,7 +1059,7 @@
display: inline-block; display: inline-block;
} }
.attachment:hover .inline-toolbar { .attachment-preview:hover ~ .inline-toolbar {
display: block; display: block;
} }
@ -2600,12 +2608,21 @@ video#inline-media-node {
margin-top: 0; margin-top: 0;
} }
.media-grid-view .media-toolbar select {
margin-top: 1px;
font-size: inherit;
}
.media-grid-view .attachments-browser .bulk-select {
display: inline-block;
}
/** /**
* Copied styles from the Add theme toolbar. * Copied styles from the Add theme toolbar.
* *
* This should be OOCSS'd so both use a shared selector. * This should be OOCSS'd so both use a shared selector.
*/ */
.media-grid-view .media-toolbar { .media-grid-view .attachments-browser .media-toolbar {
background: #fff; background: #fff;
-webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1); -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1); box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
@ -2643,7 +2660,7 @@ video#inline-media-node {
margin: 0 20px 0 0; margin: 0 20px 0 0;
} }
.media-grid-view select.attachment-filters { .media-grid-view select {
margin: 0 10px 0 0; margin: 0 10px 0 0;
} }
@ -2729,7 +2746,7 @@ video#inline-media-node {
font-weight: 300; font-weight: 300;
} }
.media-frame.mode-bulk-edit .attachment:hover .inline-toolbar { .media-frame.mode-bulk-edit .attachment-preview:hover ~ .inline-toolbar {
display: none; display: none;
} }
@ -2911,9 +2928,13 @@ video#inline-media-node {
margin-top: 3px; margin-top: 3px;
} }
/**
* Media queries for media grid.
*/
@media only screen and (max-width: 1120px) { @media only screen and (max-width: 1120px) {
.media-grid-view .media-toolbar-primary, .media-grid-view .attachments-browser .media-toolbar-primary,
.media-grid-view .media-toolbar-secondary { .media-grid-view .attachments-browser .media-toolbar-secondary {
float: none; float: none;
} }
@ -2924,4 +2945,3 @@ video#inline-media-node {
max-width: none !important; max-width: none !important;
} }
} }

File diff suppressed because one or more lines are too long

View File

@ -184,27 +184,25 @@
}, },
createStates: function() { createStates: function() {
var options = this.options, var options = this.options;
libraryState;
if ( this.options.states ) { if ( this.options.states ) {
return; return;
} }
libraryState = new media.controller.Library({ // Add the default states.
this.states.add([
new media.controller.Library({
library: media.query( options.library ), library: media.query( options.library ),
multiple: options.multiple, multiple: options.multiple,
title: options.title, title: options.title,
priority: 20, priority: 20,
toolbar: false,
router: false, router: false,
content: 'browse', content: 'browse',
filterable: 'mime-types'
});
// Add the default states. filterable: 'mime-types'
this.states.add([ })
libraryState
]); ]);
}, },
@ -254,7 +252,6 @@
filters: state.get('filterable'), filters: state.get('filterable'),
display: state.get('displaySettings'), display: state.get('displaySettings'),
dragInfo: state.get('dragInfo'), dragInfo: state.get('dragInfo'),
bulkEdit: true,
sidebar: false, sidebar: false,
suggestedWidth: state.get('suggestedWidth'), suggestedWidth: state.get('suggestedWidth'),
@ -606,55 +603,81 @@
} }
}); });
media.view.BulkSelectionToggleButton = media.view.Button.extend({ media.view.BulkSelection = media.View.extend({
className: 'bulk-select',
initialize: function() { initialize: function() {
media.view.Button.prototype.initialize.apply( this, arguments ); this.model = new Backbone.Model({
this.listenTo( this.controller, 'bulk-edit:activate bulk-edit:deactivate', _.bind( this.toggleBulkEditHandler, this ) ); currentAction: '',
},
click: function() { });
var bulkEditActive = this.controller.activeModes.where( { id: 'bulk-edit' } ).length;
media.view.Button.prototype.click.apply( this, arguments );
if ( bulkEditActive ) { this.views.add(
this.controller.deactivateMode( 'bulk-edit' ).activateMode( 'edit' ); new media.view.BulkSelectionActionDropdown({
} else { controller: this
this.controller.deactivateMode( 'edit' ).activateMode( 'bulk-edit' ); })
} );
},
toggleBulkEditHandler: function() { this.views.add(
var bulkEditActive = this.controller.activeModes.where( { id: 'bulk-edit' } ).length; new media.view.BulkSelectionActionButton({
if ( bulkEditActive ) { disabled: true,
this.$el.addClass( 'button-primary' ); text: l10n.apply,
} else { controller: this
this.$el.removeClass( 'button-primary' ); })
this.controller.state().get('selection').reset(); );
}
} }
}); });
media.view.BulkDeleteButton = media.view.Button.extend({ media.view.BulkSelectionActionDropdown = media.View.extend({
tagName: 'select',
initialize: function() { initialize: function() {
media.view.Button.prototype.initialize.apply( this, arguments ); media.view.Button.prototype.initialize.apply( this, arguments );
this.$el.hide(); this.listenTo( this.controller.controller.state().get( 'selection' ), 'add remove reset', _.bind( this.enabled, this ) );
this.listenTo( this.controller, 'bulk-edit:activate bulk-edit:deactivate', _.bind( this.visibility, this ) ); this.$el.append( $('<option></option>').val( '' ).html( l10n.bulkActions ) )
.append( $('<option></option>').val( 'delete' ).html( l10n.deletePermanently ) );
this.$el.prop( 'disabled', true );
this.$el.on( 'change', _.bind( this.toggleChange, this ) );
},
toggleChange: function() {
this.controller.model.set( { 'currentAction': this.$el.val() } );
},
enabled: function() {
var disabled = ! this.controller.controller.state().get('selection').length;
this.$el.prop( 'disabled', disabled );
}
});
media.view.BulkSelectionActionButton = media.view.Button.extend({
tagName: 'button',
initialize: function() {
media.view.Button.prototype.initialize.apply( this, arguments );
this.listenTo( this.controller.model, 'change', this.enabled, this );
this.listenTo( this.controller.controller.state().get( 'selection' ), 'add remove reset', _.bind( this.enabled, this ) );
}, },
click: function() { click: function() {
var selection = this.controller.controller.state().get('selection');
media.view.Button.prototype.click.apply( this, arguments ); media.view.Button.prototype.click.apply( this, arguments );
while (this.controller.state().get('selection').length > 0) {
this.controller.state().get('selection').at(0).destroy(); // Currently assumes delete is the only action
if ( confirm( l10n.warnBulkDelete ) ) {
while ( selection.length > 0) {
selection.at(0).destroy();
} }
}
this.enabled();
}, },
visibility: function() { enabled: function() {
var bulkEditActive = this.controller.activeModes.where( { id: 'bulk-edit' } ).length; var currentAction = this.controller.model.get( 'currentAction' ),
if ( bulkEditActive ) { selection = this.controller.controller.state().get('selection'),
this.$el.show(); disabled = ! currentAction || ! selection.length;
} else { this.$el.prop( 'disabled', disabled );
this.$el.hide();
}
} }
}); });

File diff suppressed because one or more lines are too long

View File

@ -4619,7 +4619,7 @@
'change [data-setting] select': 'updateSetting', 'change [data-setting] select': 'updateSetting',
'change [data-setting] textarea': 'updateSetting', 'change [data-setting] textarea': 'updateSetting',
'click .close': 'removeFromLibrary', 'click .close': 'removeFromLibrary',
'click .check': 'removeFromSelection', 'click .check': 'checkClickHandler',
'click a': 'preventDefault', 'click a': 'preventDefault',
'keydown': 'toggleSelectionHandler' 'keydown': 'toggleSelectionHandler'
}, },
@ -4879,12 +4879,8 @@
return; return;
} }
// In bulk edit mode (in media grid), attachments don't open the "details"
// pane, so a `details` class is unnecessary on the attachment view.
if ( ! this.controller.isModeActive( 'bulk-edit' ) ) {
details = selection.single(); details = selection.single();
this.$el.toggleClass( 'details', details === this.model ); this.$el.toggleClass( 'details', details === this.model );
}
}, },
/** /**
* @param {Object} event * @param {Object} event
@ -5015,19 +5011,25 @@
this.collection.remove( this.model ); this.collection.remove( this.model );
}, },
/** /**
* @param {Object} event * Add the model if it isn't in the selection, if it is in the selection,
* remove it.
*
* @param {[type]} event [description]
* @return {[type]} [description]
*/ */
removeFromSelection: function( event ) { checkClickHandler: function ( event ) {
var selection = this.options.selection; var selection = this.options.selection;
if ( ! selection ) { if ( ! selection ) {
return; return;
} }
// Stop propagation so the model isn't selected.
event.stopPropagation(); event.stopPropagation();
if ( selection.where( { id: this.model.get( 'id' ) } ).length ) {
selection.remove( this.model ); selection.remove( this.model );
} else {
selection.add( this.model );
}
} }
}); });
@ -5657,17 +5659,10 @@
priority: -90 priority: -90
}).render() ); }).render() );
this.toolbar.set( 'bulkSelectionToggleButton', new media.view.BulkSelectionToggleButton({ this.toolbar.set( 'BulkSelection', new media.view.BulkSelection({
text: 'Bulk Edit',
controller: this.controller, controller: this.controller,
priority: -70 priority: -70
}).render() ); }).render() );
this.toolbar.set( 'BulkDeleteButton', new media.view.BulkDeleteButton({
text: 'Bulk Delete',
controller: this.controller,
priority: -69
}).render() );
} }
filters = this.options.filters; filters = this.options.filters;

File diff suppressed because one or more lines are too long

View File

@ -397,11 +397,6 @@ function wp_print_media_templates() {
</script> </script>
<script type="text/html" id="tmpl-attachment"> <script type="text/html" id="tmpl-attachment">
<# if ( _.contains( data.controller.options.mode, 'grid' ) ) { #>
<div class="inline-toolbar js--select-attachment">
<div class="dashicons dashicons-edit edit edit-media"></div>
</div>
<# } #>
<div class="attachment-preview js--select-attachment type-{{ data.type }} subtype-{{ data.subtype }} {{ data.orientation }}"> <div class="attachment-preview js--select-attachment type-{{ data.type }} subtype-{{ data.subtype }} {{ data.orientation }}">
<# if ( data.uploading ) { #> <# if ( data.uploading ) { #>
<div class="media-progress-bar"><div></div></div> <div class="media-progress-bar"><div></div></div>
@ -424,11 +419,15 @@ function wp_print_media_templates() {
<# if ( data.buttons.close ) { #> <# if ( data.buttons.close ) { #>
<a class="close media-modal-icon" href="#" title="<?php esc_attr_e('Remove'); ?>"></a> <a class="close media-modal-icon" href="#" title="<?php esc_attr_e('Remove'); ?>"></a>
<# } #> <# } #>
</div>
<# if ( _.contains( data.controller.options.mode, 'grid' ) ) { #>
<div class="inline-toolbar js--select-attachment">
<div class="dashicons dashicons-edit edit edit-media"></div>
</div>
<# } #>
<# if ( data.buttons.check ) { #> <# if ( data.buttons.check ) { #>
<a class="check" href="#" title="<?php esc_attr_e('Deselect'); ?>" tabindex="-1"><div class="media-modal-icon"></div></a> <a class="check" href="#" title="<?php esc_attr_e('Deselect'); ?>" tabindex="-1"><div class="media-modal-icon"></div></a>
<# } #> <# } #>
</div>
<# <#
var maybeReadOnly = data.can.save || data.allowLocalEdits ? '' : 'readonly'; var maybeReadOnly = data.can.save || data.allowLocalEdits ? '' : 'readonly';
if ( data.describe ) { if ( data.describe ) {

View File

@ -2908,6 +2908,10 @@ function wp_enqueue_media( $args = array() ) {
'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ), 'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ), 'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ),
'warnDelete' => __( "You are about to permanently delete this item.\n 'Cancel' to stop, 'OK' to delete." ), 'warnDelete' => __( "You are about to permanently delete this item.\n 'Cancel' to stop, 'OK' to delete." ),
'warnBulkDelete' => __( "You are about to permanently delete these items.\n 'Cancel' to stop, 'OK' to delete." ),
'bulkActions' => __( 'Bulk Actions' ),
'deletePermanently' => __( 'Delete Permanently' ),
'apply' => __( 'Apply' ),
// Library Details // Library Details
'attachmentDetails' => __( 'Attachment Details' ), 'attachmentDetails' => __( 'Attachment Details' ),