Chromium Code Reviews| Index: chrome/browser/resources/file_manager/js/file_manager_butter_bar.js |
| diff --git a/chrome/browser/resources/file_manager/js/file_manager_butter_bar.js b/chrome/browser/resources/file_manager/js/file_manager_butter_bar.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1a091a6276fe52c08d735e7f066534dc705f3d56 |
| --- /dev/null |
| +++ b/chrome/browser/resources/file_manager/js/file_manager_butter_bar.js |
| @@ -0,0 +1,120 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * Butter bar is shown on top of the file list and is used to show the copy |
| + * progress and other messages. |
| + * @constructor |
| + * @param {HTMLElement} dialogDom FileManager top-level div. |
| + * @param {FileCopyManagerWrapper} copyManager The copy manager. |
| + */ |
| +function FileManagerButterBar(dialogDom, copyManager) { |
| + ButterBar.call(this, dialogDom); |
| + this.copyManager_ = copyManager; |
| + |
| + this.copyManager_.addEventListener('copy-progress', |
| + this.onCopyProgress_.bind(this)); |
| +} |
| + |
| +FileManagerButterBar.prototype = { |
|
Oleg Eterevsky
2012/09/07 08:43:50
In FileManager we use a different style for class
|
| + __proto__: ButterBar.prototype, |
| + |
| + /** |
| + * @private |
| + * @return {string?} The type of operation. |
| + */ |
| + transferType_: function() { |
| + var progress = this.progress_; |
| + if (!progress || |
| + progress.pendingMoves === 0 && progress.pendingCopies === 0) |
| + return 'TRANSFER'; |
| + |
| + if (progress.pendingMoves > 0) { |
| + if (progress.pendingCopies > 0) |
| + return 'TRANSFER'; |
| + return 'MOVE'; |
| + } |
| + |
| + return 'COPY'; |
| + }, |
| + |
| + /** |
| + * Set up butter bar for showing copy progress. |
| + * @private |
| + */ |
| + showProgress_: function() { |
| + this.progress_ = this.copyManager_.getStatus(); |
| + var options = {progress: this.progress_.percentage, actions: {}, |
| + timeout: 0}; |
| + |
| + var type = this.transferType_(); |
| + var progressString = (this.progress_.pendingItems === 1) ? |
| + strf(type + '_FILE_NAME', this.progress_.filename) : |
| + strf(type + '_ITEMS_REMAINING', this.progress_.pendingItems); |
| + |
| + if (this.isVisible_()) { |
| + this.update_(progressString, options); |
| + } else { |
| + options.actions[str('CANCEL_LABEL')] = |
| + this.copyManager_.requestCancel.bind(this.copyManager_); |
| + this.show(progressString, options); |
| + } |
| + }, |
| + |
| + /** |
| + * 'copy-progress' event handler. Show progress or an appropriate message. |
| + * @private |
| + * @param {cr.Event} event A 'copy-progress' event from FileCopyManager. |
| + */ |
| + onCopyProgress_: function(event) { |
| + if (event.reason != 'PROGRESS') |
| + this.clearShowTimeout_(); |
| + |
| + switch (event.reason) { |
| + case 'BEGIN': |
| + this.showTimeout_ = setTimeout(function() { |
| + this.showTimeout_ = null; |
| + this.showProgress_(); |
| + }.bind(this), 500); |
| + break; |
| + |
| + case 'PROGRESS': |
| + this.showProgress_(); |
| + break; |
| + |
| + case 'SUCCESS': |
| + this.hide_(); |
| + break; |
| + |
| + case 'CANCELLED': |
| + this.show(str(this.transferType_() + '_CANCELLED'), {timeout: 1000}); |
| + break; |
| + |
| + case 'ERROR': |
| + if (event.error.reason === 'TARGET_EXISTS') { |
| + var name = event.error.data.name; |
| + if (event.error.data.isDirectory) |
| + name += '/'; |
| + this.showError_(strf(this.transferType_() + |
| + '_TARGET_EXISTS_ERROR', name)); |
| + } else if (event.error.reason === 'FILESYSTEM_ERROR') { |
| + if (event.error.data.toGDrive && |
| + event.error.data.code === FileError.QUOTA_EXCEEDED_ERR) { |
| + // The alert will be shown in FileManager.onCopyProgress_. |
| + this.hide_(); |
| + } else { |
| + this.showError_(strf(this.transferType_() + '_FILESYSTEM_ERROR', |
| + util.getFileErrorString(event.error.data.code))); |
| + } |
| + } else { |
| + this.showError_(strf(this.transferType_() + '_UNEXPECTED_ERROR', |
| + event.error)); |
| + } |
| + break; |
| + |
| + default: |
| + console.log('Unknown "copy-progress" event reason: ' + event.reason); |
| + } |
| + } |
| +}; |