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