Make WordPress Core

Changeset 22480


Ignore:
Timestamp:
11/09/2012 01:44:02 AM (14 years ago)
Author:
koopersmith
Message:

Media: Add batch insertion workflow. see #21390.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/media-upload.js

    r22466 r22480  
    108108                        } ) );
    109109
    110                         workflow.on( 'insert', function() {
     110                        workflow.on( 'insert', function( selection ) {
    111111                                var state = workflow.state(),
    112                                         selection = state.get('selection'),
    113112                                        details = state.get('details');
     113
     114                                selection = selection || state.get('selection');
    114115
    115116                                if ( ! selection || ! details )
  • trunk/wp-includes/js/media-views.js

    r22478 r22480  
    701701                createStates: function() {
    702702                        var options = this.options,
    703                                 main, gallery;
     703                                main, gallery, batch;
    704704
    705705                        main = {
     
    714714
    715715                        gallery = {
    716                                 multiple: true,
    717                                 menu:     'gallery',
    718                                 toolbar:  'gallery-add'
     716                                multiple:     true,
     717                                menu:         'gallery',
     718                                toolbar:      'gallery-add',
     719                                excludeState: 'gallery-edit'
     720                        };
     721
     722                        batch = {
     723                                multiple:     true,
     724                                menu:         'batch',
     725                                toolbar:      'batch-add',
     726                                excludeState: 'batch-edit'
    719727                        };
    720728
    721729                        // Add the default states.
    722730                        this.states.add([
     731                                // Main states.
    723732                                new media.controller.Library( _.defaults({
    724733                                        selection: options.selection,
     
    728737                                new media.controller.Upload( main ),
    729738
     739                                // Gallery states.
    730740                                new media.controller.Gallery({
    731741                                        editing: options.editing,
     
    735745                                new media.controller.Library( _.defaults({
    736746                                        id:      'gallery-library',
    737                                         library: media.query({ type: 'image' }),
    738                                         excludeState: 'gallery-edit'
     747                                        library: media.query({ type: 'image' })
    739748                                }, gallery ) ),
    740749
    741750                                new media.controller.Upload( _.defaults({
    742                                         id: 'gallery-upload',
    743                                         excludeState: 'gallery-edit'
    744                                 }, gallery ) )
     751                                        id: 'gallery-upload'
     752                                }, gallery ) ),
     753
     754                                // Batch states.
     755                                new media.controller.Library({
     756                                        id:       'batch-edit',
     757                                        multiple: false,
     758                                        describe: true,
     759                                        edge:     199,
     760                                        sortable: true,
     761                                        menu:     'batch',
     762                                        toolbar:  'batch-edit',
     763                                        sidebar:  'attachment-settings'
     764                                }),
     765
     766                                new media.controller.Library( _.defaults({
     767                                        id:      'batch-library',
     768                                        library: media.query({ type: 'image' })
     769                                }, batch ) ),
     770
     771                                new media.controller.Upload( _.defaults({
     772                                        id: 'batch-upload'
     773                                }, batch ) )
    745774                        ]);
    746775
     
    774803                },
    775804
    776                 batchMenu: function() {},
     805                batchMenu: function() {
     806                        var previous = this.previous(),
     807                                frame = this;
     808
     809                        this.menu.view( new media.view.Menu({
     810                                controller: this,
     811                                views: {
     812                                        cancel: {
     813                                                text:     l10n.cancelBatchTitle,
     814                                                priority: 20,
     815                                                click:    function() {
     816                                                        if ( previous )
     817                                                                frame.state( previous );
     818                                                        else
     819                                                                frame.close();
     820                                                }
     821                                        },
     822                                        separateCancel: new Backbone.View({
     823                                                className: 'separator',
     824                                                priority: 40
     825                                        }),
     826                                        'batch-edit': {
     827                                                text: l10n.editBatchTitle,
     828                                                priority: 60
     829                                        },
     830                                        'batch-upload': {
     831                                                text: l10n.uploadFilesTitle,
     832                                                priority: 80
     833                                        },
     834                                        'batch-library': {
     835                                                text: l10n.mediaLibraryTitle,
     836                                                priority: 100
     837                                        }
     838                                }
     839                        }) );
     840                },
    777841
    778842                galleryMenu: function() {
     
    811875                                }
    812876                        }) );
    813 
    814877                },
    815878
     
    901964
    902965                mainEmbedToolbar: function() {},
    903                 batchEditToolbar: function() {},
    904                 batchAddToolbar: function() {},
     966
     967                batchEditToolbar: function() {
     968                        this.toolbar.view( new media.view.Toolbar({
     969                                controller: this,
     970                                items: {
     971                                        insert: {
     972                                                style:    'primary',
     973                                                text:     l10n.insertIntoPost,
     974                                                priority: 80,
     975
     976                                                click: function() {
     977                                                        var controller = this.controller,
     978                                                                state = controller.state();
     979
     980                                                        controller.close();
     981                                                        state.trigger( 'insert', state.get('library') );
     982
     983                                                        controller.reset();
     984                                                        // @todo: Make the state activated dynamic (instead of hardcoded).
     985                                                        controller.state('upload');
     986                                                }
     987                                        }
     988                                }
     989                        }) );
     990                },
     991
     992                batchAddToolbar: function() {
     993                        this.toolbar.view( new media.view.Toolbar({
     994                                controller: this,
     995                                items: {
     996                                        insert: {
     997                                                style:    'primary',
     998                                                text:     l10n.addToBatch,
     999                                                priority: 80,
     1000
     1001                                                click: function() {
     1002                                                        var controller = this.controller,
     1003                                                                state = controller.state(),
     1004                                                                edit = controller.get('batch-edit');
     1005
     1006                                                        edit.get('library').add( state.get('selection').models );
     1007                                                        state.trigger('reset');
     1008                                                        controller.state('batch-edit');
     1009                                                }
     1010                                        }
     1011                                }
     1012                        }) );
     1013                },
    9051014
    9061015                galleryEditToolbar: function() {
     
    12931402        media.view.Toolbar.Insert.Post = media.view.Toolbar.Insert.extend({
    12941403                initialize: function() {
     1404                        var selectionToLibrary = function( state ) {
     1405                                        return function() {
     1406                                                var controller = this.controller,
     1407                                                        selection = controller.state().get('selection'),
     1408                                                        edit = controller.get( state );
     1409
     1410                                                edit.set( 'library', new media.model.Selection( selection.models, {
     1411                                                        props:    selection.props.toJSON(),
     1412                                                        multiple: true
     1413                                                }) );
     1414
     1415                                                this.controller.state( state );
     1416                                        };
     1417                                };
     1418
    12951419                        this.options.items = _.defaults( this.options.items || {}, {
    12961420                                gallery: {
    12971421                                        text:     l10n.createNewGallery,
    12981422                                        priority: 40,
    1299 
    1300                                         click: function() {
    1301                                                 var controller = this.controller,
    1302                                                         selection = controller.state().get('selection'),
    1303                                                         edit = controller.get('gallery-edit');
    1304 
    1305                                                 edit.set( 'library', new media.model.Selection( selection.models, {
    1306                                                         props:    selection.props.toJSON(),
    1307                                                         multiple: true
    1308                                                 }) );
    1309 
    1310                                                 this.controller.state('gallery-edit');
    1311                                         }
     1423                                        click:    selectionToLibrary('gallery-edit')
    13121424                                },
    13131425
     
    13151427                                        text:     l10n.batchInsert,
    13161428                                        priority: 60,
    1317 
    1318                                         click: function() {
    1319                                                 this.controller.state('batch-edit');
    1320                                         }
     1429                                        click:    selectionToLibrary('batch-edit')
    13211430                                }
    13221431                        });
     
    13381447
    13391448                        // Batch insert shows for multiple selected attachments.
    1340                         // Temporarily disabled with `false &&`.
    1341                         this.get('batch').$el.toggle( false && count > 1 );
     1449                        this.get('batch').$el.toggle( count > 1 );
    13421450
    13431451                        // Insert only shows for single attachments.
    1344                         // Temporarily disabled.
    1345                         // this.get('insert').$el.toggle( count <= 1 );
     1452                        this.get('insert').$el.toggle( count <= 1 );
    13461453                }
    13471454        });
  • trunk/wp-includes/script-loader.php

    r22437 r22480  
    339339                'createNewGallery'  => __( 'Create a new gallery' ),
    340340                'insertIntoPost'    => __( 'Insert into post' ),
    341                 'addToGallery'      => __( 'Add to gallery' ),
    342341
    343342                // Embed
     
    347346                'batchInsert'      => __( 'Batch insert' ),
    348347                'cancelBatchTitle' => __( '&#8592; Cancel Batch' ),
     348                'editBatchTitle'   => __( 'Edit Batch' ),
     349                'addToBatch'       => __( 'Add to batch' ),
    349350
    350351                // Gallery
     
    355356                'updateGallery'      => __( 'Update gallery' ),
    356357                'continueEditing'    => __( 'Continue editing' ),
     358                'addToGallery'       => __( 'Add to gallery' ),
    357359        ) );
    358360
Note: See TracChangeset for help on using the changeset viewer.