<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[27362] trunk/src/wp-includes/js/media-views.js: Make `CollectionEdit` and `CollectionAdd` less dynamically quirky.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/27362">27362</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-03-02 23:10:47 +0000 (Sun, 02 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Make `CollectionEdit` and `CollectionAdd` less dynamically quirky. Rename some instance properties for disambiguation. Pass some properties from `options` when creating instances in `wp.media.view.MediaFrame.Post`.

See <a href="http://core.trac.wordpress.org/ticket/26631">#26631</a>.
Props gcorne.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesjsmediaviewsjs">trunk/src/wp-includes/js/media-views.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/media-views.js (27361 => 27362)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/media-views.js  2014-03-02 23:06:12 UTC (rev 27361)
+++ trunk/src/wp-includes/js/media-views.js     2014-03-02 23:10:47 UTC (rev 27362)
</span><span class="lines">@@ -762,108 +762,108 @@
</span><span class="cx">  /**
</span><span class="cx">   * wp.media.controller.CollectionEdit
</span><span class="cx">   *
</span><del>-        * @static
-        * @param {string} prop The shortcode slug
-        * @param {object} args
-        * @returns {wp.media.controller.Library}
</del><ins>+         * @constructor
+        * @augments wp.media.controller.Library
+        * @augments wp.media.controller.State
+        * @augments Backbone.Model
</ins><span class="cx">    */
</span><del>-       media.controller.CollectionEdit = function ( prop, args ) {
-               /**
-                * @constructor
-                * @augments wp.media.controller.Library
-                * @augments wp.media.controller.State
-                * @augments Backbone.Model
-                */
-               return media.controller.Library.extend({
-                       defaults : _.defaults(args.defaults || {}, {
-                               id:         prop + '-edit',
-                               toolbar:    prop + '-edit',
-                               multiple:   false,
-                               describe:   true,
-                               edge:       199,
-                               editing:    false,
-                               sortable:   true,
-                               searchable: false,
-                               content:    'browse',
-                               priority:   60,
-                               dragInfo:   true,
</del><ins>+        media.controller.CollectionEdit = media.controller.Library.extend({
+               defaults: {
+                       multiple:     false,
+                       describe:     true,
+                       edge:         199,
+                       editing:      false,
+                       sortable:     true,
+                       searchable:   false,
+                       content:      'browse',
+                       priority:     60,
+                       dragInfo:     true,
+                       SettingsView: false,
</ins><span class="cx"> 
</span><del>-                               // Don't sync the selection, as the Edit {Collection} library
-                               // *is* the selection.
-                               syncSelection: false
-                       }),
</del><ins>+                        // Don't sync the selection, as the Edit {Collection} library
+                       // *is* the selection.
+                       syncSelection: false
+               },
</ins><span class="cx"> 
</span><del>-                       initialize: function() {
-                               // If we haven't been provided a `library`, create a `Selection`.
-                               if ( ! this.get('library') ) {
-                                       this.set( 'library', new media.model.Selection() );
-                               }
-                               // The single `Attachment` view to be used in the `Attachments` view.
-                               if ( ! this.get('AttachmentView') ) {
-                                       this.set( 'AttachmentView', media.view.Attachment.EditLibrary );
-                               }
-                               media.controller.Library.prototype.initialize.apply( this, arguments );
-                       },
</del><ins>+                initialize: function() {
+                       var collectionType = this.get('collectionType');
</ins><span class="cx"> 
</span><del>-                       activate: function() {
-                               var library = this.get('library');
</del><ins>+                        this.set( 'id', collectionType + '-edit' );
+                       this.set( 'toolbar', collectionType + '-edit' );
</ins><span class="cx"> 
</span><del>-                               // Limit the library to images only.
-                               library.props.set( 'type', args.type );
</del><ins>+                        // If we haven't been provided a `library`, create a `Selection`.
+                       if ( ! this.get('library') ) {
+                               this.set( 'library', new media.model.Selection() );
+                       }
+                       // The single `Attachment` view to be used in the `Attachments` view.
+                       if ( ! this.get('AttachmentView') ) {
+                               this.set( 'AttachmentView', media.view.Attachment.EditLibrary );
+                       }
+                       media.controller.Library.prototype.initialize.apply( this, arguments );
+               },
</ins><span class="cx"> 
</span><del>-                               // Watch for uploaded attachments.
-                               this.get('library').observe( wp.Uploader.queue );
</del><ins>+                activate: function() {
+                       var library = this.get('library');
</ins><span class="cx"> 
</span><del>-                               this.frame.on( 'content:render:browse', this.settings, this );
</del><ins>+                        // Limit the library to images only.
+                       library.props.set( 'type', this.get( 'type' ) );
</ins><span class="cx"> 
</span><del>-                               media.controller.Library.prototype.activate.apply( this, arguments );
-                       },
</del><ins>+                        // Watch for uploaded attachments.
+                       this.get('library').observe( wp.Uploader.queue );
</ins><span class="cx"> 
</span><del>-                       deactivate: function() {
-                               // Stop watching for uploaded attachments.
-                               this.get('library').unobserve( wp.Uploader.queue );
</del><ins>+                        this.frame.on( 'content:render:browse', this.renderSettings, this );
</ins><span class="cx"> 
</span><del>-                               this.frame.off( 'content:render:browse', this.settings, this );
</del><ins>+                        media.controller.Library.prototype.activate.apply( this, arguments );
+               },
</ins><span class="cx"> 
</span><del>-                               media.controller.Library.prototype.deactivate.apply( this, arguments );
-                       },
</del><ins>+                deactivate: function() {
+                       // Stop watching for uploaded attachments.
+                       this.get('library').unobserve( wp.Uploader.queue );
</ins><span class="cx"> 
</span><del>-                       settings: function( browser ) {
-                               var library = this.get('library'), obj = {};
</del><ins>+                        this.frame.off( 'content:render:browse', this.renderSettings, this );
</ins><span class="cx"> 
</span><del>-                               if ( ! library || ! browser ) {
-                                       return;
-                               }
</del><ins>+                        media.controller.Library.prototype.deactivate.apply( this, arguments );
+               },
</ins><span class="cx"> 
</span><del>-                               library[ prop ] = library[ prop ] || new Backbone.Model();
</del><ins>+                renderSettings: function( browser ) {
+                       var library = this.get('library'),
+                               collectionType = this.get('collectionType'),
+                               dragInfoText = this.get('dragInfoText'),
+                               SettingsView = this.get('SettingsView'),
+                               obj = {};
</ins><span class="cx"> 
</span><del>-                               obj[ prop ] = new media.view.Settings[ args.settings ]({
-                                       controller: this,
-                                       model:      library[ prop ],
-                                       priority:   40
-                               });
</del><ins>+                        if ( ! library || ! browser ) {
+                               return;
+                       }
</ins><span class="cx"> 
</span><del>-                               browser.sidebar.set( obj );
</del><ins>+                        library[ collectionType ] = library[ collectionType ] || new Backbone.Model();
</ins><span class="cx"> 
</span><del>-                               if ( args.dragInfoText ) {
-                                       browser.toolbar.set( 'dragInfo', new media.View({
-                                               el: $( '<div class="instructions">' + args.dragInfoText + '</div>' )[0],
-                                               priority: -40
-                                       }) );
-                               }
</del><ins>+                        obj[ collectionType ] = new SettingsView({
+                               controller: this,
+                               model:      library[ collectionType ],
+                               priority:   40
+                       });
</ins><span class="cx"> 
</span><del>-                               browser.toolbar.set( 'reverse', {
-                                       text:     l10n.reverseOrder,
-                                       priority: 80,
</del><ins>+                        browser.sidebar.set( obj );
</ins><span class="cx"> 
</span><del>-                                       click: function() {
-                                               library.reset( library.toArray().reverse() );
-                                       }
-                               });
</del><ins>+                        if ( dragInfoText ) {
+                               browser.toolbar.set( 'dragInfo', new media.View({
+                                       el: $( '<div class="instructions">' + dragInfoText + '</div>' )[0],
+                                       priority: -40
+                               }) );
</ins><span class="cx">                   }
</span><del>-               });
-       };
</del><span class="cx"> 
</span><ins>+                       browser.toolbar.set( 'reverse', {
+                               text:     l10n.reverseOrder,
+                               priority: 80,
+
+                               click: function() {
+                                       library.reset( library.toArray().reverse() );
+                               }
+                       });
+               }
+       });
+
</ins><span class="cx">   /**
</span><span class="cx">   * wp.media.controller.CollectionAdd
</span><span class="cx">   *
</span><span class="lines">@@ -872,90 +872,54 @@
</span><span class="cx">   * @augments wp.media.controller.State
</span><span class="cx">   * @augments Backbone.Model
</span><span class="cx">   */
</span><del>-       media.controller.CollectionAdd = function (attributes) {
-               var ExtendedLibrary, extended = _.extend( attributes, {
-                       defaults: _.defaults( {
-                               id: attributes.tag + '-library',
-                               title: attributes.title,
-                               menu: attributes.tag,
-                               toolbar: attributes.tag + '-add',
-                               filterable: 'uploaded',
-                               multiple:   'add',
-                               priority:   100,
-                               syncSelection: false
-                       }, media.controller.Library.prototype.defaults ),
</del><ins>+        media.controller.CollectionAdd = media.controller.Library.extend({
+               defaults: _.defaults( {
+                       filterable:    'uploaded',
+                       multiple:      'add',
+                       priority:      100,
+                       syncSelection: false
+               }, media.controller.Library.prototype.defaults ),
</ins><span class="cx"> 
</span><del>-                       initialize: function() {
-                               // If we haven't been provided a `library`, create a `Selection`.
-                               if ( ! this.get('library') ) {
-                                       this.set( 'library', media.query({ type: this.type }) );
-                               }
-                               media.controller.Library.prototype.initialize.apply( this, arguments );
-                       },
</del><ins>+                initialize: function() {
+                       var collectionType = this.get('collectionType');
</ins><span class="cx"> 
</span><del>-                       activate: function() {
-                               var library = this.get('library'),
-                                       edit    = this.frame.state( this.tag + '-edit' ).get('library');
</del><ins>+                        this.set( 'id', collectionType + '-library' );
+                       this.set( 'toolbar', collectionType + '-add' );
+                       this.set( 'menu', collectionType );
</ins><span class="cx"> 
</span><del>-                               if ( this.editLibrary && this.editLibrary !== edit ) {
-                                       library.unobserve( this.editLibrary );
-                               }
</del><ins>+                        // If we haven't been provided a `library`, create a `Selection`.
+                       if ( ! this.get('library') ) {
+                               this.set( 'library', media.query({ type: this.get('type') }) );
+                       }
+                       media.controller.Library.prototype.initialize.apply( this, arguments );
+               },
</ins><span class="cx"> 
</span><del>-                               // Accepts attachments that exist in the original library and
-                               // that do not exist in gallery's library.
-                               library.validator = function( attachment ) {
-                                       return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && media.model.Selection.prototype.validator.apply( this, arguments );
-                               };
</del><ins>+                activate: function() {
+                       var library = this.get('library'),
+                               editLibrary = this.get('editLibrary'),
+                               edit = this.frame.state( this.get('collectionType') + '-edit' ).get('library');
</ins><span class="cx"> 
</span><del>-                               // Reset the library to ensure that all attachments are re-added
-                               // to the collection. Do so silently, as calling `observe` will
-                               // trigger the `reset` event.
-                               library.reset( library.mirroring.models, { silent: true });
-                               library.observe( edit );
-                               this.editLibrary = edit;
-
-                               media.controller.Library.prototype.activate.apply( this, arguments );
</del><ins>+                        if ( editLibrary && editLibrary !== edit ) {
+                               library.unobserve( editLibrary );
</ins><span class="cx">                   }
</span><del>-               } );
-               ExtendedLibrary = media.controller.Library.extend( extended );
</del><span class="cx"> 
</span><del>-               return new ExtendedLibrary();
-       };
</del><ins>+                        // Accepts attachments that exist in the original library and
+                       // that do not exist in gallery's library.
+                       library.validator = function( attachment ) {
+                               return !! this.mirroring.get( attachment.cid ) && ! edit.get( attachment.cid ) && media.model.Selection.prototype.validator.apply( this, arguments );
+                       };
</ins><span class="cx"> 
</span><del>-       // wp.media.controller.GalleryEdit
-       // -------------------------------
-       media.controller.GalleryEdit = media.controller.CollectionEdit( 'gallery', {
-               type: 'image',
-               settings: 'Gallery',
-               defaults: {
-                       title: l10n.editGalleryTitle
-               }
-       });
</del><ins>+                        // Reset the library to ensure that all attachments are re-added
+                       // to the collection. Do so silently, as calling `observe` will
+                       // trigger the `reset` event.
+                       library.reset( library.mirroring.models, { silent: true });
+                       library.observe( edit );
+                       this.set('editLibrary', edit);
</ins><span class="cx"> 
</span><del>-       // wp.media.controller.PlaylistEdit
-       // -------------------------------
-       media.controller.PlaylistEdit = media.controller.CollectionEdit( 'playlist', {
-               type: 'audio',
-               settings: 'Playlist',
-               dragInfoText: l10n.playlistDragInfo,
-               defaults: {
-                       title: l10n.editPlaylistTitle,
-                       dragInfo : false
</del><ins>+                        media.controller.Library.prototype.activate.apply( this, arguments );
</ins><span class="cx">           }
</span><span class="cx">  });
</span><span class="cx"> 
</span><del>-       // wp.media.controller.VideoPlaylistEdit
-       // -------------------------------
-       media.controller.VideoPlaylistEdit = media.controller.CollectionEdit( 'video-playlist', {
-               type: 'video',
-               settings: 'Playlist',
-               dragInfoText: l10n.videoPlaylistDragInfo,
-               defaults: {
-                       title: l10n.editVideoPlaylistTitle,
-                       dragInfo : false
-               }
-       });
-
</del><span class="cx">   /**
</span><span class="cx">   * wp.media.controller.FeaturedImage
</span><span class="cx">   *
</span><span class="lines">@@ -1776,16 +1740,20 @@
</span><span class="cx">                          new media.controller.Embed(),
</span><span class="cx"> 
</span><span class="cx">                          // Gallery states.
</span><del>-                               new media.controller.GalleryEdit({
-                                       library: options.selection,
-                                       editing: options.editing,
-                                       menu:    'gallery'
</del><ins>+                                new media.controller.CollectionEdit({
+                                       type:           'image',
+                                       collectionType: 'gallery',
+                                       title:           l10n.editGalleryTitle,
+                                       SettingsView:    media.view.Settings.Gallery,
+                                       library:         options.selection,
+                                       editing:         options.editing,
+                                       menu:           'gallery'
</ins><span class="cx">                           }),
</span><span class="cx"> 
</span><span class="cx">                          new media.controller.CollectionAdd({
</span><del>-                                       tag: 'gallery',
-                                       type: 'image',
-                                       title: l10n.addToGalleryTitle
</del><ins>+                                        type:           'image',
+                                       collectionType: 'gallery',
+                                       title:          l10n.addToGalleryTitle
</ins><span class="cx">                           }),
</span><span class="cx"> 
</span><span class="cx">                          new media.controller.Library({
</span><span class="lines">@@ -1803,15 +1771,21 @@
</span><span class="cx">                          }),
</span><span class="cx"> 
</span><span class="cx">                          // Playlist states.
</span><del>-                               new media.controller.PlaylistEdit({
-                                       library: options.selection,
-                                       editing: options.editing,
-                                       menu:    'playlist'
</del><ins>+                                new media.controller.CollectionEdit({
+                                       type:           'audio',
+                                       collectionType: 'playlist',
+                                       title:          l10n.editPlaylistTitle,
+                                       SettingsView:   media.view.Settings.Playlist,
+                                       library:        options.selection,
+                                       editing:        options.editing,
+                                       menu:           'playlist',
+                                       dragInfoText:   l10n.playlistDragInfo,
+                                       dragInfo:       false
</ins><span class="cx">                           }),
</span><span class="cx"> 
</span><span class="cx">                          new media.controller.CollectionAdd({
</span><del>-                                       tag: 'playlist',
</del><span class="cx">                                   type: 'audio',
</span><ins>+                                       collectionType: 'playlist',
</ins><span class="cx">                                   title: l10n.addToPlaylistTitle
</span><span class="cx">                          }),
</span><span class="cx"> 
</span><span class="lines">@@ -1830,16 +1804,22 @@
</span><span class="cx">                          }),
</span><span class="cx"> 
</span><span class="cx">                          // Video Playlist states.
</span><del>-                               new media.controller.VideoPlaylistEdit({
-                                       library: options.selection,
-                                       editing: options.editing,
-                                       menu:    'video-playlist'
</del><ins>+                                new media.controller.CollectionEdit({
+                                       type:           'video',
+                                       collectionType: 'video-playlist',
+                                       title:          l10n.editVideoPlaylistTitle,
+                                       SettingsView:   media.view.Settings.Playlist,
+                                       library:        options.selection,
+                                       editing:        options.editing,
+                                       menu:           'video-playlist',
+                                       dragInfoText:   l10n.videoPlaylistDragInfo,
+                                       dragInfo:       false
</ins><span class="cx">                           }),
</span><span class="cx"> 
</span><span class="cx">                          new media.controller.CollectionAdd({
</span><del>-                                       tag: 'video-playlist',
-                                       type: 'video',
-                                       title: l10n.addToVideoPlaylistTitle
</del><ins>+                                        type:           'video',
+                                       collectionType: 'video-playlist',
+                                       title:          l10n.addToVideoPlaylistTitle
</ins><span class="cx">                           })
</span><span class="cx">                  ]);
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>