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

Unified Diff: chrome/browser/resources/md_downloads/manager.js

Issue 1240853002: Slice MD downloads into more components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: license Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_downloads/manager.js
diff --git a/chrome/browser/resources/md_downloads/manager.js b/chrome/browser/resources/md_downloads/manager.js
index ebd003f47fc0e37e53ba7f5370eda0efaa46291a..065290d2558067425fec16a78087f81cb7821561 100644
--- a/chrome/browser/resources/md_downloads/manager.js
+++ b/chrome/browser/resources/md_downloads/manager.js
@@ -3,43 +3,75 @@
// found in the LICENSE file.
cr.define('downloads', function() {
- /**
- * Class to own and manage download items.
- * @constructor
- */
- function Manager() {}
+ var Manager = Polymer({
+ is: 'downloads-manager',
- cr.addSingletonGetter(Manager);
+ created: function() {
+ /** @private {!downloads.ActionService} */
+ this.actionService_ = new downloads.ActionService;
+ },
+
+ properties: {
+ hasDownloads_: {
+ type: Boolean,
+ value: false,
+ },
+ },
- Manager.prototype = {
- /** @private {string} */
- searchText_: '',
+ /**
+ * @return {number} A guess at how many items could be visible at once.
+ * @private
+ */
+ guesstimateNumberOfVisibleItems_: function() {
+ var toolbarHeight = this.$.toolbar.offsetHeight;
+ return Math.floor((window.innerHeight - toolbarHeight) / 46) + 1;
+ },
+
+ /**
+ * @param {Event} e
+ * @private
+ */
+ onCanExecute_: function(e) {
+ e = /** @type {cr.ui.CanExecuteEvent} */(e);
+ switch (e.command.id) {
+ case 'undo-command':
+ e.canExecute = this.$.toolbar.canUndo();
+ break;
+ case 'clear-all-command':
+ e.canExecute = true;
+ break;
+ }
+ },
/**
- * Sets the search text, updates related UIs, and tells the browser.
- * @param {string} searchText Text we're searching for.
+ * @param {Event} e
* @private
*/
- setSearchText_: function(searchText) {
- this.searchText_ = searchText;
+ onCommand_: function(e) {
+ if (e.command.id == 'clear-all-command')
+ this.actionService_.clearAll();
+ else if (e.command.id == 'undo-command')
+ this.actionService_.undo();
+ },
- $('downloads-summary-text').textContent = this.searchText_ ?
- loadTimeData.getStringF('searchResultsFor', this.searchText_) : '';
+ /** @private */
+ onLoad_: function() {
+ this.$.toolbar.setActionService(this.actionService_);
+
+ cr.ui.decorate('command', cr.ui.Command);
+ document.addEventListener('canExecute', this.onCanExecute_.bind(this));
+ document.addEventListener('command', this.onCommand_.bind(this));
- // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']).
- function trim(s) { return s.trim(); }
- chrome.send('getDownloads', searchText.split(/"([^"]*)"/).map(trim));
+ // Shows all downloads.
+ this.actionService_.search('');
},
/**
- * @return {number} A guess at how many items could be visible at once.
+ * @return {number} The number of downloads shown on the page.
* @private
*/
- guesstimateNumberOfVisibleItems_: function() {
- var toolbarHeight = $('downloads-toolbar').offsetHeight;
- var summaryHeight = $('downloads-summary').offsetHeight;
- var nonItemSpace = toolbarHeight + summaryHeight;
- return Math.floor((window.innerHeight - nonItemSpace) / 46) + 1;
+ size_: function() {
+ return this.items_.length;
},
/**
@@ -67,7 +99,8 @@ cr.define('downloads', function() {
var id = data.id;
// Re-use old items when possible (saves work, preserves focus).
- var item = oldIdMap[id] || new downloads.ItemView(this.iconLoader_);
+ var item = oldIdMap[id] ||
+ new downloads.ItemView(this.iconLoader_, this.actionService_);
this.idMap_[id] = item; // Associated by ID for fast lookup.
this.items_.push(item); // Add to sorted list for order.
@@ -102,19 +135,13 @@ cr.define('downloads', function() {
before = this.items_[j];
}
// If |before| is null, |item| will just get added at the end.
- this.node_.insertBefore(item, before);
+ this.$['downloads-list'].insertBefore(item, before);
}
- var noDownloadsOrResults = $('no-downloads-or-results');
- noDownloadsOrResults.textContent = loadTimeData.getString(
- this.searchText_ ? 'noSearchResults' : 'noDownloads');
-
- var hasDownloads = this.size_() > 0;
- this.node_.hidden = !hasDownloads;
- noDownloadsOrResults.hidden = hasDownloads;
+ this.hasDownloads_ = this.size_() > 0;
if (loadTimeData.getBoolean('allowDeletingHistory'))
- $('clear-all').hidden = !hasDownloads || this.searchText_.length > 0;
+ this.$.toolbar.canClearAll = this.hasDownloads_;
},
/**
@@ -124,108 +151,22 @@ cr.define('downloads', function() {
updateItem_: function(data) {
this.idMap_[data.id].update(data);
},
+ });
- /**
- * @return {number} The number of downloads shown on the page.
- * @private
- */
- size_: function() {
- return this.items_.length;
- },
-
- /** @private */
- clearAll_: function() {
- if (loadTimeData.getBoolean('allowDeletingHistory')) {
- chrome.send('clearAll');
- this.setSearchText_('');
- }
- },
-
- /** @private */
- onLoad_: function() {
- this.node_ = $('downloads-display');
-
- $('clear-all').onclick = function() {
- this.clearAll_();
- }.bind(this);
-
- $('open-downloads-folder').onclick = function() {
- chrome.send('openDownloadsFolder');
- };
-
- $('search-button').onclick = function() {
- if (!$('search-term').hidden)
- return;
- $('clear-search').hidden = false;
- $('search-term').hidden = false;
- };
-
- $('clear-search').onclick = function() {
- $('clear-search').hidden = true;
- $('search-term').hidden = true;
- $('search-term').value = '';
- this.setSearchText_('');
- }.bind(this);
-
- // TODO(dbeam): this previously used onsearch, which batches keystrokes
- // together. This should probably be re-instated eventually.
- $('search-term').oninput = function(e) {
- this.setSearchText_($('search-term').value);
- }.bind(this);
-
- cr.ui.decorate('command', cr.ui.Command);
- document.addEventListener('canExecute', this.onCanExecute_.bind(this));
- document.addEventListener('command', this.onCommand_.bind(this));
-
- this.setSearchText_('');
- },
-
- /**
- * @param {Event} e
- * @private
- */
- onCanExecute_: function(e) {
- e = /** @type {cr.ui.CanExecuteEvent} */(e);
- switch (e.command.id) {
- case 'undo-command':
- e.canExecute = !$('search-term').contains(document.activeElement);
- break;
- case 'clear-all-command':
- e.canExecute = true;
- break;
- }
- },
-
- /**
- * @param {Event} e
- * @private
- */
- onCommand_: function(e) {
- if (e.command.id == 'undo-command')
- chrome.send('undo');
- else if (e.command.id == 'clear-all-command')
- this.clearAll_();
- },
+ Manager.size = function() {
+ return document.querySelector('downloads-manager').size_();
};
Manager.updateAll = function(list) {
- Manager.getInstance().updateAll_(list);
+ document.querySelector('downloads-manager').updateAll_(list);
};
Manager.updateItem = function(item) {
- Manager.getInstance().updateItem_(item);
- };
-
- Manager.setSearchText = function(searchText) {
- Manager.getInstance().setSearchText_(searchText);
+ document.querySelector('downloads-manager').updateItem_(item);
};
Manager.onLoad = function() {
- Manager.getInstance().onLoad_();
- };
-
- Manager.size = function() {
- return Manager.getInstance().size_();
+ document.querySelector('downloads-manager').onLoad_();
};
return {Manager: Manager};
« no previous file with comments | « chrome/browser/resources/md_downloads/manager.html ('k') | chrome/browser/resources/md_downloads/shared_style.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698