Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/resources/file_manager/js/butter_bar.js

Issue 10914075: [filemanager] Implementing undo delete functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * The minimum about of time to display the butter bar for, in ms. 6 * The minimum about of time to display the butter bar for, in ms.
7 * Justification is 1000ms for minimum display time plus 300ms for transition 7 * Justification is 1000ms for minimum display time plus 300ms for transition
8 * duration. 8 * duration.
9 */ 9 */
10 var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300; 10 var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300;
11 11
12 /** 12 /**
13 * Butter bar is shown on top of the file list and is used to show the copy 13 * Butter bar is shown on top of the file list and is used to show the copy
14 * progress and other messages. 14 * progress and other messages.
15 * @constructor 15 * @constructor
16 * @param {HTMLElement} dialogDom FileManager top-level div. 16 * @param {HTMLElement} dialogDom FileManager top-level div.
17 * @param {FileCopyManagerWrapper} copyManager The copy manager. 17 * @param {FileCopyManagerWrapper} copyManager The copy manager.
18 * @param {MetadataCache} metadataCache The metadata cache.
18 */ 19 */
19 function ButterBar(dialogDom, copyManager) { 20 function ButterBar(dialogDom, copyManager, metadataCache) {
20 this.dialogDom_ = dialogDom; 21 this.dialogDom_ = dialogDom;
21 this.butter_ = this.dialogDom_.querySelector('#butter-bar'); 22 this.butter_ = this.dialogDom_.querySelector('#butter-bar');
22 this.document_ = this.butter_.ownerDocument; 23 this.document_ = this.butter_.ownerDocument;
23 this.copyManager_ = copyManager; 24 this.copyManager_ = copyManager;
25 this.metadataCache_ = metadataCache;
24 this.hideTimeout_ = null; 26 this.hideTimeout_ = null;
25 this.showTimeout_ = null; 27 this.showTimeout_ = null;
26 this.lastShowTime_ = 0; 28 this.lastShowTime_ = 0;
29 this.deleteTaskId_ = null;
27 30
28 this.copyManager_.addEventListener('copy-progress', 31 this.copyManager_.addEventListener('copy-progress',
29 this.onCopyProgress_.bind(this)); 32 this.onCopyProgress_.bind(this));
33 this.copyManager_.addEventListener('delete',
34 this.onDelete_.bind(this));
30 } 35 }
31 36
32 /** 37 /**
33 * @return {boolean} True if visible. 38 * @return {boolean} True if visible.
34 * @private 39 * @private
35 */ 40 */
36 ButterBar.prototype.isVisible_ = function() { 41 ButterBar.prototype.isVisible_ = function() {
37 return this.butter_.classList.contains('visible'); 42 return this.butter_.classList.contains('visible');
38 }; 43 };
39 44
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 this.show(progressString, options); 227 this.show(progressString, options);
223 } 228 }
224 }; 229 };
225 230
226 /** 231 /**
227 * 'copy-progress' event handler. Show progress or an appropriate message. 232 * 'copy-progress' event handler. Show progress or an appropriate message.
228 * @private 233 * @private
229 * @param {cr.Event} event A 'copy-progress' event from FileCopyManager. 234 * @param {cr.Event} event A 'copy-progress' event from FileCopyManager.
230 */ 235 */
231 ButterBar.prototype.onCopyProgress_ = function(event) { 236 ButterBar.prototype.onCopyProgress_ = function(event) {
237 // Delete operation has higher priority.
238 if (this.deleteTaskId_) return;
239
232 if (event.reason != 'PROGRESS') 240 if (event.reason != 'PROGRESS')
233 this.clearShowTimeout_(); 241 this.clearShowTimeout_();
234 242
235 switch (event.reason) { 243 switch (event.reason) {
236 case 'BEGIN': 244 case 'BEGIN':
237 this.showTimeout_ = setTimeout(function() { 245 this.showTimeout_ = setTimeout(function() {
238 this.showTimeout_ = null; 246 this.showTimeout_ = null;
239 this.showProgress_(); 247 this.showProgress_();
240 }.bind(this), 500); 248 }.bind(this), 500);
241 break; 249 break;
(...skipping 29 matching lines...) Expand all
271 } else { 279 } else {
272 this.showError_(strf(this.transferType_() + '_UNEXPECTED_ERROR', 280 this.showError_(strf(this.transferType_() + '_UNEXPECTED_ERROR',
273 event.error)); 281 event.error));
274 } 282 }
275 break; 283 break;
276 284
277 default: 285 default:
278 console.log('Unknown "copy-progress" event reason: ' + event.reason); 286 console.log('Unknown "copy-progress" event reason: ' + event.reason);
279 } 287 }
280 }; 288 };
289
290 /**
291 * Informs user that files were deleted with an undo option.
292 * In fact, files will be really deleted after timeout.
293 * @param {Array.<Entry>} entries The entries to delete.
294 */
295 ButterBar.prototype.initiateDelete = function(entries) {
Vladislav Kaznacheev 2012/09/04 14:50:38 It feels unnatural to have this functionality in t
dgozman 2012/09/07 11:05:10 Butter bar has to own the deleteTaskId. So, I thin
296 if (this.deleteTaskId_) {
297 this.copyManager_.forceDeleteTask(this.deleteTaskId_);
298 this.deleteTaskId_ = null;
299 }
300
301 var callback = function(id) {
302 if (this.deleteTaskId_)
303 console.error('Already got a deleteTaskId');
304 this.deleteTaskId_ = id;
305 }.bind(this);
306
307 this.copyManager_.deleteEntries(entries, callback);
308 };
309
310 /**
311 * 'delete' event handler. Shows information about deleting files.
312 * @private
313 * @param {cr.Event} event A 'delete' event from FileCopyManager.
314 */
315 ButterBar.prototype.onDelete_ = function(event) {
316 if (event.id != this.deleteTaskId_) return;
317
318 switch (event.reason) {
319 case 'SCHEDULED':
320 var props = [];
321 for (var i = 0; i < event.urls.length; i++) {
322 props[i] = {deleted: true};
323 }
324 this.metadataCache_.set(event.urls, 'internal', props);
325
326 var title = strf('DELETED_MESSAGE_PLURAL', event.urls.length);
327 if (event.urls.length == 1) {
328 var fullPath = util.extractFilePath(event.urls[0]);
329 var fileName = PathUtil.split(fullPath).pop();
330 title = strf('DELETED_MESSAGE', fileName);
331 }
332
333 this.show(title, {
334 // TODO: show the link 'undo' instead of X sign.
335 actions: {'Undo': this.undoDelete_.bind(this)},
336 timeout: 0
337 });
338 break;
339
340 case 'CANCELLED':
341 case 'SUCCESS':
342 var props = [];
343 for (var i = 0; i < event.urls.length; i++) {
344 props[i] = {deleted: false};
345 }
346 this.metadataCache_.set(event.urls, 'internal', props);
347
348 this.deleteTaskId_ = null;
349 this.hide_();
350 break;
351
352 default:
353 console.log('Unknown "delete" event reason: ' + event.reason);
354 }
355 };
356
357 /**
358 * Undo the delete operation.
359 */
360 ButterBar.prototype.undoDelete_ = function() {
361 this.copyManager_.cancelDeleteTask(this.deleteTaskId_);
362 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698