Make WordPress Core

Changeset 22781


Ignore:
Timestamp:
11/21/2012 06:29:53 PM (12 years ago)
Author:
koopersmith
Message:

Media: Make the upload state a dedicated screen, instead of including its own library view. see #21390.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/media-views.js

    r22779 r22781  
    445445    // wp.media.controller.Upload
    446446    // ---------------------------
    447     media.controller.Upload = media.controller.Library.extend({
     447    media.controller.Upload = media.controller.State.extend({
    448448        defaults: _.defaults({
    449             id:         'upload',
    450             upload:     { text: l10n.uploadMoreFiles },
    451             searchable: false,
    452             sortable:   true
    453         }, media.controller.Library.prototype.defaults ),
     449            id:      'upload',
     450            content: 'upload',
     451            sidebar: 'empty',
     452            toolbar: 'empty',
     453
     454            // The state to navigate to when files are uploading.
     455            libraryState: 'library'
     456        }, media.controller.State.prototype.defaults ),
    454457
    455458        initialize: function() {
    456             var library = this.get('library');
    457 
    458             // If a `library` attribute isn't provided, create a new
    459             // `Attachments` collection that observes (and thereby receives
    460             // all uploading) attachments.
    461             if ( ! library ) {
    462                 library = new Attachments();
    463                 library.observe( wp.Uploader.queue );
    464                 this.set( 'library', library );
    465             }
    466 
    467             media.controller.Library.prototype.initialize.apply( this, arguments );
    468         }
    469 
     459            media.controller.State.prototype.initialize.apply( this, arguments );
     460        },
     461
     462        activate: function() {
     463            wp.Uploader.queue.on( 'add', this.uploading, this );
     464            media.controller.State.prototype.activate.apply( this, arguments );
     465        },
     466
     467        deactivate: function() {
     468            wp.Uploader.queue.off( null, null, this );
     469            media.controller.State.prototype.deactivate.apply( this, arguments );
     470        },
     471
     472        uploading: function( attachment ) {
     473            var library = this.get('libraryState');
     474
     475            this.frame.get( library ).get('selection').add( attachment );
     476            this.frame.state( library );
     477        }
    470478    });
    471479
     
    11761184
    11771185        createStates: function() {
    1178             var options = this.options,
    1179                 attributes;
    1180 
    1181             attributes = {
    1182                 multiple: this.options.multiple,
    1183                 menu:     'main',
    1184                 toolbar:  'select'
    1185             };
     1186            var options = this.options;
    11861187
    11871188            // Add the default states.
     
    11901191                new media.controller.Library( _.defaults({
    11911192                    selection: options.selection,
    1192                     library:   media.query( options.library )
     1193                    library:   media.query( options.library ),
     1194                    multiple:  this.options.multiple,
     1195                    menu:      'main',
     1196                    toolbar:   'select'
    11931197                }, attributes ) ),
    11941198
    1195                 new media.controller.Upload( attributes )
     1199                new media.controller.Upload({
     1200                    menu: 'main'
     1201                })
    11961202            ]);
    11971203        },
     
    12461252
    12471253        uploadContent: function() {
    1248             // In the meantime, render an inline uploader.
     1254            this.$el.addClass('hide-sidebar hide-toolbar');
     1255
    12491256            this.content.view( new media.view.UploaderInline({
    12501257                controller: this
     
    13431350
    13441351        createStates: function() {
    1345             var options = this.options,
    1346                 main, gallery;
    1347 
    1348             main = {
    1349                 multiple: this.options.multiple,
    1350                 menu:      'main',
    1351                 sidebar:   'attachment-settings',
    1352 
    1353                 // Update user settings when users adjust the
    1354                 // attachment display settings.
    1355                 displayUserSettings: true
    1356             };
    1357 
    1358             gallery = {
    1359                 multiple:     true,
    1360                 menu:         'gallery',
    1361                 toolbar:      'gallery-add',
    1362                 excludeState: 'gallery-edit'
    1363             };
     1352            var options = this.options;
    13641353
    13651354            // Add the default states.
    13661355            this.states.add([
    13671356                // Main states.
    1368                 new media.controller.Library( _.defaults({
     1357                new media.controller.Library({
    13691358                    selection:  options.selection,
    13701359                    library:    media.query( options.library ),
    13711360                    editable:   true,
    1372                     filterable: 'all'
    1373                 }, main ) ),
    1374 
    1375                 new media.controller.Upload( main ),
     1361                    filterable: 'all',
     1362                    multiple:   this.options.multiple,
     1363                    menu:       'main',
     1364                    sidebar:    'attachment-settings',
     1365
     1366                    // Update user settings when users adjust the
     1367                    // attachment display settings.
     1368                    displayUserSettings: true
     1369                }),
     1370
     1371                new media.controller.Upload({
     1372                    menu: 'main'
     1373                }),
    13761374
    13771375                // Embed states.
     
    13851383                }),
    13861384
    1387                 new media.controller.Library( _.defaults({
    1388                     id:         'gallery-library',
    1389                     library:    media.query({ type: 'image' }),
    1390                     filterable: 'uploaded'
    1391                 }, gallery ) ),
    1392 
    1393                 new media.controller.Upload( _.defaults({
    1394                     id: 'gallery-upload'
    1395                 }, gallery ) )
     1385                new media.controller.Library({
     1386                    id:           'gallery-library',
     1387                    library:      media.query({ type: 'image' }),
     1388                    filterable:   'uploaded',
     1389                    multiple:     true,
     1390                    menu:         'gallery',
     1391                    toolbar:      'gallery-add',
     1392                    excludeState: 'gallery-edit'
     1393                }),
     1394
     1395                new media.controller.Upload({
     1396                    id:           'gallery-upload',
     1397                    menu:         'gallery',
     1398                    libraryState: 'gallery-edit'
     1399                })
    13961400            ]);
    13971401        },
Note: See TracChangeset for help on using the changeset viewer.