<!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>[22816] trunk/wp-includes: Media: Add global upload progress to the sidebar.</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/22816">22816</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2012-11-22 09:32:21 +0000 (Thu, 22 Nov 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Media: Add global upload progress to the sidebar. see <a href="http://core.trac.wordpress.org/ticket/21390">#21390</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludescssmediaviewscss">trunk/wp-includes/css/media-views.css</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>
<li><a href="#trunkwpincludesmediaphp">trunk/wp-includes/media.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludescssmediaviewscss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/css/media-views.css (22815 => 22816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/css/media-views.css        2012-11-22 09:24:11 UTC (rev 22815)
+++ trunk/wp-includes/css/media-views.css        2012-11-22 09:32:21 UTC (rev 22816)
</span><span class="lines">@@ -715,20 +715,20 @@
</span><span class="cx"> */
</span><span class="cx"> .media-progress-bar {
</span><span class="cx">         position: relative;
</span><del>-        height: 8px;
</del><ins>+        height: 10px;
</ins><span class="cx">         width: 70%;
</span><span class="cx">         margin: 10px auto;
</span><del>-        padding: 2px;
-        border: 2px solid #ccc;
-        border-radius: 8px;
-        background: #fff;
</del><ins>+        border-radius: 10px;
+        background: #dfdfdf;
+        background: rgba( 0, 0, 0, 0.1 );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .media-progress-bar div {
</span><del>-        height: 8px;
-        min-width: 8px;
</del><ins>+        height: 10px;
+        min-width: 20px;
</ins><span class="cx">         width: 0;
</span><del>-        background: #ccc;
</del><ins>+        background: #aaa;
+        background: rgba( 0, 0, 0, 0.2 );
</ins><span class="cx">         border-radius: 10px;
</span><span class="cx">         -webkit-transition: width 300ms;
</span><span class="cx">         -moz-transition: width 300ms;
</span><span class="lines">@@ -737,14 +737,38 @@
</span><span class="cx">         transition: width 300ms;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+.media-uploader-status .media-progress-bar {
+        width: 100%;
+}
+
</ins><span class="cx"> .attachment-preview .media-progress-bar {
</span><span class="cx">         position: absolute;
</span><span class="cx">         top: 50%;
</span><span class="cx">         left: 15%;
</span><span class="cx">         width: 70%;
</span><del>-        margin: -8px 0 0 -4px;
</del><ins>+        margin: -5px 0 0 0;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+.media-uploader-status {
+        padding-bottom: 10px;
+        border-bottom: 1px solid #dfdfdf;
+        box-shadow: 0 1px 0 #fff;
+}
+
+.media-uploader-status .upload-details {
+        font-size: 12px;
+        color: #666;
+        text-shadow: 0 1px 0 #fff;
+}
+
+.media-uploader-status .upload-detail-separator {
+        padding: 0 4px;
+}
+
+.media-uploader-status .upload-count {
+        color: #464646;
+}
+
</ins><span class="cx"> .uploader-window {
</span><span class="cx">         position: fixed;
</span><span class="cx">         top: 0;
</span><span class="lines">@@ -1059,7 +1083,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .uploading .attachment-info .media-progress-bar {
</span><del>-        margin-top: 32px;
</del><ins>+        margin-top: 35px;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .attachment-info .thumbnail:after {
</span></span></pre></div>
<a id="trunkwpincludesjsmediamodelsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-models.js (22815 => 22816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-models.js        2012-11-22 09:24:11 UTC (rev 22815)
+++ trunk/wp-includes/js/media-models.js        2012-11-22 09:32:21 UTC (rev 22816)
</span><span class="lines">@@ -191,6 +191,18 @@
</span><span class="cx">                                         height: height
</span><span class="cx">                                 };
</span><span class="cx">                         }
</span><ins>+                },
+
+                // Truncates a string by injecting an ellipsis into the middle.
+                // Useful for filenames.
+                truncate: function( string, length, replacement ) {
+                        length = length || 30;
+                        replacement = replacement || '&hellip;';
+
+                        if ( string.length <= length )
+                                return string;
+
+                        return string.substr( 0, length / 2 ) + replacement + string.substr( -1 * length / 2 );
</ins><span class="cx">                 }
</span><span class="cx">         });
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (22815 => 22816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-11-22 09:24:11 UTC (rev 22815)
+++ trunk/wp-includes/js/media-views.js        2012-11-22 09:32:21 UTC (rev 22816)
</span><span class="lines">@@ -255,7 +255,8 @@
</span><span class="cx">                         toolbar: 'main-attachments',
</span><span class="cx">                         sidebar: 'settings',
</span><span class="cx">                         searchable: true,
</span><del>-                        filterable: false
</del><ins>+                        filterable: false,
+                        uploads: true
</ins><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 initialize: function() {
</span><span class="lines">@@ -476,6 +477,7 @@
</span><span class="cx">                         id: 'upload',
</span><span class="cx">                         content: 'upload',
</span><span class="cx">                         toolbar: 'empty',
</span><ins>+                        uploads: true,
</ins><span class="cx">
</span><span class="cx">                         // The state to navigate to when files are uploading.
</span><span class="cx">                         libraryState: 'library'
</span><span class="lines">@@ -1290,7 +1292,7 @@
</span><span class="cx">                                 model: state,
</span><span class="cx">                                 sortable: state.get('sortable'),
</span><span class="cx">                                 search: state.get('searchable'),
</span><del>-                                upload: state.get('upload'),
</del><ins>+                                uploads: state.get('uploads'),
</ins><span class="cx">                                 filters: state.get('filterable'),
</span><span class="cx">                                 display: state.get('displaySettings'),
</span><span class="cx">
</span><span class="lines">@@ -1827,6 +1829,85 @@
</span><span class="cx">         });
</span><span class="cx">
</span><span class="cx">         /**
</span><ins>+         * wp.media.view.UploaderStatus
+         */
+        media.view.UploaderStatus = media.View.extend({
+                className: 'media-uploader-status',
+                template: media.template('uploader-status'),
+
+                initialize: function() {
+                        this.controller = this.options.controller;
+
+                        this.queue = wp.Uploader.queue;
+                        this.queue.on( 'add remove reset', this.visibility, this );
+                        this.queue.on( 'add remove reset change:percent', this.progress, this );
+                        this.queue.on( 'add remove reset change:uploading', this.info, this );
+
+                        this.errors = wp.Uploader.errors;
+                },
+
+                dispose: function() {
+                        wp.Uploader.queue.off( null, null, this );
+                        media.View.prototype.dispose.apply( this, arguments );
+                        return this;
+                },
+
+                visibility: function() {
+                        this.$el.toggleClass( 'uploading', !! this.queue.length );
+                        this.$el.toggle( !! this.queue.length || !! this.errors.length );
+                },
+
+                ready: function() {
+                        _.each({
+                                '$bar': '.media-progress-bar div',
+                                '$index': '.upload-index',
+                                '$total': '.upload-total',
+                                '$filename': '.upload-filename'
+                        }, function( selector, key ) {
+                                this[ key ] = this.$( selector );
+                        }, this );
+
+                        this.visibility();
+                        this.progress();
+                        this.info();
+                },
+
+                progress: function() {
+                        var queue = this.queue,
+                                $bar = this.$bar,
+                                memo = 0;
+
+                        if ( ! $bar || ! queue.length )
+                                return;
+
+                        $bar.width( ( queue.reduce( function( memo, attachment ) {
+                                if ( ! attachment.get('uploading') )
+                                        return memo + 100;
+
+                                var percent = attachment.get('percent');
+                                return memo + ( _.isNumber( percent ) ? percent : 100 );
+                        }, 0 ) / queue.length ) + '%' );
+                },
+
+                info: function() {
+                        var queue = this.queue,
+                                index = 0, active;
+
+                        if ( ! queue.length )
+                                return;
+
+                        active = this.queue.find( function( attachment, i ) {
+                                index = i;
+                                return attachment.get('uploading');
+                        });
+
+                        this.$index.text( index + 1 );
+                        this.$total.text( queue.length );
+                        this.$filename.html( active ? media.truncate( _.escape( active.get('filename') ), 24 ) : '' );
+                }
+        });
+
+        /**
</ins><span class="cx">          * wp.media.view.Toolbar
</span><span class="cx">          */
</span><span class="cx">         media.view.Toolbar = media.View.extend({
</span><span class="lines">@@ -2860,7 +2941,7 @@
</span><span class="cx">                         _.defaults( this.options, {
</span><span class="cx">                                 filters: false,
</span><span class="cx">                                 search: true,
</span><del>-                                upload: false,
</del><ins>+                                uploads: false,
</ins><span class="cx">                                 display: false,
</span><span class="cx">
</span><span class="cx">                                 AttachmentView: media.view.Attachment.Library
</span><span class="lines">@@ -2914,15 +2995,6 @@
</span><span class="cx">                                         priority: -40
</span><span class="cx">                                 }) );
</span><span class="cx">                         }
</span><del>-
-                        if ( this.options.upload && this.controller.uploader ) {
-                                this.toolbar.set( 'upload', new media.view.Button( _.extend({
-                                        el: this.controller.uploader.$browser.detach()[0],
-                                        priority: -60,
-                                        size: 'large',
-                                        text: l10n.selectFiles
-                                }, this.options.upload ) ).render() );
-                        }
</del><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 createAttachments: function() {
</span><span class="lines">@@ -2941,14 +3013,26 @@
</span><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 createSidebar: function() {
</span><del>-                        this.sidebar = new media.view.Sidebar({
-                                controller: this.controller
-                        });
</del><ins>+                        var options = this.options,
+                                selection = options.selection,
+                                sidebar = this.sidebar = new media.view.Sidebar({
+                                        controller: this.controller
+                                });
</ins><span class="cx">
</span><del>-                        this.views.add( this.sidebar );
</del><ins>+                        this.views.add( sidebar );
</ins><span class="cx">
</span><del>-                        this.options.selection.on( 'selection:single', this.createSingle, this );
-                        this.options.selection.on( 'selection:unsingle', this.disposeSingle, this );
</del><ins>+                        if ( options.uploads && this.controller.uploader ) {
+                                sidebar.set( 'uploads', new media.view.UploaderStatus({
+                                        controller: this.controller,
+                                        priority: 40
+                                }) );
+                        }
+
+                        selection.on( 'selection:single', this.createSingle, this );
+                        selection.on( 'selection:unsingle', this.disposeSingle, this );
+
+                        if ( selection.single() )
+                                this.createSingle();
</ins><span class="cx">                 },
</span><span class="cx">
</span><span class="cx">                 createSingle: function() {
</span></span></pre></div>
<a id="trunkwpincludesjspluploadwppluploadjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/plupload/wp-plupload.js (22815 => 22816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/plupload/wp-plupload.js        2012-11-22 09:24:11 UTC (rev 22815)
+++ trunk/wp-includes/js/plupload/wp-plupload.js        2012-11-22 09:32:21 UTC (rev 22816)
</span><span class="lines">@@ -86,6 +86,13 @@
</span><span class="cx">                 error = function( message, data, file ) {
</span><span class="cx">                         if ( file.attachment )
</span><span class="cx">                                 file.attachment.destroy();
</span><ins>+
+                        Uploader.errors.unshift({
+                                message: message,
+                                data: data,
+                                file: file
+                        });
+
</ins><span class="cx">                         self.error( message, data, file );
</span><span class="cx">                 };
</span><span class="cx">
</span><span class="lines">@@ -284,6 +291,7 @@
</span><span class="cx">         });
</span><span class="cx">
</span><span class="cx">         Uploader.queue = new wp.media.model.Attachments( [], { query: false });
</span><ins>+        Uploader.errors = new Backbone.Collection();
</ins><span class="cx">
</span><span class="cx">         exports.Uploader = Uploader;
</span><span class="cx"> })( wp, jQuery );
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (22815 => 22816)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-11-22 09:24:11 UTC (rev 22815)
+++ trunk/wp-includes/media.php        2012-11-22 09:32:21 UTC (rev 22816)
</span><span class="lines">@@ -1443,6 +1443,20 @@
</span><span class="cx">                 </div>
</span><span class="cx">         </script>
</span><span class="cx">
</span><ins>+        <script type="text/html" id="tmpl-uploader-status">
+                <h3><?php _e( 'Uploading' ); ?></h3>
+                <div class="media-progress-bar"><div></div></div>
+                <div class="upload-details">
+                        <span class="upload-count">
+                                <span class="upload-index"></span> / <span class="upload-total"></span>
+                        </span>
+                        <span class="upload-detail-separator">&ndash;</span>
+                        <span class="upload-filename"></span>
+                </div>
+                <div class="upload-errors">
+                </div>
+        </script>
+
</ins><span class="cx">         <script type="text/html" id="tmpl-attachment">
</span><span class="cx">                 <div class="attachment-preview type-{{ data.type }} subtype-{{ data.subtype }} {{ data.orientation }}">
</span><span class="cx">                         <# if ( data.uploading ) { #>
</span></span></pre>
</div>
</div>
</body>
</html>