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

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

Issue 540563002: Export vendor capabilities to the CJT ticket. (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 15 matching lines...) Expand all
26 */ 26 */
27 this.eventTarget_ = eventTarget; 27 this.eventTarget_ = eventTarget;
28 28
29 /** 29 /**
30 * Contains the print ticket to print. 30 * Contains the print ticket to print.
31 * @private {!print_preview.PrintTicketStore} 31 * @private {!print_preview.PrintTicketStore}
32 */ 32 */
33 this.printTicketStore_ = printTicketStore; 33 this.printTicketStore_ = printTicketStore;
34 34
35 /** 35 /**
36 * Capability that the list item renders. 36 * Capability this component renders.
37 * @private {!Object} 37 * @private {!Object}
38 */ 38 */
39 this.capability_ = capability; 39 this.capability_ = capability;
40 40
41 /** 41 /**
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
44 * selected).
45 * @private {?string}
46 */
47 this.selectedValue_ = null;
48
49 /**
42 * Active filter query text. 50 * Active filter query text.
43 * @private {RegExp} 51 * @private {RegExp}
44 */ 52 */
45 this.query_ = null; 53 this.query_ = null;
46 };
47 54
48 /** 55 /** @private {!EventTracker} */
49 * Event types dispatched by this class. 56 this.tracker_ = new EventTracker();
50 * @enum {string}
51 */
52 AdvancedSettingsItem.EventType = {
53 CHANGED: 'print_preview.AdvancedSettingsItem.CHANGED'
54 }; 57 };
55 58
56 AdvancedSettingsItem.prototype = { 59 AdvancedSettingsItem.prototype = {
57 __proto__: print_preview.Component.prototype, 60 __proto__: print_preview.Component.prototype,
58 61
59 /** @override */ 62 /** @override */
60 createDom: function() { 63 createDom: function() {
61 this.setElementInternal(this.cloneTemplateInternal( 64 this.setElementInternal(this.cloneTemplateInternal(
62 'advanced-settings-item-template')); 65 'advanced-settings-item-template'));
63 66
64 var nameEl = this.getChildElement('.advanced-settings-item-label'); 67 var nameEl = this.getChildElement('.advanced-settings-item-label');
65 var textContent = this.capability_.display_name; 68 var textContent = this.capability_.display_name;
66 if (this.query_) 69 if (this.query_)
67 this.addTextWithHighlight_(nameEl, textContent); 70 this.addTextWithHighlight_(nameEl, textContent);
68 else 71 else
69 nameEl.textContent = textContent; 72 nameEl.textContent = textContent;
70 nameEl.title = textContent; 73 nameEl.title = textContent;
71 74
75 this.tracker_.add(
76 this.select_, 'change', this.onSelectChange_.bind(this));
77 this.tracker_.add(this.text_, 'input', this.onTextInput_.bind(this));
78
72 this.initializeValue_(); 79 this.initializeValue_();
73 }, 80 },
74 81
75 /** 82 /**
83 * ID of the corresponding vendor capability.
84 * @return {string}
85 */
86 get id() {
87 return this.capability_.id;
88 },
89
90 /**
91 * Currently selected value.
92 * @return {string}
93 */
94 get selectedValue() {
95 return this.selectedValue_ || '';
96 },
97
98 /**
76 * Whether the corresponding ticket item was changed or not. 99 * Whether the corresponding ticket item was changed or not.
77 * @return {boolean} 100 * @return {boolean}
78 */ 101 */
79 isModified: function() { 102 isModified: function() {
80 return false; 103 return !!this.selectedValue_;
81 }, 104 },
82 105
83 /** 106 /**
107 * @return {HTMLSelectElement} Select element.
108 * @private
109 */
110 get select_() {
111 return this.getChildElement(
112 '.advanced-settings-item-value-select-control');
113 },
114
115 /**
116 * @return {HTMLSelectElement} Text element.
117 * @private
118 */
119 get text_() {
120 return this.getChildElement('.advanced-settings-item-value-text-control');
121 },
122
123 /**
124 * Called when the select element value is changed.
125 * @private
126 */
127 onSelectChange_: function() {
128 this.selectedValue_ = this.select_.value;
129 this.capability_.select_cap.option.some(function(option) {
130 if (this.select_.value == option.value && option.is_default)
131 this.selectedValue_ = null;
132 return this.select_.value == option.value || option.is_default;
133 }.bind(this));
134 },
135
136 /**
137 * Called when the text element value is changed.
138 * @private
139 */
140 onTextInput_: function() {
141 this.selectedValue_ = this.text_.value || null;
142 },
143
144 /**
84 * Initializes the element's value control. 145 * Initializes the element's value control.
85 * @private 146 * @private
86 */ 147 */
87 initializeValue_: function() { 148 initializeValue_: function() {
149 this.selectedValue_ =
150 this.printTicketStore_.vendorItems.ticketItems[this.id] || null;
151
88 if (this.capability_.type == 'SELECT') 152 if (this.capability_.type == 'SELECT')
89 this.initializeSelectValue_(); 153 this.initializeSelectValue_();
90 else 154 else
91 this.initializeTextValue_(); 155 this.initializeTextValue_();
92 }, 156 },
93 157
94 /** 158 /**
95 * Initializes the select element. 159 * Initializes the select element.
96 * @private 160 * @private
97 */ 161 */
98 initializeSelectValue_: function() { 162 initializeSelectValue_: function() {
99 var selectEl = this.getChildElement(
100 '.advanced-settings-item-value-select-control');
101 setIsVisible( 163 setIsVisible(
102 this.getChildElement('.advanced-settings-item-value-select'), true); 164 this.getChildElement('.advanced-settings-item-value-select'), true);
165 var selectEl = this.select_;
103 var indexToSelect = 0; 166 var indexToSelect = 0;
104 this.capability_.select_cap.option.forEach(function(option, index) { 167 this.capability_.select_cap.option.forEach(function(option, index) {
105 var item = document.createElement('option'); 168 var item = document.createElement('option');
106 item.text = option.display_name; 169 item.text = option.display_name;
107 item.value = option.value; 170 item.value = option.value;
108 if (option.is_default) 171 if (option.is_default)
109 indexToSelect = index; 172 indexToSelect = index;
110 selectEl.add(item); 173 selectEl.add(item);
111 }); 174 });
112 // TODO: Try to select current ticket item.
113 var valueToSelect = '';
114 for (var i = 0, option; option = selectEl.options[i]; i++) { 175 for (var i = 0, option; option = selectEl.options[i]; i++) {
115 if (option.value == valueToSelect) { 176 if (option.value == this.selectedValue_) {
116 indexToSelect = i; 177 indexToSelect = i;
117 break; 178 break;
118 } 179 }
119 } 180 }
120 selectEl.selectedIndex = indexToSelect; 181 selectEl.selectedIndex = indexToSelect;
121 }, 182 },
122 183
123 /** 184 /**
124 * Initializes the text element. 185 * Initializes the text element.
125 * @private 186 * @private
126 */ 187 */
127 initializeTextValue_: function() { 188 initializeTextValue_: function() {
128 var textEl = this.getChildElement(
129 '.advanced-settings-item-value-text-control');
130 setIsVisible( 189 setIsVisible(
131 this.getChildElement('.advanced-settings-item-value-text'), true); 190 this.getChildElement('.advanced-settings-item-value-text'), true);
191 this.text_.value = this.selectedValue;
132 }, 192 },
133 193
134 /** 194 /**
135 * Adds text to parent element wrapping search query matches in highlighted 195 * Adds text to parent element wrapping search query matches in highlighted
136 * spans. 196 * spans.
137 * @param {!Element} parent Element to build the text in. 197 * @param {!Element} parent Element to build the text in.
138 * @param {string} text The text string to highlight segments in. 198 * @param {string} text The text string to highlight segments in.
139 * @private 199 * @private
140 */ 200 */
141 addTextWithHighlight_: function(parent, text) { 201 addTextWithHighlight_: function(parent, text) {
142 text.split(this.query_).forEach(function(section, i) { 202 text.split(this.query_).forEach(function(section, i) {
143 if (i % 2 == 0) { 203 if (i % 2 == 0) {
144 parent.appendChild(document.createTextNode(section)); 204 parent.appendChild(document.createTextNode(section));
145 } else { 205 } else {
146 var span = document.createElement('span'); 206 var span = document.createElement('span');
147 span.className = 'advanced-settings-item-query-highlight'; 207 span.className = 'advanced-settings-item-query-highlight';
148 span.textContent = section; 208 span.textContent = section;
149 parent.appendChild(span); 209 parent.appendChild(span);
150 } 210 }
151 }); 211 });
152 } 212 }
153 }; 213 };
154 214
155 // Export 215 // Export
156 return { 216 return {
157 AdvancedSettingsItem: AdvancedSettingsItem 217 AdvancedSettingsItem: AdvancedSettingsItem
158 }; 218 };
159 }); 219 });
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