Make WordPress Core

Changeset 22397


Ignore:
Timestamp:
11/06/2012 01:19:39 AM (14 years ago)
Author:
koopersmith
Message:

Media JS: Move state-related logic from sidebar views to the state controllers. see #21390.

File:
1 edited

Legend:

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

    r22363 r22397  
    185185
    186186                activate: function() {
     187                        var selection = this.get('selection');
     188
    187189                        // If we're in a workflow that supports multiple attachments,
    188190                        // automatically select any uploading attachments.
     
    190192                                wp.Uploader.queue.on( 'add', this.selectUpload, this );
    191193
    192                         this.get('selection').on( 'selection:single', this.buildDetails, this );
    193                         this.get('selection').on( 'selection:unsingle', this.clearDetails, this );
     194                        selection.on( 'selection:single', this.buildDetails, this );
     195                        selection.on( 'selection:unsingle', this.clearDetails, this );
     196                        selection.on( 'add remove reset', this.updateToolbarVisibility, this );
    194197
    195198                        this._updateEmpty();
     
    200203
    201204                deactivate: function() {
    202                         var toolbar = this._postLibraryToolbar;
    203 
    204                         if ( toolbar )
    205                                 this.get('selection').off( 'add remove', toolbar.visibility, toolbar );
    206 
    207205                        wp.Uploader.queue.off( 'add', this.selectUpload, this );
    208                         this.get('selection').off( 'selection:single', this.buildDetails, this );
    209                         this.get('selection').off( 'selection:unsingle', this.clearDetails, this );
     206
     207                        // Unbind all event handlers that use this state as the context
     208                        // from the selection.
     209                        this.get('selection').off( null, null, this );
    210210                        this.get('library').off( 'add remove reset', this._updateEmpty, this );
    211211                        this.off( 'change:empty', this.refresh, this );
     
    213213
    214214                toolbar: function() {
    215                         var frame = this.frame,
    216                                 toolbar;
    217 
    218                         // Toolbar.
    219                         toolbar = this._postLibraryToolbar = new media.view.Toolbar.PostLibrary({
    220                                 controller: frame,
    221                                 state:      this
    222                         });
    223 
    224                         frame.toolbar( toolbar );
    225                         this.get('selection').on( 'add remove', toolbar.visibility, toolbar );
     215                        var frame = this.frame;
     216
     217                        frame.toolbar( new media.view.Toolbar.PostLibrary({
     218                                controller: frame
     219                        }) );
    226220                },
    227221
     
    272266                },
    273267
     268                updateToolbarVisibility: function() {
     269                        this.frame.toolbar().visibility();
     270                },
     271
    274272                selectUpload: function( attachment ) {
    275273                        this.get('selection').add( attachment );
     
    358356
    359357                toolbar: function() {
    360                         this.frame.toolbar( new media.view.Toolbar.Gallery({
    361                                 controller: this.frame,
    362                                 state:      this
     358                        var frame = this.frame;
     359                        frame.toolbar( new media.view.Toolbar.Gallery({
     360                                controller: frame
    363361                        }) );
    364362                },
     
    409407                toolbar: function() {
    410408                        var frame = this.frame;
    411 
    412409                        frame.toolbar( new media.view.Toolbar.GalleryAddImages({
    413                                 controller: frame,
    414                                 state:      this
     410                                controller: frame
    415411                        }) );
    416412                },
     
    873869        media.view.Toolbar.PostLibrary = media.view.Toolbar.extend({
    874870                initialize: function() {
    875                         var state = this.options.state,
    876                                 selection = state.get('selection'),
    877                                 controller = this.options.controller;
     871                        var controller = this.options.controller,
     872                                selection = controller.state().get('selection');
    878873
    879874                        this.options.items = {
     
    902897                                                        click: function() {
    903898                                                                controller.close();
    904                                                                 state.trigger( 'insert', selection );
     899                                                                controller.state().trigger( 'insert', selection );
    905900                                                                selection.clear();
    906901                                                        }
     
    942937
    943938                visibility: function() {
    944                         var state = this.options.state,
    945                                 selection = state.get('selection'),
    946                                 controller = this.options.controller,
     939                        var selection = this.controller.state().get('selection'),
    947940                                count = selection.length,
    948941                                showGallery;
     
    967960        media.view.Toolbar.Gallery = media.view.Toolbar.extend({
    968961                initialize: function() {
    969                         var state = this.options.state,
     962                        var controller = this.options.controller,
     963                                state = controller.state(),
    970964                                editing = state.get('editing'),
    971                                 library = state.get('library'),
    972                                 controller = this.options.controller;
     965                                library = state.get('library');
    973966
    974967                        this.options.items = {
     
    978971                                        priority: 40,
    979972                                        click:    function() {
     973                                                var state = controller.state();
    980974                                                controller.close();
    981                                                 state.trigger( 'update', library );
     975                                                state.trigger( 'update', state.get('library') );
    982976                                                controller.get('library').get('selection').clear();
    983977                                                controller.state('library');
     
    991985                                        click: function() {
    992986                                                controller.get('gallery:add').set( 'selection', new media.model.Selection( library.models, {
    993                                                         props:    library.props.toJSON(),
     987                                                        props:    controller.state().get('library').props.toJSON(),
    994988                                                        multiple: true
    995989                                                }) );
     
    10191013        media.view.Toolbar.GalleryAddImages = media.view.Toolbar.extend({
    10201014                initialize: function() {
    1021                         var state = this.options.state,
    1022                                 editing = state.get('editing'),
    1023                                 library = state.get('library'),
    1024                                 controller = this.options.controller;
     1015                        var controller = this.options.controller;
    10251016
    10261017                        this.options.items = {
     
    10311022
    10321023                                        click: function() {
    1033                                                 controller.get('gallery').set( 'library', state.get('selection') );
     1024                                                controller.get('gallery').set( 'library', controller.state().get('selection') );
    10341025                                                controller.state('gallery');
    10351026                                        }
Note: See TracChangeset for help on using the changeset viewer.