OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * Empty folder controller. |
| 7 * @param {!EmptyFolder} emptyFolder Empty folder ui. |
| 8 * @param {!DirectoryModel} directoryModel Directory model. |
| 9 * @constructor |
| 10 * @struct |
| 11 */ |
| 12 function EmptyFolderController(emptyFolder, directoryModel) { |
| 13 /** |
| 14 * @private {!EmptyFolder} |
| 15 */ |
| 16 this.emptyFolder_ = emptyFolder; |
| 17 |
| 18 /** |
| 19 * @private {!DirectoryModel} |
| 20 */ |
| 21 this.directoryModel_ = directoryModel; |
| 22 |
| 23 /** |
| 24 * @private {!FileListModel} |
| 25 */ |
| 26 this.dataModel_ = assert(this.directoryModel_.getFileList()); |
| 27 |
| 28 /** |
| 29 * @private {boolean} |
| 30 */ |
| 31 this.isScanning_ = false; |
| 32 |
| 33 this.directoryModel_.addEventListener( |
| 34 'scan-started', this.onScanStarted_.bind(this)); |
| 35 this.directoryModel_.addEventListener( |
| 36 'scan-failed', this.onScanFinished_.bind(this)); |
| 37 this.directoryModel_.addEventListener( |
| 38 'scan-cancelled', this.onScanFinished_.bind(this)); |
| 39 this.directoryModel_.addEventListener( |
| 40 'scan-completed', this.onScanFinished_.bind(this)); |
| 41 this.directoryModel_.addEventListener( |
| 42 'rescan-completed', this.onScanFinished_.bind(this)); |
| 43 |
| 44 this.dataModel_.addEventListener('splice', this.onSplice_.bind(this)); |
| 45 } |
| 46 |
| 47 /** |
| 48 * Handles splice event. |
| 49 * @private |
| 50 */ |
| 51 EmptyFolderController.prototype.onSplice_ = function() { |
| 52 this.update_(); |
| 53 }; |
| 54 |
| 55 /** |
| 56 * Handles scan start. |
| 57 * @private |
| 58 */ |
| 59 EmptyFolderController.prototype.onScanStarted_ = function() { |
| 60 this.isScanning_ = true; |
| 61 this.update_(); |
| 62 }; |
| 63 |
| 64 /** |
| 65 * Handles scan finish. |
| 66 * @private |
| 67 */ |
| 68 EmptyFolderController.prototype.onScanFinished_ = function() { |
| 69 this.isScanning_ = false; |
| 70 this.update_(); |
| 71 }; |
| 72 |
| 73 /** |
| 74 * Updates visibility of empty folder UI. |
| 75 * @private |
| 76 */ |
| 77 EmptyFolderController.prototype.update_ = function() { |
| 78 if (!this.isScanning_ && this.dataModel_.length === 0) |
| 79 this.emptyFolder_.show(); |
| 80 else |
| 81 this.emptyFolder_.hide(); |
| 82 }; |
OLD | NEW |