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 Toolbar = Polymer({ | 6 var Toolbar = Polymer({ |
7 is: 'downloads-toolbar', | 7 is: 'downloads-toolbar', |
8 | 8 |
9 /** @param {!downloads.ActionService} actionService */ | 9 /** @param {!downloads.ActionService} actionService */ |
10 setActionService: function(actionService) { | 10 setActionService: function(actionService) { |
11 /** @private {!downloads.ActionService} */ | 11 /** @private {!downloads.ActionService} */ |
12 this.actionService_ = actionService; | 12 this.actionService_ = actionService; |
13 }, | 13 }, |
14 | 14 |
15 attached: function() { | |
16 /** @private {!SearchField.Delegate} */ | |
17 this.searchFieldDelegate_ = new ToolbarSearchFieldDelegate(this); | |
18 this.$['search-input'].setDelegate(this.searchFieldDelegate_); | |
19 }, | |
20 | |
15 properties: { | 21 properties: { |
16 downloadsShowing: { | 22 downloadsShowing: { |
17 reflectToAttribute: true, | 23 reflectToAttribute: true, |
18 type: Boolean, | 24 type: Boolean, |
19 value: false, | 25 value: false, |
20 observer: 'onDownloadsShowingChange_', | 26 observer: 'onDownloadsShowingChange_', |
21 }, | 27 }, |
22 | |
23 showingSearch_: { | |
24 type: Boolean, | |
25 value: false, | |
26 }, | |
27 }, | 28 }, |
28 | 29 |
29 /** @return {boolean} Whether removal can be undone. */ | 30 /** @return {boolean} Whether removal can be undone. */ |
30 canUndo: function() { | 31 canUndo: function() { |
31 return this.$['search-input'] != this.shadowRoot.activeElement; | 32 return this.$['search-input'] != this.shadowRoot.activeElement; |
32 }, | 33 }, |
33 | 34 |
34 /** @return {boolean} Whether "Clear all" should be allowed. */ | 35 /** @return {boolean} Whether "Clear all" should be allowed. */ |
35 canClearAll: function() { | 36 canClearAll: function() { |
36 return !this.$['search-input'].value && this.downloadsShowing; | 37 return !this.$['search-input'].getValue() && this.downloadsShowing; |
37 }, | 38 }, |
38 | 39 |
39 /** @private */ | 40 /** @private */ |
40 onClearAllClick_: function() { | 41 onClearAllClick_: function() { |
41 assert(this.canClearAll()); | 42 assert(this.canClearAll()); |
42 this.actionService_.clearAll(); | 43 this.actionService_.clearAll(); |
43 }, | 44 }, |
44 | 45 |
45 /** @private */ | 46 /** @private */ |
46 onDownloadsShowingChange_: function() { | 47 onDownloadsShowingChange_: function() { |
47 this.updateClearAll_(); | 48 this.updateClearAll_(); |
48 }, | 49 }, |
49 | 50 |
50 /** @private */ | 51 /** |
51 onSearchTermSearch_: function() { | 52 * @param {string} value |
Dan Beam
2015/09/14 23:16:06
nit: /** @param {string} ... */ if it fits in one
Dan Beam
2015/09/14 23:16:06
nit: value -> searchText
Devlin
2015/09/15 17:24:06
Done.
Devlin
2015/09/15 17:24:06
Done.
| |
52 this.actionService_.search(this.$['search-input'].value); | 53 */ |
54 onSearchTermSearch: function(value) { | |
55 this.actionService_.search(value); | |
53 this.updateClearAll_(); | 56 this.updateClearAll_(); |
54 }, | 57 }, |
55 | 58 |
56 /** @private */ | 59 /** @private */ |
57 onSearchTermKeydown_: function(e) { | |
58 assert(this.showingSearch_); | |
59 if (e.keyIdentifier == 'U+001B') // Escape. | |
60 this.toggleShowingSearch_(); | |
61 }, | |
62 | |
63 /** @private */ | |
64 onOpenDownloadsFolderClick_: function() { | 60 onOpenDownloadsFolderClick_: function() { |
65 this.actionService_.openDownloadsFolder(); | 61 this.actionService_.openDownloadsFolder(); |
66 }, | 62 }, |
67 | 63 |
68 /** @private */ | 64 /** @private */ |
69 toggleShowingSearch_: function() { | |
70 this.showingSearch_ = !this.showingSearch_; | |
71 this.$['search-button'].disabled = this.showingSearch_; | |
72 | |
73 if (this.showingSearch_) { | |
74 this.$['search-input'].focus(); | |
75 } else { | |
76 this.$['search-input'].value = ''; | |
77 this.onSearchTermSearch_(); | |
78 } | |
79 }, | |
80 | |
81 /** @private */ | |
82 updateClearAll_: function() { | 65 updateClearAll_: function() { |
83 this.$$('#actions .clear-all').hidden = !this.canClearAll(); | 66 this.$$('#actions .clear-all').hidden = !this.canClearAll(); |
84 this.$$('paper-menu .clear-all').hidden = !this.canClearAll(); | 67 this.$$('paper-menu .clear-all').hidden = !this.canClearAll(); |
85 }, | 68 }, |
86 }); | 69 }); |
87 | 70 |
71 /** | |
72 * @constructor | |
73 * @implements {SearchField.Delegate} | |
74 */ | |
75 function ToolbarSearchFieldDelegate(toolbar) { | |
76 this.toolbar_ = toolbar; | |
77 } | |
78 | |
79 ToolbarSearchFieldDelegate.prototype = { | |
80 /** @override */ | |
81 onSearchTermSearch: function(value) { | |
Dan Beam
2015/09/14 23:16:06
can downloads.Toolbar just implement SearchField.D
Dan Beam
2015/09/14 23:52:54
safe to ignore if this isn't currently feasible
| |
82 this.toolbar_.onSearchTermSearch(value); | |
83 } | |
84 }; | |
85 | |
88 return {Toolbar: Toolbar}; | 86 return {Toolbar: Toolbar}; |
89 }); | 87 }); |
90 | 88 |
91 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files | 89 // TODO(dbeam): https://github.com/PolymerElements/iron-dropdown/pull/16/files |
92 /** @suppress {checkTypes} */ | 90 /** @suppress {checkTypes} */ |
93 (function() { | 91 (function() { |
94 Polymer.IronDropdownScrollManager.pushScrollLock = function() {}; | 92 Polymer.IronDropdownScrollManager.pushScrollLock = function() {}; |
95 })(); | 93 })(); |
OLD | NEW |