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.
5 cr.define('downloads', function() {
6 var Toolbar = Polymer({
7 is: 'downloads-toolbar',
9 /** @param {!downloads.ActionService} actionService */
10 setActionService: function(actionService) {
11 /** @private {!downloads.ActionService} */
12 this.actionService_ = actionService;
15 attached: function() {
16 /** @private {!SearchFieldDelegate} */
17 this.searchFieldDelegate_ = new ToolbarSearchFieldDelegate(this);
18 this.$['search-input'].setDelegate(this.searchFieldDelegate_);
23 reflectToAttribute: true,
26 observer: 'onDownloadsShowingChange_',
30 /** @return {boolean} Whether removal can be undone. */
32 return this.$['search-input'] != this.shadowRoot.activeElement;
35 /** @return {boolean} Whether "Clear all" should be allowed. */
36 canClearAll: function() {
37 return !this.$['search-input'].getValue() && this.downloadsShowing;
41 onClearAllClick_: function() {
42 assert(this.canClearAll());
43 this.actionService_.clearAll();
47 onDownloadsShowingChange_: function() {
48 this.updateClearAll_();
51 /** @param {string} searchTerm */
52 onSearchTermSearch: function(searchTerm) {
53 this.actionService_.search(searchTerm);
54 this.updateClearAll_();
58 onOpenDownloadsFolderClick_: function() {
59 this.actionService_.openDownloadsFolder();
63 updateClearAll_: function() {
64 this.$$('#actions .clear-all').hidden = !this.canClearAll();
65 this.$$('paper-menu .clear-all').hidden = !this.canClearAll();
71 * @implements {SearchFieldDelegate}
73 // TODO(devlin): This is a bit excessive, and it would be better to just have
74 // Toolbar implement SearchFieldDelegate. But for now, we don't know how to
75 // make that happen with closure compiler.
76 function ToolbarSearchFieldDelegate(toolbar) {
77 this.toolbar_ = toolbar;
80 ToolbarSearchFieldDelegate.prototype = {
82 onSearchTermSearch: function(searchTerm) {
83 this.toolbar_.onSearchTermSearch(searchTerm);
87 return {Toolbar: Toolbar};
90 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files
91 /** @suppress {checkTypes} */
93 Polymer.IronDropdownScrollManager.pushScrollLock = function() {};