| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 cr.define('downloads', function() { | 5 cr.define('downloads', function() { |
| 6 var Manager = Polymer({ | 6 var Manager = Polymer({ |
| 7 is: 'downloads-manager', | 7 is: 'downloads-manager', |
| 8 | 8 |
| 9 properties: { | 9 properties: { |
| 10 /** @private */ | 10 /** @private */ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 listeners: { | 46 listeners: { |
| 47 'downloads-list.scroll': 'onListScroll_', | 47 'downloads-list.scroll': 'onListScroll_', |
| 48 'toolbar.search-changed': 'onSearchChanged_', | 48 'toolbar.search-changed': 'onSearchChanged_', |
| 49 }, | 49 }, |
| 50 | 50 |
| 51 observers: [ | 51 observers: [ |
| 52 'itemsChanged_(items_.*)', | 52 'itemsChanged_(items_.*)', |
| 53 ], | 53 ], |
| 54 | 54 |
| 55 /** @private {!PromiseResolver} */ |
| 56 loaded_: new PromiseResolver, |
| 57 |
| 55 /** @private */ | 58 /** @private */ |
| 56 clearAll_: function() { | 59 clearAll_: function() { |
| 57 this.set('items_', []); | 60 this.set('items_', []); |
| 58 }, | 61 }, |
| 59 | 62 |
| 60 /** @private */ | 63 /** @private */ |
| 61 hasDownloadsChanged_: function() { | 64 hasDownloadsChanged_: function() { |
| 62 if (loadTimeData.getBoolean('allowDeletingHistory')) | 65 if (loadTimeData.getBoolean('allowDeletingHistory')) |
| 63 this.$.toolbar.downloadsShowing = this.hasDownloads_; | 66 this.$.toolbar.downloadsShowing = this.hasDownloads_; |
| 64 | 67 |
| 65 if (this.hasDownloads_) | 68 if (this.hasDownloads_) |
| 66 this.$['downloads-list'].fire('iron-resize'); | 69 this.$['downloads-list'].fire('iron-resize'); |
| 67 }, | 70 }, |
| 68 | 71 |
| 69 /** | 72 /** |
| 70 * @param {number} index | 73 * @param {number} index |
| 71 * @param {!Array<!downloads.Data>} list | 74 * @param {!Array<!downloads.Data>} list |
| 72 * @private | 75 * @private |
| 73 */ | 76 */ |
| 74 insertItems_: function(index, list) { | 77 insertItems_: function(index, list) { |
| 75 this.splice.apply(this, ['items_', index, 0].concat(list)); | 78 this.splice.apply(this, ['items_', index, 0].concat(list)); |
| 76 this.updateHideDates_(index, index + list.length); | 79 this.updateHideDates_(index, index + list.length); |
| 77 this.removeAttribute('loading'); | 80 |
| 81 if (this.hasAttribute('loading')) { |
| 82 this.removeAttribute('loading'); |
| 83 this.loaded_.resolve(); |
| 84 } |
| 85 |
| 78 this.spinnerActive_ = false; | 86 this.spinnerActive_ = false; |
| 79 }, | 87 }, |
| 80 | 88 |
| 81 /** @private */ | 89 /** @private */ |
| 82 itemsChanged_: function() { | 90 itemsChanged_: function() { |
| 83 this.hasDownloads_ = this.items_.length > 0; | 91 this.hasDownloads_ = this.items_.length > 0; |
| 84 }, | 92 }, |
| 85 | 93 |
| 86 /** | 94 /** |
| 87 * @return {string} The text to show when no download items are showing. | 95 * @return {string} The text to show when no download items are showing. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 /** @private */ | 135 /** @private */ |
| 128 onListScroll_: function() { | 136 onListScroll_: function() { |
| 129 var list = this.$['downloads-list']; | 137 var list = this.$['downloads-list']; |
| 130 if (list.scrollHeight - list.scrollTop - list.offsetHeight <= 100) { | 138 if (list.scrollHeight - list.scrollTop - list.offsetHeight <= 100) { |
| 131 // Approaching the end of the scrollback. Attempt to load more items. | 139 // Approaching the end of the scrollback. Attempt to load more items. |
| 132 downloads.ActionService.getInstance().loadMore(); | 140 downloads.ActionService.getInstance().loadMore(); |
| 133 } | 141 } |
| 134 this.hasShadow_ = list.scrollTop > 0; | 142 this.hasShadow_ = list.scrollTop > 0; |
| 135 }, | 143 }, |
| 136 | 144 |
| 137 /** @private */ | 145 /** |
| 146 * @return {!Promise} |
| 147 * @private |
| 148 */ |
| 138 onLoad_: function() { | 149 onLoad_: function() { |
| 139 cr.ui.decorate('command', cr.ui.Command); | 150 cr.ui.decorate('command', cr.ui.Command); |
| 140 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); | 151 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); |
| 141 document.addEventListener('command', this.onCommand_.bind(this)); | 152 document.addEventListener('command', this.onCommand_.bind(this)); |
| 142 | 153 |
| 143 downloads.ActionService.getInstance().loadMore(); | 154 downloads.ActionService.getInstance().loadMore(); |
| 155 return this.loaded_.promise; |
| 144 }, | 156 }, |
| 145 | 157 |
| 146 /** @private */ | 158 /** @private */ |
| 147 onSearchChanged_: function() { | 159 onSearchChanged_: function() { |
| 148 this.inSearchMode_ = downloads.ActionService.getInstance().isSearching(); | 160 this.inSearchMode_ = downloads.ActionService.getInstance().isSearching(); |
| 149 }, | 161 }, |
| 150 | 162 |
| 151 /** | 163 /** |
| 152 * @param {number} index | 164 * @param {number} index |
| 153 * @private | 165 * @private |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 /** @return {!downloads.Manager} */ | 206 /** @return {!downloads.Manager} */ |
| 195 Manager.get = function() { | 207 Manager.get = function() { |
| 196 return /** @type {!downloads.Manager} */( | 208 return /** @type {!downloads.Manager} */( |
| 197 queryRequiredElement('downloads-manager')); | 209 queryRequiredElement('downloads-manager')); |
| 198 }; | 210 }; |
| 199 | 211 |
| 200 Manager.insertItems = function(index, list) { | 212 Manager.insertItems = function(index, list) { |
| 201 Manager.get().insertItems_(index, list); | 213 Manager.get().insertItems_(index, list); |
| 202 }; | 214 }; |
| 203 | 215 |
| 216 /** @return {!Promise} */ |
| 204 Manager.onLoad = function() { | 217 Manager.onLoad = function() { |
| 205 Manager.get().onLoad_(); | 218 return Manager.get().onLoad_(); |
| 206 }; | 219 }; |
| 207 | 220 |
| 208 Manager.removeItem = function(index) { | 221 Manager.removeItem = function(index) { |
| 209 Manager.get().removeItem_(index); | 222 Manager.get().removeItem_(index); |
| 210 }; | 223 }; |
| 211 | 224 |
| 212 Manager.updateItem = function(index, data) { | 225 Manager.updateItem = function(index, data) { |
| 213 Manager.get().updateItem_(index, data); | 226 Manager.get().updateItem_(index, data); |
| 214 }; | 227 }; |
| 215 | 228 |
| 216 return {Manager: Manager}; | 229 return {Manager: Manager}; |
| 217 }); | 230 }); |
| OLD | NEW |