<!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>[22951] trunk/wp-includes/js: Update the "Uploaded to this post" filter view when uploading new files.</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, #logmsg > ol { margin-left: 0; 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/22951">22951</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2012-11-30 15:11:44 +0000 (Fri, 30 Nov 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Update the "Uploaded to this post" filter view when uploading new files.
* Add an Attachments collection filter for uploadedTo (post_parent).
* Correct an erroneous map from the non-existent parent prop to post_parent.
* Define default menuOrder and uploadedTo props for uploading attachments.
* Unify filterable props into a single method (improving validation performance for calls to set with multiple properties).
Props koopersmith
fixes <a href="http://core.trac.wordpress.org/ticket/22654">#22654</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesjsmediaeditorjs">trunk/wp-includes/js/media-editor.js</a></li>
<li><a href="#trunkwpincludesjsmediamodelsjs">trunk/wp-includes/js/media-models.js</a></li>
<li><a href="#trunkwpincludesjsmediaviewsjs">trunk/wp-includes/js/media-views.js</a></li>
<li><a href="#trunkwpincludesjspluploadwppluploadjs">trunk/wp-includes/js/plupload/wp-plupload.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesjsmediaeditorjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-editor.js (22950 => 22951)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-editor.js        2012-11-30 14:03:47 UTC (rev 22950)
+++ trunk/wp-includes/js/media-editor.js        2012-11-30 15:11:44 UTC (rev 22951)
</span><span class="lines">@@ -205,7 +205,7 @@
</span><span class="cx">                                         args.post__not_in = attrs.exclude.split(',');
</span><span class="cx">
</span><span class="cx">                                 if ( ! args.post__in )
</span><del>-                                        args.parent = attrs.id;
</del><ins>+                                        args.uploadedTo = attrs.id;
</ins><span class="cx">
</span><span class="cx">                                 // Collect the attributes that were not included in `args`.
</span><span class="cx">                                 others = _.omit( attrs, 'id', 'ids', 'include', 'exclude', 'orderby', 'order' );
</span><span class="lines">@@ -228,9 +228,9 @@
</span><span class="cx">                                 // the collection will already reflect those properties.
</span><span class="cx">                                 attrs.ids = attachments.pluck('id');
</span><span class="cx">
</span><del>-                                // Copy the `parent` post ID.
-                                if ( props.parent )
-                                        attrs.id = props.parent;
</del><ins>+                                // Copy the `uploadedTo` post ID.
+                                if ( props.uploadedTo )
+                                        attrs.id = props.uploadedTo;
</ins><span class="cx">
</span><span class="cx">                                 // If the `ids` attribute is set and `orderby` attribute
</span><span class="cx">                                 // is the default value, clear it for cleaner output.
</span></span></pre></div>
<a id="trunkwpincludesjsmediamodelsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-models.js (22950 => 22951)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-models.js        2012-11-30 14:03:47 UTC (rev 22950)
+++ trunk/wp-includes/js/media-models.js        2012-11-30 15:11:44 UTC (rev 22951)
</span><span class="lines">@@ -316,11 +316,11 @@
</span><span class="cx">                         this.filters = options.filters || {};
</span><span class="cx">
</span><span class="cx">                         // Bind default `change` events to the `props` model.
</span><ins>+                        this.props.on( 'change', this._changeFilteredProps, this );
+
</ins><span class="cx">                         this.props.on( 'change:order', this._changeOrder, this );
</span><span class="cx">                         this.props.on( 'change:orderby', this._changeOrderby, this );
</span><span class="cx">                         this.props.on( 'change:query', this._changeQuery, this );
</span><del>-                        this.props.on( 'change:search', this._changeSearch, this );
-                        this.props.on( 'change:type', this._changeType, this );
</del><span class="cx">
</span><span class="cx">                         // Set the `props` model and fill the default property values.
</span><span class="cx">                         this.props.set( _.defaults( options.props || {} ) );
</span><span class="lines">@@ -359,17 +359,33 @@
</span><span class="cx">                         }
</span><span class="cx">                 },
</span><span class="cx">
</span><del>-                _changeFilteredProp: function( prop, model, term ) {
</del><ins>+                _changeFilteredProps: function( model, options ) {
</ins><span class="cx">                         // If this is a query, updating the collection will be handled by
</span><span class="cx">                         // `this._requery()`.
</span><span class="cx">                         if ( this.props.get('query') )
</span><span class="cx">                                 return;
</span><span class="cx">
</span><del>-                        if ( term && ! this.filters[ prop ] )
-                                this.filters[ prop ] = Attachments.filters[ prop ];
-                        else if ( ! term && this.filters[ prop ] === Attachments.filters[ prop ] )
-                                delete this.filters[ prop ];
</del><ins>+                        var changed = _.chain( options.changes ).map( function( t, prop ) {
+                                var filter = Attachments.filters[ prop ],
+                                        term = model.get( prop );
</ins><span class="cx">
</span><ins>+                                if ( ! filter )
+                                        return;
+
+                                if ( term && ! this.filters[ prop ] )
+                                        this.filters[ prop ] = filter;
+                                else if ( ! term && this.filters[ prop ] === filter )
+                                        delete this.filters[ prop ];
+                                else
+                                        return;
+
+                                // Record the change.
+                                return true;
+                        }, this ).any().value();
+
+                        if ( ! changed )
+                                return;
+
</ins><span class="cx">                         // If no `Attachments` model is provided to source the searches
</span><span class="cx">                         // from, then automatically generate a source from the existing
</span><span class="cx">                         // models.
</span><span class="lines">@@ -379,14 +395,6 @@
</span><span class="cx">                         this.reset( this._source.filter( this.validator, this ) );
</span><span class="cx">                 },
</span><span class="cx">
</span><del>-                _changeSearch: function( model, term ) {
-                        return this._changeFilteredProp( 'search', model, term );
-                },
-
-                _changeType: function( model, term ) {
-                        return this._changeFilteredProp( 'type', model, term );
-                },
-
</del><span class="cx">                 validator: function( attachment ) {
</span><span class="cx">                         return _.all( this.filters, function( filter, key ) {
</span><span class="cx">                                 return !! filter.call( this, attachment );
</span><span class="lines">@@ -499,7 +507,7 @@
</span><span class="cx">                                 this.mirror( Query.get( this.props.toJSON() ) );
</span><span class="cx">                 }
</span><span class="cx">         }, {
</span><del>-                comparator: function( a, b ) {
</del><ins>+                comparator: function( a, b, options ) {
</ins><span class="cx">                         var key = this.props.get('orderby'),
</span><span class="cx">                                 order = this.props.get('order') || 'DESC',
</span><span class="cx">                                 ac = a.cid,
</span><span class="lines">@@ -513,6 +521,10 @@
</span><span class="cx">                                 b = b || new Date();
</span><span class="cx">                         }
</span><span class="cx">
</span><ins>+                        // If `options.ties` is set, don't enforce the `cid` tiebreaker.
+                        if ( options && options.ties )
+                                ac = bc = null;
+
</ins><span class="cx">                         return ( 'DESC' === order ) ? compare( a, b, ac, bc ) : compare( b, a, bc, ac );
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="lines">@@ -531,10 +543,15 @@
</span><span class="cx">
</span><span class="cx">                         type: function( attachment ) {
</span><span class="cx">                                 var type = this.props.get('type');
</span><del>-                                if ( ! type )
</del><ins>+                                return ! type || -1 !== type.indexOf( attachment.get('type') );
+                        },
+
+                        uploadedTo: function( attachment ) {
+                                var uploadedTo = this.props.get('uploadedTo');
+                                if ( _.isUndefined( uploadedTo ) )
</ins><span class="cx">                                         return true;
</span><span class="cx">
</span><del>-                                return -1 !== type.indexOf( attachment.get('type') );
</del><ins>+                                return uploadedTo === attachment.get('uploadedTo');
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">         });
</span><span class="lines">@@ -571,6 +588,9 @@
</span><span class="cx">                         this.created = new Date();
</span><span class="cx">
</span><span class="cx">                         this.filters.order = function( attachment ) {
</span><ins>+                                var orderby = this.props.get('orderby'),
+                                        order = this.props.get('order');
+
</ins><span class="cx">                                 if ( ! this.comparator )
</span><span class="cx">                                         return true;
</span><span class="cx">
</span><span class="lines">@@ -578,13 +598,18 @@
</span><span class="cx">                                 // item in the set. If we add any items after the last
</span><span class="cx">                                 // item, then we can't guarantee the set is complete.
</span><span class="cx">                                 if ( this.length ) {
</span><del>-                                        return 1 !== this.comparator( attachment, this.last() );
</del><ins>+                                        return 1 !== this.comparator( attachment, this.last(), { ties: true });
</ins><span class="cx">
</span><span class="cx">                                 // Handle the case where there are no items yet and
</span><span class="cx">                                 // we're sorting for recent items. In that case, we want
</span><span class="cx">                                 // changes that occurred after we created the query.
</span><del>-                                } else if ( 'DESC' === this.args.order && ( 'date' === this.args.orderby || 'modified' === this.args.orderby ) ) {
-                                        return attachment.get( this.args.orderby ) >= this.created;
</del><ins>+                                } else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) {
+                                        return attachment.get( orderby ) >= this.created;
+
+                                // If we're sorting by menu order and we have no items,
+                                // accept any items that have the default menu order (0).
+                                } else if ( 'ASC' === order && 'menuOrder' === orderby ) {
+                                        return attachment.get( orderby ) === 0;
</ins><span class="cx">                                 }
</span><span class="cx">
</span><span class="cx">                                 // Otherwise, we don't want any items yet.
</span><span class="lines">@@ -597,7 +622,7 @@
</span><span class="cx">                         // Only observe when a limited number of query args are set. There
</span><span class="cx">                         // are no filters for other properties, so observing will result in
</span><span class="cx">                         // false positives in those queries.
</span><del>-                        allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type' ];
</del><ins>+                        allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent' ];
</ins><span class="cx">                         if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() )
</span><span class="cx">                                 this.observe( wp.Uploader.queue );
</span><span class="cx">                 },
</span><span class="lines">@@ -670,9 +695,9 @@
</span><span class="cx">                 propmap: {
</span><span class="cx">                         'search': 's',
</span><span class="cx">                         'type': 'post_mime_type',
</span><del>-                        'parent': 'post_parent',
</del><span class="cx">                         'perPage': 'posts_per_page',
</span><del>-                        'menuOrder': 'menu_order'
</del><ins>+                        'menuOrder': 'menu_order',
+                        'uploadedTo': 'post_parent'
</ins><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 // Caches query objects so queries can be easily reused.
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (22950 => 22951)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-11-30 14:03:47 UTC (rev 22950)
+++ trunk/wp-includes/js/media-views.js        2012-11-30 15:11:44 UTC (rev 22951)
</span><span class="lines">@@ -2920,7 +2920,7 @@
</span><span class="cx">                         all: {
</span><span class="cx">                                 text: l10n.allMediaItems,
</span><span class="cx">                                 props: {
</span><del>-                                        parent: null,
</del><ins>+                                        uploadedTo: null,
</ins><span class="cx">                                         orderby: 'date',
</span><span class="cx">                                         order: 'DESC'
</span><span class="cx">                                 },
</span><span class="lines">@@ -2930,7 +2930,7 @@
</span><span class="cx">                         uploaded: {
</span><span class="cx">                                 text: l10n.uploadedToThisPost,
</span><span class="cx">                                 props: {
</span><del>-                                        parent: media.view.settings.postId,
</del><ins>+                                        uploadedTo: media.view.settings.postId,
</ins><span class="cx">                                         orderby: 'menuOrder',
</span><span class="cx">                                         order: 'ASC'
</span><span class="cx">                                 },
</span><span class="lines">@@ -2948,7 +2948,7 @@
</span><span class="cx">                                         text: text,
</span><span class="cx">                                         props: {
</span><span class="cx">                                                 type: key,
</span><del>-                                                parent: null,
</del><ins>+                                                uploadedTo: null,
</ins><span class="cx">                                                 orderby: 'date',
</span><span class="cx">                                                 order: 'DESC'
</span><span class="cx">                                         }
</span><span class="lines">@@ -2959,7 +2959,7 @@
</span><span class="cx">                                 text: l10n.allMediaItems,
</span><span class="cx">                                 props: {
</span><span class="cx">                                         type: null,
</span><del>-                                        parent: null,
</del><ins>+                                        uploadedTo: null,
</ins><span class="cx">                                         orderby: 'date',
</span><span class="cx">                                         order: 'DESC'
</span><span class="cx">                                 },
</span><span class="lines">@@ -2970,7 +2970,7 @@
</span><span class="cx">                                 text: l10n.uploadedToThisPost,
</span><span class="cx">                                 props: {
</span><span class="cx">                                         type: null,
</span><del>-                                        parent: media.view.settings.postId,
</del><ins>+                                        uploadedTo: media.view.settings.postId,
</ins><span class="cx">                                         orderby: 'menuOrder',
</span><span class="cx">                                         order: 'ASC'
</span><span class="cx">                                 },
</span></span></pre></div>
<a id="trunkwpincludesjspluploadwppluploadjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/plupload/wp-plupload.js (22950 => 22951)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/plupload/wp-plupload.js        2012-11-30 14:03:47 UTC (rev 22950)
+++ trunk/wp-includes/js/plupload/wp-plupload.js        2012-11-30 15:11:44 UTC (rev 22951)
</span><span class="lines">@@ -155,7 +155,9 @@
</span><span class="cx">                                         file: file,
</span><span class="cx">                                         uploading: true,
</span><span class="cx">                                         date: new Date(),
</span><del>-                                        filename: file.name
</del><ins>+                                        filename: file.name,
+                                        menuOrder: 0,
+                                        uploadedTo: media.model.settings.postId
</ins><span class="cx">                                 }, _.pick( file, 'loaded', 'size', 'percent' ) );
</span><span class="cx">
</span><span class="cx">                                 // Handle early mime type scanning for images.
</span></span></pre>
</div>
</div>
</body>
</html>