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

Side by Side Diff: chrome/browser/resources/print_preview/search/destination_list_item.js

Issue 2760753002: [CUPS] Implement the local CUPS printer setup waiting UI. (Closed)
Patch Set: Address skau@'s comment. Rebase Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 * @private 46 * @private
47 */ 47 */
48 this.fedexTos_ = null; 48 this.fedexTos_ = null;
49 }; 49 };
50 50
51 /** 51 /**
52 * Event types dispatched by the destination list item. 52 * Event types dispatched by the destination list item.
53 * @enum {string} 53 * @enum {string}
54 */ 54 */
55 DestinationListItem.EventType = { 55 DestinationListItem.EventType = {
56 // Dispatched to check the printer needs to be configured before activation.
57 CONFIGURE_REQUEST: 'print_preview.DestinationListItem.CONFIGURE_REQUEST',
56 // Dispatched when the list item is activated. 58 // Dispatched when the list item is activated.
57 SELECT: 'print_preview.DestinationListItem.SELECT', 59 SELECT: 'print_preview.DestinationListItem.SELECT',
58 REGISTER_PROMO_CLICKED: 60 REGISTER_PROMO_CLICKED:
59 'print_preview.DestinationListItem.REGISTER_PROMO_CLICKED' 61 'print_preview.DestinationListItem.REGISTER_PROMO_CLICKED'
60 }; 62 };
61 63
62 DestinationListItem.prototype = { 64 DestinationListItem.prototype = {
63 __proto__: print_preview.Component.prototype, 65 __proto__: print_preview.Component.prototype,
64 66
65 /** @override */ 67 /** @override */
(...skipping 26 matching lines...) Expand all
92 * to render. 94 * to render.
93 * @param {RegExp} query Active filter query. 95 * @param {RegExp} query Active filter query.
94 */ 96 */
95 update: function(destination, query) { 97 update: function(destination, query) {
96 this.destination_ = destination; 98 this.destination_ = destination;
97 this.query_ = query; 99 this.query_ = query;
98 this.updateUi_(); 100 this.updateUi_();
99 }, 101 },
100 102
101 /** 103 /**
104 * Called if the printer configuration request is accepted. Show the waiting
105 * message to the user as the configuration might take longer than expected.
106 */
107 onConfigureRequestAccepted: function() {
108 // It must be a Chrome OS CUPS printer which hasn't been set up before.
109 assert(
110 this.destination_.origin == print_preview.Destination.Origin.CROS &&
111 !this.destination_.capabilities);
112 setIsVisible(
113 this.getChildElement('.configuring-in-progress-text'), true);
114 },
115
116 /**
117 * Called if the printer configuration request is rejected. The request is
118 * rejected if another printer is setting up in process or the current
119 * printer doesn't need to be setup.
120 * @param {bool} shouldIgnore If true, which indicates another printer is
121 * setting up in process, the printer should not be activated.
122 */
123 onConfigureRequestRejected: function(shouldIgnore) {
124 if (!shouldIgnore)
125 this.onDestinationActivated_();
126 },
127
128 /**
129 * Called when the printer configuration request is resolved successful or
130 * failed.
131 * @param response {!print_preview.PrinterSetupResponse}
132 */
133 onConfigureResolved: function(response) {
134 assert(response.printerId == this.destination_.id);
135 if (response.success) {
136 setIsVisible(
137 this.getChildElement('.configuring-in-progress-text'), false);
138 this.destination_.capabilities = response.capabilities;
139 this.onDestinationActivated_();
140 } else {
141 setIsVisible(
142 this.getChildElement('.configuring-in-progress-text'), false);
143 setIsVisible(
144 this.getChildElement('.configuring-failed-text'), true);
145 }
146 },
147
148 /**
102 * Initializes the element with destination's info. 149 * Initializes the element with destination's info.
103 * @private 150 * @private
104 */ 151 */
105 updateUi_: function() { 152 updateUi_: function() {
106 var iconImg = this.getChildElement('.destination-list-item-icon'); 153 var iconImg = this.getChildElement('.destination-list-item-icon');
107 iconImg.src = this.destination_.iconUrl; 154 iconImg.src = this.destination_.iconUrl;
108 155
109 var nameEl = this.getChildElement('.destination-list-item-name'); 156 var nameEl = this.getChildElement('.destination-list-item-name');
110 var textContent = this.destination_.displayName; 157 var textContent = this.destination_.displayName;
111 if (this.query_) { 158 if (this.query_) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 this.getElement().classList.toggle('stale', this.destination_.isOffline); 211 this.getElement().classList.toggle('stale', this.destination_.isOffline);
165 var offlineStatusEl = this.getChildElement('.offline-status'); 212 var offlineStatusEl = this.getChildElement('.offline-status');
166 offlineStatusEl.textContent = this.destination_.offlineStatusText; 213 offlineStatusEl.textContent = this.destination_.offlineStatusText;
167 setIsVisible(offlineStatusEl, this.destination_.isOffline); 214 setIsVisible(offlineStatusEl, this.destination_.isOffline);
168 215
169 // Initialize registration promo element for Privet unregistered printers. 216 // Initialize registration promo element for Privet unregistered printers.
170 setIsVisible( 217 setIsVisible(
171 this.getChildElement('.register-promo'), 218 this.getChildElement('.register-promo'),
172 this.destination_.connectionStatus == 219 this.destination_.connectionStatus ==
173 print_preview.Destination.ConnectionStatus.UNREGISTERED); 220 print_preview.Destination.ConnectionStatus.UNREGISTERED);
221
222 // Reset the configuring messages for CUPS printers.
223 setIsVisible(
224 this.getChildElement('.configuring-in-progress-text'), false);
225 setIsVisible(
226 this.getChildElement('.configuring-failed-text'), false);
174 }, 227 },
175 228
176 /** 229 /**
177 * Adds text to parent element wrapping search query matches in highlighted 230 * Adds text to parent element wrapping search query matches in highlighted
178 * spans. 231 * spans.
179 * @param {!Element} parent Element to build the text in. 232 * @param {!Element} parent Element to build the text in.
180 * @param {string} text The text string to highlight segments in. 233 * @param {string} text The text string to highlight segments in.
181 * @private 234 * @private
182 */ 235 */
183 addTextWithHighlight_: function(parent, text) { 236 addTextWithHighlight_: function(parent, text) {
184 var sections = text.split(this.query_); 237 var sections = text.split(this.query_);
185 for (var i = 0; i < sections.length; ++i) { 238 for (var i = 0; i < sections.length; ++i) {
186 if (i % 2 == 0) { 239 if (i % 2 == 0) {
187 parent.appendChild(document.createTextNode(sections[i])); 240 parent.appendChild(document.createTextNode(sections[i]));
188 } else { 241 } else {
189 var span = document.createElement('span'); 242 var span = document.createElement('span');
190 span.className = 'destination-list-item-query-highlight'; 243 span.className = 'destination-list-item-query-highlight';
191 span.textContent = sections[i]; 244 span.textContent = sections[i];
192 parent.appendChild(span); 245 parent.appendChild(span);
193 } 246 }
194 } 247 }
195 }, 248 },
196 249
197 /** 250 /**
198 * Called when the destination item is activated. Dispatches a SELECT event 251 * Called when the destination item is activated. Check if the printer needs
199 * on the given event target. 252 * to be set up first before activation.
200 * @private 253 * @private
201 */ 254 */
202 onActivate_: function() { 255 onActivate_: function() {
256 if (!cr.isChromeOS) {
257 onDestinationActivated_();
258 return;
259 }
260
261 // Check if the printer needs configuration before using. The user is only
262 // allowed to set up one printer at one time.
263 var configureEvt =
264 new Event(DestinationListItem.EventType.CONFIGURE_REQUEST);
265 configureEvt.destination = this.destination_;
266 this.eventTarget_.dispatchEvent(configureEvt);
267 },
268
269 /**
270 * Called when the destination has been resolved successfully and needs to
271 * be activated. Dispatches a SELECT event on the given event target.
272 * @private
273 */
274 onDestinationActivated_: function() {
203 if (this.destination_.id == 275 if (this.destination_.id ==
204 print_preview.Destination.GooglePromotedId.FEDEX && 276 print_preview.Destination.GooglePromotedId.FEDEX &&
205 !this.destination_.isTosAccepted) { 277 !this.destination_.isTosAccepted) {
206 if (!this.fedexTos_) { 278 if (!this.fedexTos_) {
207 this.fedexTos_ = new print_preview.FedexTos(); 279 this.fedexTos_ = new print_preview.FedexTos();
208 this.fedexTos_.render(this.getElement()); 280 this.fedexTos_.render(this.getElement());
209 this.tracker.add( 281 this.tracker.add(
210 this.fedexTos_, 282 this.fedexTos_,
211 print_preview.FedexTos.EventType.AGREE, 283 print_preview.FedexTos.EventType.AGREE,
212 this.onTosAgree_.bind(this)); 284 this.onTosAgree_.bind(this));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 return; 359 return;
288 this.onExtensionIconClicked_(event); 360 this.onExtensionIconClicked_(event);
289 } 361 }
290 }; 362 };
291 363
292 // Export 364 // Export
293 return { 365 return {
294 DestinationListItem: DestinationListItem 366 DestinationListItem: DestinationListItem
295 }; 367 };
296 }); 368 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698