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 Polymer({ | 5 Polymer({ |
6 is: 'history-toolbar', | 6 is: 'history-toolbar', |
7 properties: { | 7 properties: { |
8 // Number of history items currently selected. | 8 // Number of history items currently selected. |
9 // TODO(calamity): bind this to | 9 // TODO(calamity): bind this to |
10 // listContainer.selectedItem.selectedPaths.length. | 10 // listContainer.selectedItem.selectedPaths.length. |
11 count: { | 11 count: { |
12 type: Number, | 12 type: Number, |
13 value: 0, | 13 value: 0, |
14 observer: 'changeToolbarView_' | 14 observer: 'changeToolbarView_' |
15 }, | 15 }, |
16 | 16 |
17 // True if 1 or more history items are selected. When this value changes | 17 // True if 1 or more history items are selected. When this value changes |
18 // the background colour changes. | 18 // the background colour changes. |
19 itemsSelected_: { | 19 itemsSelected_: { |
20 type: Boolean, | 20 type: Boolean, |
21 value: false, | 21 value: false, |
22 reflectToAttribute: true | 22 reflectToAttribute: true |
23 }, | 23 }, |
24 | 24 |
25 // The most recent term entered in the search field. Updated incrementally | 25 // The most recent term entered in the search field. Updated incrementally |
26 // as the user types. | 26 // as the user types. |
27 searchTerm: { | 27 searchTerm: { |
28 type: String, | 28 type: String, |
29 observer: 'searchTermChanged_', | |
29 notify: true, | 30 notify: true, |
30 }, | 31 }, |
31 | 32 |
32 // True if the backend is processing and a spinner should be shown in the | 33 // True if the backend is processing and a spinner should be shown in the |
33 // toolbar. | 34 // toolbar. |
34 spinnerActive: { | 35 spinnerActive: { |
35 type: Boolean, | 36 type: Boolean, |
36 value: false | 37 value: false |
37 }, | 38 }, |
38 | 39 |
(...skipping 19 matching lines...) Expand all Loading... | |
58 notify: true | 59 notify: true |
59 }, | 60 }, |
60 | 61 |
61 // The start time of the query range. | 62 // The start time of the query range. |
62 queryStartTime: String, | 63 queryStartTime: String, |
63 | 64 |
64 // The end time of the query range. | 65 // The end time of the query range. |
65 queryEndTime: String, | 66 queryEndTime: String, |
66 }, | 67 }, |
67 | 68 |
69 /** @return {CrToolbarSearchFieldElement} */ | |
70 get searchBar() { | |
calamity
2016/09/22 05:12:26
Might be a good time to rename this 'searchField'.
tsergeant
2016/09/23 00:37:44
Done.
| |
71 return /** @type {CrToolbarElement} */ (this.$['main-toolbar']) | |
72 .getSearchField(); | |
73 }, | |
74 | |
75 showSearchField: function() { | |
76 this.searchBar.showAndFocus(); | |
77 }, | |
78 | |
68 /** | 79 /** |
69 * Changes the toolbar background color depending on whether any history items | 80 * Changes the toolbar background color depending on whether any history items |
70 * are currently selected. | 81 * are currently selected. |
71 * @private | 82 * @private |
72 */ | 83 */ |
73 changeToolbarView_: function() { | 84 changeToolbarView_: function() { |
74 this.itemsSelected_ = this.count > 0; | 85 this.itemsSelected_ = this.count > 0; |
75 }, | 86 }, |
76 | 87 |
77 /** | 88 /** |
78 * When changing the search term externally, update the search field to | 89 * When changing the search term externally, update the search field to |
79 * reflect the new search term. | 90 * reflect the new search term. |
80 * @param {string} search | |
81 */ | 91 */ |
82 setSearchTerm: function(search) { | 92 searchTermChanged_: function() { |
83 if (this.searchTerm == search) | 93 if (this.searchBar.getValue() != this.searchTerm) { |
84 return; | 94 this.searchBar.showAndFocus(); |
85 | 95 this.searchBar.setValue(this.searchTerm); |
86 this.searchTerm = search; | 96 } |
87 var searchField = /** @type {!CrToolbarElement} */(this.$['main-toolbar']) | |
88 .getSearchField(); | |
89 searchField.showAndFocus(); | |
90 searchField.setValue(search); | |
91 }, | 97 }, |
92 | 98 |
93 /** | 99 /** |
94 * @param {!CustomEvent} event | 100 * @param {!CustomEvent} event |
95 * @private | 101 * @private |
96 */ | 102 */ |
97 onSearchChanged_: function(event) { | 103 onSearchChanged_: function(event) { |
98 this.searchTerm = /** @type {string} */ (event.detail); | 104 this.searchTerm = /** @type {string} */ (event.detail); |
99 }, | 105 }, |
100 | 106 |
101 /** @private */ | 107 /** @private */ |
102 onInfoButtonTap_: function() { | 108 onInfoButtonTap_: function() { |
103 var dropdown = this.$.syncNotice.get(); | 109 var dropdown = this.$.syncNotice.get(); |
104 dropdown.positionTarget = this.$$('#info-button-icon'); | 110 dropdown.positionTarget = this.$$('#info-button-icon'); |
105 // It is possible for this listener to trigger while the dialog is | 111 // It is possible for this listener to trigger while the dialog is |
106 // closing. Ensure the dialog is fully closed before reopening it. | 112 // closing. Ensure the dialog is fully closed before reopening it. |
107 if (dropdown.style.display == 'none') | 113 if (dropdown.style.display == 'none') |
108 dropdown.open(); | 114 dropdown.open(); |
109 }, | 115 }, |
110 | 116 |
111 onClearSelectionTap_: function() { | 117 onClearSelectionTap_: function() { |
112 this.fire('unselect-all'); | 118 this.fire('unselect-all'); |
113 }, | 119 }, |
114 | 120 |
115 onDeleteTap_: function() { | 121 onDeleteTap_: function() { |
116 this.fire('delete-selected'); | 122 this.fire('delete-selected'); |
117 }, | 123 }, |
118 | 124 |
119 get searchBar() { | |
120 return this.$['main-toolbar'].getSearchField(); | |
121 }, | |
122 | |
123 showSearchField: function() { | |
124 /** @type {!CrToolbarElement} */(this.$['main-toolbar']) | |
125 .getSearchField() | |
126 .showAndFocus(); | |
127 }, | |
128 | |
129 /** | 125 /** |
130 * If the user is a supervised user the delete button is not shown. | 126 * If the user is a supervised user the delete button is not shown. |
131 * @private | 127 * @private |
132 */ | 128 */ |
133 deletingAllowed_: function() { | 129 deletingAllowed_: function() { |
134 return loadTimeData.getBoolean('allowDeletingHistory'); | 130 return loadTimeData.getBoolean('allowDeletingHistory'); |
135 }, | 131 }, |
136 | 132 |
137 numberOfItemsSelected_: function(count) { | 133 numberOfItemsSelected_: function(count) { |
138 return count > 0 ? loadTimeData.getStringF('itemsSelected', count) : ''; | 134 return count > 0 ? loadTimeData.getStringF('itemsSelected', count) : ''; |
139 }, | 135 }, |
140 | 136 |
141 getHistoryInterval_: function(queryStartTime, queryEndTime) { | 137 getHistoryInterval_: function(queryStartTime, queryEndTime) { |
142 // TODO(calamity): Fix the format of these dates. | 138 // TODO(calamity): Fix the format of these dates. |
143 return loadTimeData.getStringF( | 139 return loadTimeData.getStringF( |
144 'historyInterval', queryStartTime, queryEndTime); | 140 'historyInterval', queryStartTime, queryEndTime); |
145 }, | 141 }, |
146 | 142 |
147 /** @private */ | 143 /** @private */ |
148 hasDrawerChanged_: function() { | 144 hasDrawerChanged_: function() { |
149 this.updateStyles(); | 145 this.updateStyles(); |
150 }, | 146 }, |
151 }); | 147 }); |
OLD | NEW |