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

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 dpapad@'s comments. Fix failed test. 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 this.updateConfiguringMessage_(true);
113 },
114
115 /**
116 * Called if the printer configuration request is rejected. The request is
117 * rejected if another printer is setting up in process or the current
118 * printer doesn't need to be setup.
119 * @param {boolean} otherPrinterSetupInProgress
120 */
121 onConfigureRequestRejected: function(otherPrinterSetupInProgress) {
122 // If another printer setup is in progress, the printer should not be
123 // activated.
124 if (!otherPrinterSetupInProgress)
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 this.updateConfiguringMessage_(false);
137 this.destination_.capabilities = response.capabilities;
138 this.onDestinationActivated_();
139 } else {
140 this.updateConfiguringMessage_(false);
141 setIsVisible(
142 this.getChildElement('.configuring-failed-text'), true);
143 }
144 },
145
146 /**
102 * Initializes the element with destination's info. 147 * Initializes the element with destination's info.
103 * @private 148 * @private
104 */ 149 */
105 updateUi_: function() { 150 updateUi_: function() {
106 var iconImg = this.getChildElement('.destination-list-item-icon'); 151 var iconImg = this.getChildElement('.destination-list-item-icon');
107 iconImg.src = this.destination_.iconUrl; 152 iconImg.src = this.destination_.iconUrl;
108 153
109 var nameEl = this.getChildElement('.destination-list-item-name'); 154 var nameEl = this.getChildElement('.destination-list-item-name');
110 var textContent = this.destination_.displayName; 155 var textContent = this.destination_.displayName;
111 if (this.query_) { 156 if (this.query_) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 this.getElement().classList.toggle('stale', this.destination_.isOffline); 209 this.getElement().classList.toggle('stale', this.destination_.isOffline);
165 var offlineStatusEl = this.getChildElement('.offline-status'); 210 var offlineStatusEl = this.getChildElement('.offline-status');
166 offlineStatusEl.textContent = this.destination_.offlineStatusText; 211 offlineStatusEl.textContent = this.destination_.offlineStatusText;
167 setIsVisible(offlineStatusEl, this.destination_.isOffline); 212 setIsVisible(offlineStatusEl, this.destination_.isOffline);
168 213
169 // Initialize registration promo element for Privet unregistered printers. 214 // Initialize registration promo element for Privet unregistered printers.
170 setIsVisible( 215 setIsVisible(
171 this.getChildElement('.register-promo'), 216 this.getChildElement('.register-promo'),
172 this.destination_.connectionStatus == 217 this.destination_.connectionStatus ==
173 print_preview.Destination.ConnectionStatus.UNREGISTERED); 218 print_preview.Destination.ConnectionStatus.UNREGISTERED);
219
220 if (cr.isChromeOS) {
221 // Reset the configuring messages for CUPS printers.
222 this.updateConfiguringMessage_(false);
223 setIsVisible(
224 this.getChildElement('.configuring-failed-text'), false);
225 }
174 }, 226 },
175 227
176 /** 228 /**
177 * Adds text to parent element wrapping search query matches in highlighted 229 * Adds text to parent element wrapping search query matches in highlighted
178 * spans. 230 * spans.
179 * @param {!Element} parent Element to build the text in. 231 * @param {!Element} parent Element to build the text in.
180 * @param {string} text The text string to highlight segments in. 232 * @param {string} text The text string to highlight segments in.
181 * @private 233 * @private
182 */ 234 */
183 addTextWithHighlight_: function(parent, text) { 235 addTextWithHighlight_: function(parent, text) {
184 var sections = text.split(this.query_); 236 var sections = text.split(this.query_);
185 for (var i = 0; i < sections.length; ++i) { 237 for (var i = 0; i < sections.length; ++i) {
186 if (i % 2 == 0) { 238 if (i % 2 == 0) {
187 parent.appendChild(document.createTextNode(sections[i])); 239 parent.appendChild(document.createTextNode(sections[i]));
188 } else { 240 } else {
189 var span = document.createElement('span'); 241 var span = document.createElement('span');
190 span.className = 'destination-list-item-query-highlight'; 242 span.className = 'destination-list-item-query-highlight';
191 span.textContent = sections[i]; 243 span.textContent = sections[i];
192 parent.appendChild(span); 244 parent.appendChild(span);
193 } 245 }
194 } 246 }
195 }, 247 },
196 248
197 /** 249 /**
198 * Called when the destination item is activated. Dispatches a SELECT event 250 * Shows/Hides the configuring in progress message and starts/stops its
199 * on the given event target. 251 * animation accordingly.
252 * @param {bool} show If the message and animation should be shown.
253 * @private
254 */
255 updateConfiguringMessage_: function(show) {
256 setIsVisible(
257 this.getChildElement('.configuring-in-progress-text'), show);
258 this.getChildElement('.configuring-text-jumping-dots')
259 .classList.toggle('jumping-dots', show);
260 },
261
262 /**
263 * Called when the destination item is activated. Check if the printer needs
264 * to be set up first before activation.
200 * @private 265 * @private
201 */ 266 */
202 onActivate_: function() { 267 onActivate_: function() {
268 if (!cr.isChromeOS) {
269 onDestinationActivated_();
270 return;
271 }
272
273 // Check if the printer needs configuration before using. The user is only
274 // allowed to set up one printer at one time.
275 var configureEvent = new CustomEvent(
276 DestinationListItem.EventType.CONFIGURE_REQUEST,
277 {detail: {destination: this.destination_}});
278 this.eventTarget_.dispatchEvent(configureEvent);
279 },
280
281 /**
282 * Called when the destination has been resolved successfully and needs to
283 * be activated. Dispatches a SELECT event on the given event target.
284 * @private
285 */
286 onDestinationActivated_: function() {
203 if (this.destination_.id == 287 if (this.destination_.id ==
204 print_preview.Destination.GooglePromotedId.FEDEX && 288 print_preview.Destination.GooglePromotedId.FEDEX &&
205 !this.destination_.isTosAccepted) { 289 !this.destination_.isTosAccepted) {
206 if (!this.fedexTos_) { 290 if (!this.fedexTos_) {
207 this.fedexTos_ = new print_preview.FedexTos(); 291 this.fedexTos_ = new print_preview.FedexTos();
208 this.fedexTos_.render(this.getElement()); 292 this.fedexTos_.render(this.getElement());
209 this.tracker.add( 293 this.tracker.add(
210 this.fedexTos_, 294 this.fedexTos_,
211 print_preview.FedexTos.EventType.AGREE, 295 print_preview.FedexTos.EventType.AGREE,
212 this.onTosAgree_.bind(this)); 296 this.onTosAgree_.bind(this));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 return; 371 return;
288 this.onExtensionIconClicked_(event); 372 this.onExtensionIconClicked_(event);
289 } 373 }
290 }; 374 };
291 375
292 // Export 376 // Export
293 return { 377 return {
294 DestinationListItem: DestinationListItem 378 DestinationListItem: DestinationListItem
295 }; 379 };
296 }); 380 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698