Skip to content
This repository
Browse code

Replacing SWFUpload with Flash-less solution

  • Loading branch information...
commit 8c8ce193f6ad697ba911c435cedcc49540eb4866 1 parent fa402e3
Samuel Luescher authored February 21, 2012
59  media_tree/static/media_tree/js/django_admin_fileuploader.js
@@ -33,9 +33,12 @@ jQuery(function($) {
33 33
 
34 34
         _setQueueMessage: function()
35 35
         {
36  
-            document.title = gettext('uploading… (%i in queue)').replace('%i', this._filesInProgress)+' – '+this._options.originalDocumentTitle;
  36
+            if (this._filesInProgress > 0) {
  37
+                document.title = gettext('uploading… (%i in queue)').replace('%i', this._filesInProgress)+' – '+this._options.originalDocumentTitle;
  38
+            } else {
  39
+                document.title = this._options.originalDocumentTitle;
  40
+            }
37 41
             var message = ngettext('%i file in queue.', '%i files in queue.', this._filesInProgress).replace('%i', this._filesInProgress);
38  
-            console.log(message);
39 42
             $.addUserMessage(message, 'upload-queue-message');
40 43
         },
41 44
 
@@ -48,9 +51,9 @@ jQuery(function($) {
48 51
         },
49 52
 
50 53
         _reloadAfterQueueComplete: function() {
51  
-            document.title = this._options.originalDocumentTitle;
  54
+            this._setQueueMessage();
52 55
             var stats = this._options.stats;
53  
-            var _this = this;
  56
+            var self = this;
54 57
             if (stats.upload_errors == 0) {
55 58
                 /*window.location.reload();*/
56 59
                 // instead, replace change list only:
@@ -61,15 +64,15 @@ jQuery(function($) {
61 64
                 $('#changelist').setUpdateReq($.ajax({
62 65
                     url: window.location.href, 
63 66
                     success: function(data, textStatus) {
64  
-                        stats = _this._options.stats;
65  
-                        if (_this._filesInProgress == 0) {
  67
+                        stats = self._options.stats;
  68
+                        if (self._filesInProgress == 0) {
66 69
                             // reload changelist contents
67 70
                             $('#changelist').updateChangelist($(data).find('#changelist').html());
68 71
                             // insert success message
69 72
                             message = ngettext('Successfully added %i file.', 'Successfully added %i files.', stats.successful_uploads).replace('%i', stats.successful_uploads);
70 73
                             $.addUserMessage(message, 'upload-queue-message');
71 74
                             // reset stats
72  
-                            _this._options.stats.successful_uploads = 0;
  75
+                            self._options.stats.successful_uploads = 0;
73 76
                         }
74 77
                     },
75 78
                     complete: function(jqXHR, textStatus) {
@@ -87,9 +90,6 @@ jQuery(function($) {
87 90
         _onComplete: function(id, fileName, result){
88 91
             qq.FileUploaderBasic.prototype._onComplete.apply(this, arguments);
89 92
 
90  
-            // the request was aborted/cancelled
91  
-            if (!this._files[id]) return;
92  
-
93 93
             // mark completed
94 94
             var item = this._getItemByFileId(id);                
95 95
             qq.remove(this._find(item, 'cancel'));
@@ -110,7 +110,6 @@ jQuery(function($) {
110 110
             
111 111
             this._setQueueMessage();
112 112
             
113  
-            console.log('queue: '+this._filesInProgress);
114 113
             if (this._filesInProgress == 0) {
115 114
                 this._reloadAfterQueueComplete();
116 115
             }
@@ -131,17 +130,10 @@ jQuery(function($) {
131 130
                 bar.addClass('complete');
132 131
             }
133 132
 
134  
-            this._setQueueMessage();        
  133
+            this._setQueueMessage();
135 134
         },
136 135
 
137 136
         _addToList: function(id, fileName){
138  
-
139  
-            var file = {
140  
-                name: fileName,
141  
-                size: 0,
142  
-                id: id
143  
-            };
144  
-            
145 137
             var c = this._options.classes;
146 138
 
147 139
             cols = [];
@@ -149,12 +141,12 @@ jQuery(function($) {
149 141
                 '<td class="nowrap"><span style="display: none;" class="upload-progress-bar-container">'
150 142
                 + '<span class="upload-progress-bar"></span></span><span class="queue-status">' 
151 143
                 + gettext('queued') + '</span>' 
152  
-                + '&nbsp;<a href="#">' + file.name + '</a>'
  144
+                + '&nbsp;<a href="#">' + fileName + '</a>'
153 145
                 + '&nbsp;<a href="#" class="' + c['cancel'] + '">'+gettext('cancel')+'</a>'
154 146
                 + '</td>');
155 147
             cols[2] = $('<td class="filesize"><span class="' + c['size'] + '"></span></td>');
156 148
 
157  
-            var row = $.makeChangelistRow(cols, this._getItemByFileId(id));
  149
+            var row = $.makeChangelistRow(cols, this._getItemByFileId(id))[0];
158 150
             row.qqFileId = id;
159 151
 
160 152
             var queuedRows = $('tr.queue');
@@ -177,5 +169,30 @@ jQuery(function($) {
177 169
                 return $('<tr id="queue-'+id+'" class="queue"></tr>');
178 170
             }
179 171
         },
  172
+
  173
+        _bindCancelEvent: function() {
  174
+            var self = this,
  175
+                list = this._listElement;            
  176
+            
  177
+            qq.attach(list, 'click', function(e){            
  178
+                e = e || window.event;
  179
+                var target = e.target || e.srcElement;
  180
+                
  181
+                if (qq.hasClass(target, self._classes.cancel)){                
  182
+                    qq.preventDefault(e);
  183
+                   
  184
+                    // patch: item is not a list item, but a table row, hence is not
  185
+                    // the cancel button's parentNode:
  186
+                    /* var item = target.parentNode; */
  187
+                    var item = $(target).closest('tr')[0];
  188
+
  189
+                    self._handler.cancel(item.qqFileId);
  190
+                    qq.remove(item);
  191
+
  192
+                    self._setQueueMessage();
  193
+                }
  194
+            });
  195
+        }    
  196
+
180 197
     });
181 198
 });

0 notes on commit 8c8ce19

Please sign in to comment.
Something went wrong with that request. Please try again.