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 used for searching for a print destination. | 9 * Component used for searching for a print destination. |
10 * This is a modal dialog that allows the user to search and select a | 10 * This is a modal dialog that allows the user to search and select a |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 */ | 95 */ |
96 this.recentList_ = new print_preview.RecentDestinationList(this); | 96 this.recentList_ = new print_preview.RecentDestinationList(this); |
97 this.addChild(this.recentList_); | 97 this.addChild(this.recentList_); |
98 | 98 |
99 /** | 99 /** |
100 * Destination list containing local destinations. | 100 * Destination list containing local destinations. |
101 * @type {!print_preview.DestinationList} | 101 * @type {!print_preview.DestinationList} |
102 * @private | 102 * @private |
103 */ | 103 */ |
104 this.localList_ = new print_preview.DestinationList( | 104 this.localList_ = new print_preview.DestinationList( |
105 this, | 105 this, loadTimeData.getString('localDestinationsTitle'), |
106 loadTimeData.getString('localDestinationsTitle'), | |
107 loadTimeData.getBoolean('showLocalManageButton') ? | 106 loadTimeData.getBoolean('showLocalManageButton') ? |
108 loadTimeData.getString('manage') : null); | 107 loadTimeData.getString('manage') : |
| 108 null); |
109 this.addChild(this.localList_); | 109 this.addChild(this.localList_); |
110 | 110 |
111 /** | 111 /** |
112 * Destination list containing cloud destinations. | 112 * Destination list containing cloud destinations. |
113 * @type {!print_preview.DestinationList} | 113 * @type {!print_preview.DestinationList} |
114 * @private | 114 * @private |
115 */ | 115 */ |
116 this.cloudList_ = new print_preview.CloudDestinationList(this); | 116 this.cloudList_ = new print_preview.CloudDestinationList(this); |
117 this.addChild(this.cloudList_); | 117 this.addChild(this.cloudList_); |
118 } | 118 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 this.localList_.setIsShowAll(false); | 172 this.localList_.setIsShowAll(false); |
173 this.cloudList_.setIsShowAll(false); | 173 this.cloudList_.setIsShowAll(false); |
174 if (this.provisionalDestinationResolver_) | 174 if (this.provisionalDestinationResolver_) |
175 this.provisionalDestinationResolver_.cancel(); | 175 this.provisionalDestinationResolver_.cancel(); |
176 this.resetSearch_(); | 176 this.resetSearch_(); |
177 } | 177 } |
178 }, | 178 }, |
179 | 179 |
180 /** @override */ | 180 /** @override */ |
181 onCancelInternal: function() { | 181 onCancelInternal: function() { |
182 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. | 182 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket |
183 DESTINATION_CLOSED_UNCHANGED); | 183 .DESTINATION_CLOSED_UNCHANGED); |
184 }, | 184 }, |
185 | 185 |
186 /** Shows the Google Cloud Print promotion banner. */ | 186 /** Shows the Google Cloud Print promotion banner. */ |
187 showCloudPrintPromo: function() { | 187 showCloudPrintPromo: function() { |
188 setIsVisible(this.getChildElement('.cloudprint-promo'), true); | 188 setIsVisible(this.getChildElement('.cloudprint-promo'), true); |
189 if (this.getIsVisible()) { | 189 if (this.getIsVisible()) { |
190 this.metrics_.record( | 190 this.metrics_.record( |
191 print_preview.Metrics.DestinationSearchBucket.SIGNIN_PROMPT); | 191 print_preview.Metrics.DestinationSearchBucket.SIGNIN_PROMPT); |
192 chrome.send( | 192 chrome.send( |
193 'metricsHandler:recordAction', | 193 'metricsHandler:recordAction', |
194 ['Signin_Impression_FromCloudPrint']); | 194 ['Signin_Impression_FromCloudPrint']); |
195 } | 195 } |
196 this.reflowLists_(); | 196 this.reflowLists_(); |
197 }, | 197 }, |
198 | 198 |
199 /** @override */ | 199 /** @override */ |
200 enterDocument: function() { | 200 enterDocument: function() { |
201 print_preview.Overlay.prototype.enterDocument.call(this); | 201 print_preview.Overlay.prototype.enterDocument.call(this); |
202 | 202 |
203 this.tracker.add( | 203 this.tracker.add( |
204 this.getChildElement('.account-select'), | 204 this.getChildElement('.account-select'), 'change', |
205 'change', | |
206 this.onAccountChange_.bind(this)); | 205 this.onAccountChange_.bind(this)); |
207 | 206 |
208 this.tracker.add( | 207 this.tracker.add( |
209 this.getChildElement('.sign-in'), | 208 this.getChildElement('.sign-in'), 'click', |
210 'click', | |
211 this.onSignInActivated_.bind(this)); | 209 this.onSignInActivated_.bind(this)); |
212 | 210 |
213 this.tracker.add( | 211 this.tracker.add( |
214 this.getChildElement('.invitation-accept-button'), | 212 this.getChildElement('.invitation-accept-button'), 'click', |
215 'click', | |
216 this.onInvitationProcessButtonClick_.bind(this, true /*accept*/)); | 213 this.onInvitationProcessButtonClick_.bind(this, true /*accept*/)); |
217 this.tracker.add( | 214 this.tracker.add( |
218 this.getChildElement('.invitation-reject-button'), | 215 this.getChildElement('.invitation-reject-button'), 'click', |
219 'click', | |
220 this.onInvitationProcessButtonClick_.bind(this, false /*accept*/)); | 216 this.onInvitationProcessButtonClick_.bind(this, false /*accept*/)); |
221 | 217 |
222 this.tracker.add( | 218 this.tracker.add( |
223 this.getChildElement('.cloudprint-promo > .close-button'), | 219 this.getChildElement('.cloudprint-promo > .close-button'), 'click', |
224 'click', | |
225 this.onCloudprintPromoCloseButtonClick_.bind(this)); | 220 this.onCloudprintPromoCloseButtonClick_.bind(this)); |
226 this.tracker.add( | 221 this.tracker.add( |
227 this.searchBox_, | 222 this.searchBox_, print_preview.SearchBox.EventType.SEARCH, |
228 print_preview.SearchBox.EventType.SEARCH, | |
229 this.onSearch_.bind(this)); | 223 this.onSearch_.bind(this)); |
230 this.tracker.add( | 224 this.tracker.add( |
231 this, | 225 this, print_preview.DestinationListItem.EventType.CONFIGURE_REQUEST, |
232 print_preview.DestinationListItem.EventType.CONFIGURE_REQUEST, | |
233 this.onDestinationConfigureRequest_.bind(this)); | 226 this.onDestinationConfigureRequest_.bind(this)); |
234 this.tracker.add( | 227 this.tracker.add( |
235 this, | 228 this, print_preview.DestinationListItem.EventType.SELECT, |
236 print_preview.DestinationListItem.EventType.SELECT, | |
237 this.onDestinationSelect_.bind(this)); | 229 this.onDestinationSelect_.bind(this)); |
238 this.tracker.add( | 230 this.tracker.add( |
239 this, | 231 this, |
240 print_preview.DestinationListItem.EventType.REGISTER_PROMO_CLICKED, | 232 print_preview.DestinationListItem.EventType.REGISTER_PROMO_CLICKED, |
241 function() { | 233 function() { |
242 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. | 234 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket |
243 REGISTER_PROMO_SELECTED); | 235 .REGISTER_PROMO_SELECTED); |
244 }.bind(this)); | 236 }.bind(this)); |
245 | 237 |
246 this.tracker.add( | 238 this.tracker.add( |
247 this.destinationStore_, | 239 this.destinationStore_, |
248 print_preview.DestinationStore.EventType.DESTINATIONS_INSERTED, | 240 print_preview.DestinationStore.EventType.DESTINATIONS_INSERTED, |
249 this.onDestinationsInserted_.bind(this)); | 241 this.onDestinationsInserted_.bind(this)); |
250 this.tracker.add( | 242 this.tracker.add( |
251 this.destinationStore_, | 243 this.destinationStore_, |
252 print_preview.DestinationStore.EventType.DESTINATION_SELECT, | 244 print_preview.DestinationStore.EventType.DESTINATION_SELECT, |
253 this.onDestinationStoreSelect_.bind(this)); | 245 this.onDestinationStoreSelect_.bind(this)); |
(...skipping 23 matching lines...) Expand all Loading... |
277 this.tracker.add( | 269 this.tracker.add( |
278 this.localList_, | 270 this.localList_, |
279 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, | 271 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, |
280 this.onManageLocalDestinationsActivated_.bind(this)); | 272 this.onManageLocalDestinationsActivated_.bind(this)); |
281 this.tracker.add( | 273 this.tracker.add( |
282 this.cloudList_, | 274 this.cloudList_, |
283 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, | 275 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, |
284 this.onManageCloudDestinationsActivated_.bind(this)); | 276 this.onManageCloudDestinationsActivated_.bind(this)); |
285 | 277 |
286 this.tracker.add( | 278 this.tracker.add( |
287 this.userInfo_, | 279 this.userInfo_, print_preview.UserInfo.EventType.USERS_CHANGED, |
288 print_preview.UserInfo.EventType.USERS_CHANGED, | |
289 this.onUsersChanged_.bind(this)); | 280 this.onUsersChanged_.bind(this)); |
290 | 281 |
291 this.tracker.add( | 282 this.tracker.add( |
292 this.getChildElement('.button-strip .cancel-button'), | 283 this.getChildElement('.button-strip .cancel-button'), 'click', |
293 'click', | |
294 this.cancel.bind(this)); | 284 this.cancel.bind(this)); |
295 | 285 |
296 this.tracker.add(window, 'resize', this.onWindowResize_.bind(this)); | 286 this.tracker.add(window, 'resize', this.onWindowResize_.bind(this)); |
297 | 287 |
298 this.updateThrobbers_(); | 288 this.updateThrobbers_(); |
299 | 289 |
300 // Render any destinations already in the store. | 290 // Render any destinations already in the store. |
301 this.renderDestinations_(); | 291 this.renderDestinations_(); |
302 }, | 292 }, |
303 | 293 |
304 /** @override */ | 294 /** @override */ |
305 decorateInternal: function() { | 295 decorateInternal: function() { |
306 this.searchBox_.render(this.getChildElement('.search-box-container')); | 296 this.searchBox_.render(this.getChildElement('.search-box-container')); |
307 this.recentList_.render(this.getChildElement('.recent-list')); | 297 this.recentList_.render(this.getChildElement('.recent-list')); |
308 this.localList_.render(this.getChildElement('.local-list')); | 298 this.localList_.render(this.getChildElement('.local-list')); |
309 this.cloudList_.render(this.getChildElement('.cloud-list')); | 299 this.cloudList_.render(this.getChildElement('.cloud-list')); |
310 this.getChildElement('.promo-text').innerHTML = loadTimeData.getStringF( | 300 this.getChildElement('.promo-text').innerHTML = loadTimeData.getStringF( |
311 'cloudPrintPromotion', | 301 'cloudPrintPromotion', '<a is="action-link" class="sign-in">', |
312 '<a is="action-link" class="sign-in">', | |
313 '</a>'); | 302 '</a>'); |
314 this.getChildElement('.account-select-label').textContent = | 303 this.getChildElement('.account-select-label').textContent = |
315 loadTimeData.getString('accountSelectTitle'); | 304 loadTimeData.getString('accountSelectTitle'); |
316 }, | 305 }, |
317 | 306 |
318 /** | 307 /** |
319 * @return {number} Height available for destination lists, in pixels. | 308 * @return {number} Height available for destination lists, in pixels. |
320 * @private | 309 * @private |
321 */ | 310 */ |
322 getAvailableListsHeight_: function() { | 311 getAvailableListsHeight_: function() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 this.destinationStore_.destinations(this.userInfo_.activeUser); | 353 this.destinationStore_.destinations(this.userInfo_.activeUser); |
365 destinations.forEach(function(destination) { | 354 destinations.forEach(function(destination) { |
366 if (destination.isRecent) { | 355 if (destination.isRecent) { |
367 recentDestinations.push(destination); | 356 recentDestinations.push(destination); |
368 } | 357 } |
369 if (destination.isLocal || | 358 if (destination.isLocal || |
370 destination.origin == print_preview.DestinationOrigin.DEVICE) { | 359 destination.origin == print_preview.DestinationOrigin.DEVICE) { |
371 localDestinations.push(destination); | 360 localDestinations.push(destination); |
372 } else { | 361 } else { |
373 if (destination.connectionStatus == | 362 if (destination.connectionStatus == |
374 print_preview.DestinationConnectionStatus.UNREGISTERED) { | 363 print_preview.DestinationConnectionStatus.UNREGISTERED) { |
375 unregisteredCloudDestinations.push(destination); | 364 unregisteredCloudDestinations.push(destination); |
376 } else { | 365 } else { |
377 cloudDestinations.push(destination); | 366 cloudDestinations.push(destination); |
378 } | 367 } |
379 } | 368 } |
380 }); | 369 }); |
381 | 370 |
382 if (unregisteredCloudDestinations.length != 0 && | 371 if (unregisteredCloudDestinations.length != 0 && |
383 !this.registerPromoShownMetricRecorded_) { | 372 !this.registerPromoShownMetricRecorded_) { |
384 this.metrics_.record( | 373 this.metrics_.record( |
385 print_preview.Metrics.DestinationSearchBucket.REGISTER_PROMO_SHOWN); | 374 print_preview.Metrics.DestinationSearchBucket.REGISTER_PROMO_SHOWN); |
386 this.registerPromoShownMetricRecorded_ = true; | 375 this.registerPromoShownMetricRecorded_ = true; |
387 } | 376 } |
388 | 377 |
389 var finalCloudDestinations = unregisteredCloudDestinations.slice( | 378 var finalCloudDestinations = |
390 0, DestinationSearch.MAX_PROMOTED_UNREGISTERED_PRINTERS_).concat( | 379 unregisteredCloudDestinations |
391 cloudDestinations, | 380 .slice(0, DestinationSearch.MAX_PROMOTED_UNREGISTERED_PRINTERS_) |
392 unregisteredCloudDestinations.slice( | 381 .concat( |
393 DestinationSearch.MAX_PROMOTED_UNREGISTERED_PRINTERS_)); | 382 cloudDestinations, |
| 383 unregisteredCloudDestinations.slice( |
| 384 DestinationSearch.MAX_PROMOTED_UNREGISTERED_PRINTERS_)); |
394 | 385 |
395 this.recentList_.updateDestinations(recentDestinations); | 386 this.recentList_.updateDestinations(recentDestinations); |
396 this.localList_.updateDestinations(localDestinations); | 387 this.localList_.updateDestinations(localDestinations); |
397 this.cloudList_.updateDestinations(finalCloudDestinations); | 388 this.cloudList_.updateDestinations(finalCloudDestinations); |
398 }, | 389 }, |
399 | 390 |
400 /** | 391 /** |
401 * Reflows the destination lists according to the available height. | 392 * Reflows the destination lists according to the available height. |
402 * @private | 393 * @private |
403 */ | 394 */ |
404 reflowLists_: function() { | 395 reflowLists_: function() { |
405 if (!this.getIsVisible()) { | 396 if (!this.getIsVisible()) { |
406 return; | 397 return; |
407 } | 398 } |
408 | 399 |
409 var hasCloudList = getIsVisible(this.getChildElement('.cloud-list')); | 400 var hasCloudList = getIsVisible(this.getChildElement('.cloud-list')); |
410 var lists = [this.recentList_, this.localList_]; | 401 var lists = [this.recentList_, this.localList_]; |
411 if (hasCloudList) { | 402 if (hasCloudList) { |
412 lists.push(this.cloudList_); | 403 lists.push(this.cloudList_); |
413 } | 404 } |
414 | 405 |
415 var getListsTotalHeight = function(lists, counts) { | 406 var getListsTotalHeight = function(lists, counts) { |
416 return lists.reduce(function(sum, list, index) { | 407 return lists.reduce(function(sum, list, index) { |
417 var container = list.getContainerElement(); | 408 var container = list.getContainerElement(); |
418 return sum + list.getEstimatedHeightInPixels(counts[index]) + | 409 return sum + list.getEstimatedHeightInPixels(counts[index]) + |
419 parseInt(window.getComputedStyle(container).paddingBottom, 10); | 410 parseInt(window.getComputedStyle(container).paddingBottom, 10); |
420 }, 0); | 411 }, 0); |
421 }; | 412 }; |
422 var getCounts = function(lists, count) { | 413 var getCounts = function(lists, count) { |
423 return lists.map(function(list) { return count; }); | 414 return lists.map(function(list) { |
| 415 return count; |
| 416 }); |
424 }; | 417 }; |
425 | 418 |
426 var availableHeight = this.getAvailableListsHeight_(); | 419 var availableHeight = this.getAvailableListsHeight_(); |
427 var listsEl = this.getChildElement('.lists'); | 420 var listsEl = this.getChildElement('.lists'); |
428 listsEl.style.maxHeight = availableHeight + 'px'; | 421 listsEl.style.maxHeight = availableHeight + 'px'; |
429 | 422 |
430 var maxListLength = lists.reduce(function(prevCount, list) { | 423 var maxListLength = lists.reduce(function(prevCount, list) { |
431 return Math.max(prevCount, list.getDestinationsCount()); | 424 return Math.max(prevCount, list.getDestinationsCount()); |
432 }, 0); | 425 }, 0); |
433 for (var i = 1; i <= maxListLength; i++) { | 426 for (var i = 1; i <= maxListLength; i++) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 this.destinationStore_.isCloudDestinationSearchInProgress); | 474 this.destinationStore_.isCloudDestinationSearchInProgress); |
482 this.reflowLists_(); | 475 this.reflowLists_(); |
483 }, | 476 }, |
484 | 477 |
485 /** | 478 /** |
486 * Updates printer sharing invitations UI. | 479 * Updates printer sharing invitations UI. |
487 * @private | 480 * @private |
488 */ | 481 */ |
489 updateInvitations_: function() { | 482 updateInvitations_: function() { |
490 var invitations = this.userInfo_.activeUser ? | 483 var invitations = this.userInfo_.activeUser ? |
491 this.invitationStore_.invitations(this.userInfo_.activeUser) : []; | 484 this.invitationStore_.invitations(this.userInfo_.activeUser) : |
| 485 []; |
492 if (invitations.length > 0) { | 486 if (invitations.length > 0) { |
493 if (this.invitation_ != invitations[0]) { | 487 if (this.invitation_ != invitations[0]) { |
494 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. | 488 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket |
495 INVITATION_AVAILABLE); | 489 .INVITATION_AVAILABLE); |
496 } | 490 } |
497 this.invitation_ = invitations[0]; | 491 this.invitation_ = invitations[0]; |
498 this.showInvitation_(this.invitation_); | 492 this.showInvitation_(this.invitation_); |
499 } else { | 493 } else { |
500 this.invitation_ = null; | 494 this.invitation_ = null; |
501 } | 495 } |
502 setIsVisible( | 496 setIsVisible( |
503 this.getChildElement('.invitation-container'), !!this.invitation_); | 497 this.getChildElement('.invitation-container'), !!this.invitation_); |
504 this.reflowLists_(); | 498 this.reflowLists_(); |
505 }, | 499 }, |
506 | 500 |
507 /** | 501 /** |
508 * @param {!print_preview.Invitation} invitation Invitation to show. | 502 * @param {!print_preview.Invitation} invitation Invitation to show. |
509 * @private | 503 * @private |
510 */ | 504 */ |
511 showInvitation_: function(invitation) { | 505 showInvitation_: function(invitation) { |
512 var invitationText = ''; | 506 var invitationText = ''; |
513 if (invitation.asGroupManager) { | 507 if (invitation.asGroupManager) { |
514 invitationText = loadTimeData.getStringF( | 508 invitationText = loadTimeData.getStringF( |
515 'groupPrinterSharingInviteText', | 509 'groupPrinterSharingInviteText', HTMLEscape(invitation.sender), |
516 HTMLEscape(invitation.sender), | |
517 HTMLEscape(invitation.destination.displayName), | 510 HTMLEscape(invitation.destination.displayName), |
518 HTMLEscape(invitation.receiver)); | 511 HTMLEscape(invitation.receiver)); |
519 } else { | 512 } else { |
520 invitationText = loadTimeData.getStringF( | 513 invitationText = loadTimeData.getStringF( |
521 'printerSharingInviteText', | 514 'printerSharingInviteText', HTMLEscape(invitation.sender), |
522 HTMLEscape(invitation.sender), | |
523 HTMLEscape(invitation.destination.displayName)); | 515 HTMLEscape(invitation.destination.displayName)); |
524 } | 516 } |
525 this.getChildElement('.invitation-text').innerHTML = invitationText; | 517 this.getChildElement('.invitation-text').innerHTML = invitationText; |
526 | 518 |
527 var acceptButton = this.getChildElement('.invitation-accept-button'); | 519 var acceptButton = this.getChildElement('.invitation-accept-button'); |
528 acceptButton.textContent = loadTimeData.getString( | 520 acceptButton.textContent = loadTimeData.getString( |
529 invitation.asGroupManager ? 'acceptForGroup' : 'accept'); | 521 invitation.asGroupManager ? 'acceptForGroup' : 'accept'); |
530 acceptButton.disabled = !!this.invitationStore_.invitationInProgress; | 522 acceptButton.disabled = !!this.invitationStore_.invitationInProgress; |
531 this.getChildElement('.invitation-reject-button').disabled = | 523 this.getChildElement('.invitation-reject-button').disabled = |
532 !!this.invitationStore_.invitationInProgress; | 524 !!this.invitationStore_.invitationInProgress; |
(...skipping 16 matching lines...) Expand all Loading... |
549 option.text = account; | 541 option.text = account; |
550 option.value = account; | 542 option.value = account; |
551 accountSelectEl.add(option); | 543 accountSelectEl.add(option); |
552 }); | 544 }); |
553 var option = document.createElement('option'); | 545 var option = document.createElement('option'); |
554 option.text = loadTimeData.getString('addAccountTitle'); | 546 option.text = loadTimeData.getString('addAccountTitle'); |
555 option.value = ''; | 547 option.value = ''; |
556 accountSelectEl.add(option); | 548 accountSelectEl.add(option); |
557 | 549 |
558 accountSelectEl.selectedIndex = this.userInfo_.activeUser ? | 550 accountSelectEl.selectedIndex = this.userInfo_.activeUser ? |
559 this.userInfo_.users.indexOf(this.userInfo_.activeUser) : -1; | 551 this.userInfo_.users.indexOf(this.userInfo_.activeUser) : |
| 552 -1; |
560 } | 553 } |
561 | 554 |
562 setIsVisible(this.getChildElement('.user-info'), loggedIn); | 555 setIsVisible(this.getChildElement('.user-info'), loggedIn); |
563 setIsVisible(this.getChildElement('.cloud-list'), loggedIn); | 556 setIsVisible(this.getChildElement('.cloud-list'), loggedIn); |
564 setIsVisible(this.getChildElement('.cloudprint-promo'), !loggedIn); | 557 setIsVisible(this.getChildElement('.cloudprint-promo'), !loggedIn); |
565 this.updateInvitations_(); | 558 this.updateInvitations_(); |
566 }, | 559 }, |
567 | 560 |
568 /** | 561 /** |
569 * Called when a destination search should be executed. Filters the | 562 * Called when a destination search should be executed. Filters the |
(...skipping 14 matching lines...) Expand all Loading... |
584 * @private | 577 * @private |
585 */ | 578 */ |
586 onDestinationConfigureRequest_: function(event) { | 579 onDestinationConfigureRequest_: function(event) { |
587 var destination = event.detail.destination; | 580 var destination = event.detail.destination; |
588 // Cloud Print Device printers are stored in the local list | 581 // Cloud Print Device printers are stored in the local list |
589 // crbug.com/713831. | 582 // crbug.com/713831. |
590 // TODO(crbug.com/416701): Upon resolution, update this. | 583 // TODO(crbug.com/416701): Upon resolution, update this. |
591 var destinationItem = | 584 var destinationItem = |
592 (destination.isLocal || | 585 (destination.isLocal || |
593 destination.origin == print_preview.DestinationOrigin.DEVICE) ? | 586 destination.origin == print_preview.DestinationOrigin.DEVICE) ? |
594 this.localList_.getDestinationItem(destination.id) : | 587 this.localList_.getDestinationItem(destination.id) : |
595 this.cloudList_.getDestinationItem(destination.id); | 588 this.cloudList_.getDestinationItem(destination.id); |
596 assert(destinationItem != null, | 589 assert( |
597 'User does not select a valid destination item.'); | 590 destinationItem != null, |
| 591 'User does not select a valid destination item.'); |
598 | 592 |
599 // Another printer setup is in process or the printer doesn't need to be | 593 // Another printer setup is in process or the printer doesn't need to be |
600 // set up. Reject the setup request directly. | 594 // set up. Reject the setup request directly. |
601 if (this.destinationInConfiguring_ != null || | 595 if (this.destinationInConfiguring_ != null || |
602 destination.origin != print_preview.DestinationOrigin.CROS || | 596 destination.origin != print_preview.DestinationOrigin.CROS || |
603 destination.capabilities != null) { | 597 destination.capabilities != null) { |
604 destinationItem.onConfigureRequestRejected( | 598 destinationItem.onConfigureRequestRejected( |
605 this.destinationInConfiguring_ != null); | 599 this.destinationInConfiguring_ != null); |
606 } else { | 600 } else { |
607 destinationItem.onConfigureRequestAccepted(); | 601 destinationItem.onConfigureRequestAccepted(); |
608 this.handleConfigureDestination_(destination); | 602 this.handleConfigureDestination_(destination); |
609 } | 603 } |
610 }, | 604 }, |
611 | 605 |
612 /** | 606 /** |
613 * Called When a destination needs to be setup. | 607 * Called When a destination needs to be setup. |
614 * @param {!print_preview.Destination} destination The destination needs to | 608 * @param {!print_preview.Destination} destination The destination needs to |
615 * be setup. | 609 * be setup. |
616 * @private | 610 * @private |
617 */ | 611 */ |
618 handleConfigureDestination_: function(destination) { | 612 handleConfigureDestination_: function(destination) { |
619 assert(destination.origin == print_preview.DestinationOrigin.CROS, | 613 assert( |
620 'Only local printer on Chrome OS requires setup.'); | 614 destination.origin == print_preview.DestinationOrigin.CROS, |
| 615 'Only local printer on Chrome OS requires setup.'); |
621 this.destinationInConfiguring_ = destination; | 616 this.destinationInConfiguring_ = destination; |
622 this.destinationStore_.resolveCrosDestination(destination).then( | 617 this.destinationStore_.resolveCrosDestination(destination) |
623 /** | 618 .then( |
624 * @param {!print_preview.PrinterSetupResponse} response | 619 /** |
625 */ | 620 * @param {!print_preview.PrinterSetupResponse} response |
626 function(response) { | 621 */ |
627 this.destinationInConfiguring_ = null; | 622 function(response) { |
628 this.localList_.getDestinationItem(destination.id) | 623 this.destinationInConfiguring_ = null; |
629 .onConfigureResolved(response); | 624 this.localList_.getDestinationItem(destination.id) |
630 }.bind(this), | 625 .onConfigureResolved(response); |
631 function() { | 626 }.bind(this), |
632 this.destinationInConfiguring_ = null; | 627 function() { |
633 this.localList_.getDestinationItem(destination.id) | 628 this.destinationInConfiguring_ = null; |
634 .onConfigureResolved({printerId: destination.id, | 629 this.localList_.getDestinationItem(destination.id) |
635 success: false}); | 630 .onConfigureResolved( |
636 }.bind(this)); | 631 {printerId: destination.id, success: false}); |
| 632 }.bind(this)); |
637 }, | 633 }, |
638 | 634 |
639 /** | 635 /** |
640 * Handler for {@code print_preview.DestinationListItem.EventType.SELECT} | 636 * Handler for {@code print_preview.DestinationListItem.EventType.SELECT} |
641 * event, which is called when a destination list item is selected. | 637 * event, which is called when a destination list item is selected. |
642 * @param {Event} event Contains the selected destination. | 638 * @param {Event} event Contains the selected destination. |
643 * @private | 639 * @private |
644 */ | 640 */ |
645 onDestinationSelect_: function(event) { | 641 onDestinationSelect_: function(event) { |
646 this.handleOnDestinationSelect_(event.destination); | 642 this.handleOnDestinationSelect_(event.destination); |
647 }, | 643 }, |
648 | 644 |
649 /** | 645 /** |
650 * Called when a destination is selected. Clears the search and hides the | 646 * Called when a destination is selected. Clears the search and hides the |
651 * widget. If The destination is provisional, it runs provisional | 647 * widget. If The destination is provisional, it runs provisional |
652 * destination resolver first. | 648 * destination resolver first. |
653 * @param {!print_preview.Destination} destination The selected destination. | 649 * @param {!print_preview.Destination} destination The selected destination. |
654 * @private | 650 * @private |
655 */ | 651 */ |
656 handleOnDestinationSelect_: function(destination) { | 652 handleOnDestinationSelect_: function(destination) { |
657 if (destination.isProvisional) { | 653 if (destination.isProvisional) { |
658 assert(!this.provisionalDestinationResolver_, | 654 assert( |
659 'Provisional destination resolver already exists.'); | 655 !this.provisionalDestinationResolver_, |
| 656 'Provisional destination resolver already exists.'); |
660 this.provisionalDestinationResolver_ = | 657 this.provisionalDestinationResolver_ = |
661 print_preview.ProvisionalDestinationResolver.create( | 658 print_preview.ProvisionalDestinationResolver.create( |
662 this.destinationStore_, destination); | 659 this.destinationStore_, destination); |
663 assert(!!this.provisionalDestinationResolver_, | 660 assert( |
664 'Unable to create provisional destination resolver'); | 661 !!this.provisionalDestinationResolver_, |
| 662 'Unable to create provisional destination resolver'); |
665 | 663 |
666 var lastFocusedElement = document.activeElement; | 664 var lastFocusedElement = document.activeElement; |
667 this.addChild(this.provisionalDestinationResolver_); | 665 this.addChild(this.provisionalDestinationResolver_); |
668 this.provisionalDestinationResolver_.run(this.getElement()). | 666 this.provisionalDestinationResolver_.run(this.getElement()) |
669 then( | 667 .then( |
670 /** | 668 /** |
671 * @param {!print_preview.Destination} resolvedDestination | 669 * @param {!print_preview.Destination} resolvedDestination |
672 * Destination to which the provisional destination was | 670 * Destination to which the provisional destination was |
673 * resolved. | 671 * resolved. |
674 */ | 672 */ |
675 function(resolvedDestination) { | 673 function(resolvedDestination) { |
676 this.handleOnDestinationSelect_(resolvedDestination); | 674 this.handleOnDestinationSelect_(resolvedDestination); |
677 }.bind(this)). | 675 }.bind(this)) |
678 catch( | 676 .catch(function() { |
679 function() { | 677 console.error( |
680 console.error('Failed to resolve provisional destination: ' + | 678 'Failed to resolve provisional destination: ' + |
681 destination.id); | 679 destination.id); |
682 }). | 680 }) |
683 then( | 681 .then(function() { |
684 function() { | 682 this.removeChild(assert(this.provisionalDestinationResolver_)); |
685 this.removeChild( | 683 this.provisionalDestinationResolver_ = null; |
686 assert(this.provisionalDestinationResolver_)); | |
687 this.provisionalDestinationResolver_ = null; | |
688 | 684 |
689 // Restore focus to the previosly focused element if it's | 685 // Restore focus to the previosly focused element if it's |
690 // still shown in the search. | 686 // still shown in the search. |
691 if (lastFocusedElement && | 687 if (lastFocusedElement && this.getIsVisible() && |
692 this.getIsVisible() && | 688 getIsVisible(lastFocusedElement) && |
693 getIsVisible(lastFocusedElement) && | 689 this.getElement().contains(lastFocusedElement)) { |
694 this.getElement().contains(lastFocusedElement)) { | 690 lastFocusedElement.focus(); |
695 lastFocusedElement.focus(); | 691 } |
696 } | 692 }.bind(this)); |
697 }.bind(this)); | |
698 return; | 693 return; |
699 } | 694 } |
700 | 695 |
701 this.setIsVisible(false); | 696 this.setIsVisible(false); |
702 this.destinationStore_.selectDestination(destination); | 697 this.destinationStore_.selectDestination(destination); |
703 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. | 698 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket |
704 DESTINATION_CLOSED_CHANGED); | 699 .DESTINATION_CLOSED_CHANGED); |
705 }, | 700 }, |
706 | 701 |
707 /** | 702 /** |
708 * Called when a destination is selected. Selected destination are marked as | 703 * Called when a destination is selected. Selected destination are marked as |
709 * recent, so we have to update our recent destinations list. | 704 * recent, so we have to update our recent destinations list. |
710 * @private | 705 * @private |
711 */ | 706 */ |
712 onDestinationStoreSelect_: function() { | 707 onDestinationStoreSelect_: function() { |
713 var destinations = | 708 var destinations = |
714 this.destinationStore_.destinations(this.userInfo_.activeUser); | 709 this.destinationStore_.destinations(this.userInfo_.activeUser); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 print_preview.Metrics.DestinationSearchBucket.ADD_ACCOUNT_SELECTED); | 800 print_preview.Metrics.DestinationSearchBucket.ADD_ACCOUNT_SELECTED); |
806 } | 801 } |
807 }, | 802 }, |
808 | 803 |
809 /** | 804 /** |
810 * Called when the printer sharing invitation Accept/Reject button is | 805 * Called when the printer sharing invitation Accept/Reject button is |
811 * clicked. | 806 * clicked. |
812 * @private | 807 * @private |
813 */ | 808 */ |
814 onInvitationProcessButtonClick_: function(accept) { | 809 onInvitationProcessButtonClick_: function(accept) { |
815 this.metrics_.record(accept ? | 810 this.metrics_.record( |
816 print_preview.Metrics.DestinationSearchBucket.INVITATION_ACCEPTED : | 811 accept ? print_preview.Metrics.DestinationSearchBucket |
817 print_preview.Metrics.DestinationSearchBucket.INVITATION_REJECTED); | 812 .INVITATION_ACCEPTED : |
| 813 print_preview.Metrics.DestinationSearchBucket |
| 814 .INVITATION_REJECTED); |
818 this.invitationStore_.processInvitation(assert(this.invitation_), accept); | 815 this.invitationStore_.processInvitation(assert(this.invitation_), accept); |
819 this.updateInvitations_(); | 816 this.updateInvitations_(); |
820 }, | 817 }, |
821 | 818 |
822 /** | 819 /** |
823 * Called when the close button on the cloud print promo is clicked. Hides | 820 * Called when the close button on the cloud print promo is clicked. Hides |
824 * the promo. | 821 * the promo. |
825 * @private | 822 * @private |
826 */ | 823 */ |
827 onCloudprintPromoCloseButtonClick_: function() { | 824 onCloudprintPromoCloseButtonClick_: function() { |
828 setIsVisible(this.getChildElement('.cloudprint-promo'), false); | 825 setIsVisible(this.getChildElement('.cloudprint-promo'), false); |
829 this.reflowLists_(); | 826 this.reflowLists_(); |
830 }, | 827 }, |
831 | 828 |
832 /** | 829 /** |
833 * Called when the window is resized. Reflows layout of destination lists. | 830 * Called when the window is resized. Reflows layout of destination lists. |
834 * @private | 831 * @private |
835 */ | 832 */ |
836 onWindowResize_: function() { | 833 onWindowResize_: function() { |
837 this.reflowLists_(); | 834 this.reflowLists_(); |
838 } | 835 } |
839 }; | 836 }; |
840 | 837 |
841 // Export | 838 // Export |
842 return { | 839 return {DestinationSearch: DestinationSearch}; |
843 DestinationSearch: DestinationSearch | |
844 }; | |
845 }); | 840 }); |
OLD | NEW |