Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / resources / md_downloads / toolbar.js
blob3cab91fb7047d8e9309973e6c8bb4d904347d8a7
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;
13     },
15     attached: function() {
16       /** @private {!SearchFieldDelegate} */
17       this.searchFieldDelegate_ = new ToolbarSearchFieldDelegate(this);
18       this.$['search-input'].setDelegate(this.searchFieldDelegate_);
19     },
21     properties: {
22       downloadsShowing: {
23         reflectToAttribute: true,
24         type: Boolean,
25         value: false,
26         observer: 'onDownloadsShowingChange_',
27       },
28     },
30     /** @return {boolean} Whether removal can be undone. */
31     canUndo: function() {
32       return this.$['search-input'] != this.shadowRoot.activeElement;
33     },
35     /** @return {boolean} Whether "Clear all" should be allowed. */
36     canClearAll: function() {
37       return !this.$['search-input'].getValue() && this.downloadsShowing;
38     },
40     /** @private */
41     onClearAllClick_: function() {
42       assert(this.canClearAll());
43       this.actionService_.clearAll();
44     },
46     /** @private */
47     onDownloadsShowingChange_: function() {
48       this.updateClearAll_();
49     },
51     /** @param {string} searchTerm */
52     onSearchTermSearch: function(searchTerm) {
53       this.actionService_.search(searchTerm);
54       this.updateClearAll_();
55     },
57     /** @private */
58     onOpenDownloadsFolderClick_: function() {
59       this.actionService_.openDownloadsFolder();
60     },
62     /** @private */
63     updateClearAll_: function() {
64       this.$$('#actions .clear-all').hidden = !this.canClearAll();
65       this.$$('paper-menu .clear-all').hidden = !this.canClearAll();
66     },
67   });
69   /**
70    * @constructor
71    * @implements {SearchFieldDelegate}
72    */
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;
78   }
80   ToolbarSearchFieldDelegate.prototype = {
81     /** @override */
82     onSearchTermSearch: function(searchTerm) {
83       this.toolbar_.onSearchTermSearch(searchTerm);
84     }
85   };
87   return {Toolbar: Toolbar};
88 });
90 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files
91 /** @suppress {checkTypes} */
92 (function() {
93 Polymer.IronDropdownScrollManager.pushScrollLock = function() {};
94 })();