Ticket #28842: 28842.7.diff
| File 28842.7.diff, 10.4 KB (added by , 11 years ago) |
|---|
-
src/wp-includes/css/media-views.css
944 944 0 0 0 2px #1e8cbe; 945 945 } 946 946 947 .media-frame.mode-grid .attachment .check {948 display: block;949 }950 951 .media-frame.mode-grid .attachment .check div {952 background-position: 21px 0;953 }954 955 947 .attachment.details .check div, 956 948 .media-frame.mode-grid .attachment.selected .check div { 957 949 background-position: -21px 0; … … 997 989 .attachments-browser .media-toolbar-primary > .media-button-group, 998 990 .attachments-browser .media-toolbar-secondary > .media-button, 999 991 .attachments-browser .media-toolbar-secondary > .media-button-group { 1000 margin -top: 10px;992 margin: 11px 0; 1001 993 } 1002 994 1003 995 .attachments-browser .attachments, … … 2453 2445 2454 2446 /* Regions we don't use at all */ 2455 2447 .media-frame.mode-grid .media-frame-title, 2456 .media-frame.mode-grid .media-frame-toolbar,2457 2448 .media-frame.mode-grid .media-frame-router, 2458 2449 .media-frame.mode-grid .media-frame-menu { 2459 2450 display: none; … … 2539 2530 margin-top: 15px; 2540 2531 } 2541 2532 2533 .media-frame.mode-grid .delete-selected-button { 2534 margin: 11px 20px; 2535 } 2536 2542 2537 .media-frame.mode-grid .attachments-browser { 2543 2538 padding: 0; 2544 2539 } -
src/wp-includes/js/media-grid.js
62 62 multiple: 'add', 63 63 state: 'library', 64 64 uploader: true, 65 mode: [ 'grid' ]65 mode: [ 'grid', 'edit' ] 66 66 }); 67 67 68 68 $(document).on( 'click', '.add-new-h2', _.bind( this.addNewClickHandler, this ) ); … … 130 130 multiple: options.multiple, 131 131 title: options.title, 132 132 content: 'browse', 133 toolbar: 'select', 133 134 contentUserSetting: false, 134 135 filterable: 'all' 135 136 }) … … 144 145 145 146 // Handle a frame-level event for editing an attachment. 146 147 this.on( 'edit:attachment', this.openEditAttachmentModal, this ); 148 this.on( 'toolbar:render:select', this.toggleToolbar, this ); 149 this.on( 'select:activate edit:activate', this.toggleToolbar, this ); 147 150 }, 148 151 149 152 /** … … 219 222 pushState: true 220 223 } ); 221 224 } 225 }, 226 227 toggleToolbar: function() { 228 if ( this.isModeActive( 'edit' ) ) { 229 this.$el.addClass( 'hide-toolbar' ); 230 } else { 231 this.$el.removeClass( 'hide-toolbar' ); 232 } 222 233 } 223 234 }); 224 235 … … 542 553 } 543 554 }); 544 555 545 /** 546 * Controller for bulk selection. 547 */ 548 media.view.BulkSelection = media.View.extend({ 549 className: 'bulk-select', 550 556 media.view.SelectModeToggleButton = media.view.Button.extend({ 551 557 initialize: function() { 552 this.model = new Backbone.Model({553 currentAction: ''554 555 });556 557 this.views.add( new media.view.Label({558 value: l10n.bulkActionsLabel,559 attributes: {560 'for': 'bulk-select-dropdown'561 }562 }) );563 564 this.views.add(565 new media.view.BulkSelectionActionDropdown({566 controller: this567 })568 );569 570 this.views.add(571 new media.view.BulkSelectionActionButton({572 disabled: true,573 text: l10n.apply,574 controller: this575 })576 );577 }578 });579 580 /**581 * Bulk Selection dropdown view.582 *583 * @constructor584 * @augments wp.media.View585 * @augments wp.Backbone.View586 * @augments Backbone.View587 */588 media.view.BulkSelectionActionDropdown = media.View.extend({589 tagName: 'select',590 id: 'bulk-select-dropdown',591 592 initialize: function() {593 558 media.view.Button.prototype.initialize.apply( this, arguments ); 594 this.listenTo( this.controller.controller.state().get( 'selection' ), 'add remove reset', _.bind( this.enabled, this ) ); 595 this.$el.append( $('<option></option>').val( '' ).html( l10n.bulkActions ) ) 596 .append( $('<option></option>').val( 'delete' ).html( l10n.deletePermanently ) ); 597 this.$el.prop( 'disabled', true ); 598 this.$el.on( 'change', _.bind( this.changeHandler, this ) ); 559 this.listenTo( this.controller, 'select:activate select:deactivate', this.toggleBulkEditHandler ); 599 560 }, 600 561 601 /**602 * Change handler for the dropdown.603 *604 * Sets the bulk selection controller's currentAction.605 */606 changeHandler: function() {607 this.controller.model.set( { 'currentAction': this.$el.val() } );562 click: function() { 563 media.view.Button.prototype.click.apply( this, arguments ); 564 if ( this.controller.isModeActive( 'select' ) ) { 565 this.controller.deactivateMode( 'select' ).activateMode( 'edit' ); 566 } else { 567 this.controller.deactivateMode( 'edit' ).activateMode( 'select' ); 568 } 608 569 }, 609 570 610 /** 611 * Enable or disable the dropdown if attachments have been selected. 612 */ 613 enabled: function() { 614 var disabled = ! this.controller.controller.state().get('selection').length; 615 this.$el.prop( 'disabled', disabled ); 616 } 617 }); 571 render: function() { 572 media.view.Button.prototype.render.apply( this, arguments ); 573 this.$el.addClass( 'select-mode-toggle-button' ); 574 return this; 575 }, 618 576 619 /** 620 * Bulk Selection dropdown view. 621 * 622 * @constructor 623 * 624 * @augments wp.media.view.Button 625 * @augments wp.media.View 626 * @augments wp.Backbone.View 627 * @augments Backbone.View 628 */ 629 media.view.BulkSelectionActionButton = media.view.Button.extend({ 630 tagName: 'button', 577 toggleBulkEditHandler: function() { 578 var toolbar = this.controller.content.get().toolbar, children; 631 579 632 initialize: function() { 633 media.view.Button.prototype.initialize.apply( this, arguments ); 580 children = toolbar.$( '.media-toolbar-secondary > *, .media-toolbar-primary > *'); 634 581 635 this.listenTo( this.controller.model, 'change', this.enabled, this ); 636 this.listenTo( this.controller.controller.state().get( 'selection' ), 'add remove reset', _.bind( this.enabled, this ) ); 637 }, 638 /** 639 * Button click handler. 640 */ 641 click: function() { 642 var selection = this.controller.controller.state().get('selection'); 643 media.view.Button.prototype.click.apply( this, arguments ); 644 645 if ( 'delete' === this.controller.model.get( 'currentAction' ) ) { 646 // Currently assumes delete is the only action 647 if ( confirm( l10n.warnBulkDelete ) ) { 648 while ( selection.length > 0 ) { 649 selection.at(0).destroy(); 650 } 651 } 582 if ( this.controller.isModeActive( 'select' ) ) { 583 this.model.set( 'text', l10n.cancel ); 584 children.not( '.delete-selected-button' ).hide(); 585 toolbar.$( '.select-mode-toggle-button' ).show(); 586 toolbar.$( '.delete-selected-button' ).removeClass( 'hidden' ); 587 } else { 588 this.model.set( 'text', l10n.bulkSelect ); 589 toolbar.$( '.delete-selected-button' ).addClass( 'hidden' ); 590 children.not( '.spinner, .delete-selected-button' ).show(); 591 this.controller.state().get( 'selection' ).reset(); 652 592 } 593 } 594 }); 653 595 654 this.enabled(); 655 }, 656 /** 657 * Enable or disable the button depending if a bulk action is selected 658 * in the bulk select dropdown, and if attachments have been selected. 659 */ 660 enabled: function() { 661 var currentAction = this.controller.model.get( 'currentAction' ), 662 selection = this.controller.controller.state().get('selection'), 663 disabled = ! currentAction || ! selection.length; 664 this.$el.prop( 'disabled', disabled ); 596 media.view.DeleteSelectedButton = media.view.Button.extend({ 597 render: function() { 598 media.view.Button.prototype.render.apply( this, arguments ); 599 this.$el.addClass( 'delete-selected-button hidden' ); 600 return this; 665 601 } 666 602 }); 667 603 -
src/wp-includes/js/media-views.js
1792 1792 deactivateMode: function( mode ) { 1793 1793 // Bail if the mode isn't active. 1794 1794 if ( ! this.isModeActive( mode ) ) { 1795 return ;1795 return this; 1796 1796 } 1797 1797 this.activeModes.remove( this.activeModes.where( { id: mode } ) ); 1798 1798 this.$el.removeClass( 'mode-' + mode ); … … 4820 4820 } 4821 4821 4822 4822 // In the grid view, bubble up an edit:attachment event to the controller. 4823 if ( this.controller.isModeActive( 'grid' ) ) {4823 if ( this.controller.isModeActive( 'grid' ) && this.controller.isModeActive( 'edit' ) ) { 4824 4824 // Pass the current target to restore focus when closing 4825 4825 this.controller.trigger( 'edit:attachment', this.model, event.currentTarget ); 4826 4826 … … 5784 5784 priority: -90 5785 5785 }).render() ); 5786 5786 5787 // BulkSelection is a <div> with subviews, including screen reader text5788 this.toolbar.set( 'bulkSelection', new media.view.BulkSelection({5789 controller: this.controller,5790 priority: -705791 }).render() );5792 5793 5787 // DateFilter is a <select>, screen reader text needs to be rendered before 5794 5788 this.toolbar.set( 'dateFilterLabel', new media.view.Label({ 5795 5789 value: l10n.filterByDate, … … 5803 5797 model: this.collection.props, 5804 5798 priority: -75 5805 5799 }).render() ); 5800 5801 // BulkSelection is a <div> with subviews, including screen reader text 5802 this.toolbar.set( 'selectModeToggleButton', new media.view.SelectModeToggleButton({ 5803 text: l10n.bulkSelect, 5804 controller: this.controller, 5805 priority: -70 5806 }).render() ); 5807 5808 this.toolbar.set( 'deleteSelectedButton', new media.view.DeleteSelectedButton({ 5809 style: 'primary', 5810 text: l10n.deleteSelected, 5811 controller: this.controller, 5812 priority: -60, 5813 click: function() { 5814 while ( this.controller.state().get( 'selection' ).length > 0 ) { 5815 this.controller.state().get( 'selection' ).at( 0 ).destroy(); 5816 } 5817 } 5818 }).render() ); 5806 5819 } 5807 5820 5808 5821 this.toolbar.set( 'spinner', new media.view.Spinner({ -
src/wp-includes/media.php
2936 2936 'warnBulkDelete' => __( "You are about to permanently delete these items.\n 'Cancel' to stop, 'OK' to delete." ), 2937 2937 'bulkActions' => __( 'Bulk Actions' ), 2938 2938 'bulkActionsLabel' => __( 'Select bulk action' ), 2939 'bulkSelect' => __( 'Bulk Select' ), 2940 'deleteSelected' => __( 'Delete Selected' ), 2939 2941 'deletePermanently' => __( 'Delete Permanently' ), 2940 2942 'apply' => __( 'Apply' ), 2941 2943 'filterByDate' => __( 'Filter by date' ),