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

Side by Side Diff: chrome/browser/resources/print_preview/settings/advanced_settings/advanced_settings_item.js

Issue 540183002: Add search to Print Preview advanced options and enable them in the UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/print_preview/settings/advanced_settings/advanced_settings.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Component that renders a destination item in a destination list. 9 * Component that renders a destination item in a destination list.
10 * @param {!cr.EventTarget} eventTarget Event target to dispatch selection 10 * @param {!cr.EventTarget} eventTarget Event target to dispatch selection
(...skipping 29 matching lines...) Expand all
40 40
41 /** 41 /**
42 * Value selected by user. {@code null}, if user has not changed the default 42 * Value selected by user. {@code null}, if user has not changed the default
43 * value yet (still, the value can be the default one, if it is what user 43 * value yet (still, the value can be the default one, if it is what user
44 * selected). 44 * selected).
45 * @private {?string} 45 * @private {?string}
46 */ 46 */
47 this.selectedValue_ = null; 47 this.selectedValue_ = null;
48 48
49 /** 49 /**
50 * Active filter query text. 50 * Active filter query.
51 * @private {RegExp} 51 * @private {RegExp}
52 */ 52 */
53 this.query_ = null; 53 this.query_ = null;
54 54
55 /**
56 * Search hint for the control.
57 * @private {print_preview.SearchBubble}
58 */
59 this.searchBubble_ = null;
60
55 /** @private {!EventTracker} */ 61 /** @private {!EventTracker} */
56 this.tracker_ = new EventTracker(); 62 this.tracker_ = new EventTracker();
57 }; 63 };
58 64
59 AdvancedSettingsItem.prototype = { 65 AdvancedSettingsItem.prototype = {
60 __proto__: print_preview.Component.prototype, 66 __proto__: print_preview.Component.prototype,
61 67
62 /** @override */ 68 /** @override */
63 createDom: function() { 69 createDom: function() {
64 this.setElementInternal(this.cloneTemplateInternal( 70 this.setElementInternal(this.cloneTemplateInternal(
65 'advanced-settings-item-template')); 71 'advanced-settings-item-template'));
66 72
67 var nameEl = this.getChildElement('.advanced-settings-item-label');
68 var textContent = this.capability_.display_name;
69 if (this.query_)
70 this.addTextWithHighlight_(nameEl, textContent);
71 else
72 nameEl.textContent = textContent;
73 nameEl.title = textContent;
74
75 this.tracker_.add( 73 this.tracker_.add(
76 this.select_, 'change', this.onSelectChange_.bind(this)); 74 this.select_, 'change', this.onSelectChange_.bind(this));
77 this.tracker_.add(this.text_, 'input', this.onTextInput_.bind(this)); 75 this.tracker_.add(this.text_, 'input', this.onTextInput_.bind(this));
78 76
79 this.initializeValue_(); 77 this.initializeValue_();
78
79 this.renderCapability_();
80 }, 80 },
81 81
82 /** 82 /**
83 * ID of the corresponding vendor capability. 83 * ID of the corresponding vendor capability.
84 * @return {string} 84 * @return {string}
85 */ 85 */
86 get id() { 86 get id() {
87 return this.capability_.id; 87 return this.capability_.id;
88 }, 88 },
89 89
90 /** 90 /**
91 * Currently selected value. 91 * Currently selected value.
92 * @return {string} 92 * @return {string}
93 */ 93 */
94 get selectedValue() { 94 get selectedValue() {
95 return this.selectedValue_ || ''; 95 return this.selectedValue_ || '';
96 }, 96 },
97 97
98 /** 98 /**
99 * Whether the corresponding ticket item was changed or not. 99 * Whether the corresponding ticket item was changed or not.
100 * @return {boolean} 100 * @return {boolean}
101 */ 101 */
102 isModified: function() { 102 isModified: function() {
103 return !!this.selectedValue_; 103 return !!this.selectedValue_;
104 }, 104 },
105 105
106 /** @param {RegExp} query Query to update the filter with. */
107 updateSearchQuery: function(query) {
108 this.query_ = query;
109 this.renderCapability_();
110 },
111
106 /** 112 /**
107 * @return {HTMLSelectElement} Select element. 113 * @return {HTMLSelectElement} Select element.
108 * @private 114 * @private
109 */ 115 */
110 get select_() { 116 get select_() {
111 return this.getChildElement( 117 return this.getChildElement(
112 '.advanced-settings-item-value-select-control'); 118 '.advanced-settings-item-value-select-control');
113 }, 119 },
114 120
115 /** 121 /**
(...skipping 19 matching lines...) Expand all
135 141
136 /** 142 /**
137 * Called when the text element value is changed. 143 * Called when the text element value is changed.
138 * @private 144 * @private
139 */ 145 */
140 onTextInput_: function() { 146 onTextInput_: function() {
141 this.selectedValue_ = this.text_.value || null; 147 this.selectedValue_ = this.text_.value || null;
142 }, 148 },
143 149
144 /** 150 /**
151 * Renders capability properties according to the current state.
152 * @private
153 */
154 renderCapability_: function() {
155 var textContent = this.capability_.display_name;
156 var nameMatches = this.query_ ? !!textContent.match(this.query_) : true;
157 var optionMatches = null;
158 if (false && this.query_) {
159 if (this.capability_.type == 'SELECT') {
160 this.capability_.select_cap.option.some(function(option) {
161 optionMatches = (option.display_name || '').match(this.query_);
162 return !!optionMatches;
163 }.bind(this));
164 } else {
165 optionMatches = (this.text_.value || '').match(this.query_);
166 }
167 }
168 var matches = nameMatches || optionMatches;
169
170 if ((!matches || !optionMatches) && this.searchBubble_) {
171 this.searchBubble_.dispose();
172 this.searchBubble_ = null;
173 }
174
175 setIsVisible(this.getElement(), matches);
176 if (!matches)
177 return;
178
179 var nameEl = this.getChildElement('.advanced-settings-item-label');
180 if (this.query_) {
181 nameEl.textContent = '';
182 this.addTextWithHighlight_(nameEl, textContent);
183 } else {
184 nameEl.textContent = textContent;
185 }
186 nameEl.title = textContent;
187
188 if (optionMatches) {
189 window.console.log(optionMatches[0]);
190 var element =
191 this.capability_.type == 'SELECT' ? this.select_ : this.text_;
192 if (!this.searchBubble_) {
193 this.searchBubble_ = new print_preview.SearchBubble(optionMatches[0]);
194 this.searchBubble_.attachTo(element);
195 } else {
196 this.searchBubble_.content = optionMatches[0];
197 }
198 }
199 },
200
201 /**
145 * Initializes the element's value control. 202 * Initializes the element's value control.
146 * @private 203 * @private
147 */ 204 */
148 initializeValue_: function() { 205 initializeValue_: function() {
149 this.selectedValue_ = 206 this.selectedValue_ =
150 this.printTicketStore_.vendorItems.ticketItems[this.id] || null; 207 this.printTicketStore_.vendorItems.ticketItems[this.id] || null;
151 208
152 if (this.capability_.type == 'SELECT') 209 if (this.capability_.type == 'SELECT')
153 this.initializeSelectValue_(); 210 this.initializeSelectValue_();
154 else 211 else
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 267 }
211 }); 268 });
212 } 269 }
213 }; 270 };
214 271
215 // Export 272 // Export
216 return { 273 return {
217 AdvancedSettingsItem: AdvancedSettingsItem 274 AdvancedSettingsItem: AdvancedSettingsItem
218 }; 275 };
219 }); 276 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/print_preview/settings/advanced_settings/advanced_settings.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698