| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 setTimeout(function(element) { | 140 setTimeout(function(element) { |
| 141 element.classList.remove('transparent'); | 141 element.classList.remove('transparent'); |
| 142 }.bind(this, this.getElement()), 0); | 142 }.bind(this, this.getElement()), 0); |
| 143 this.searchBox_.focus(); | 143 this.searchBox_.focus(); |
| 144 var promoEl = this.getChildElement('.cloudprint-promo'); | 144 var promoEl = this.getChildElement('.cloudprint-promo'); |
| 145 if (getIsVisible(promoEl)) { | 145 if (getIsVisible(promoEl)) { |
| 146 this.metrics_.incrementDestinationSearchBucket( | 146 this.metrics_.incrementDestinationSearchBucket( |
| 147 print_preview.Metrics.DestinationSearchBucket. | 147 print_preview.Metrics.DestinationSearchBucket. |
| 148 CLOUDPRINT_PROMO_SHOWN); | 148 CLOUDPRINT_PROMO_SHOWN); |
| 149 } | 149 } |
| 150 if (this.userInfo_.initialized) { |
| 151 this.onUsersChanged_(); |
| 152 } |
| 150 this.reflowLists_(); | 153 this.reflowLists_(); |
| 151 } else { | 154 } else { |
| 152 this.getElement().classList.add('transparent'); | 155 this.getElement().classList.add('transparent'); |
| 153 // Collapse all destination lists | 156 // Collapse all destination lists |
| 154 this.localList_.setIsShowAll(false); | 157 this.localList_.setIsShowAll(false); |
| 155 this.cloudList_.setIsShowAll(false); | 158 this.cloudList_.setIsShowAll(false); |
| 156 this.searchBox_.setQuery(''); | 159 this.searchBox_.setQuery(''); |
| 157 this.filterLists_(null); | 160 this.filterLists_(null); |
| 158 } | 161 } |
| 159 }, | 162 }, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 this.destinationStore_, | 220 this.destinationStore_, |
| 218 print_preview.DestinationStore.EventType.DESTINATION_SELECT, | 221 print_preview.DestinationStore.EventType.DESTINATION_SELECT, |
| 219 this.onDestinationStoreSelect_.bind(this)); | 222 this.onDestinationStoreSelect_.bind(this)); |
| 220 this.tracker.add( | 223 this.tracker.add( |
| 221 this.destinationStore_, | 224 this.destinationStore_, |
| 222 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_STARTED, | 225 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_STARTED, |
| 223 this.updateThrobbers_.bind(this)); | 226 this.updateThrobbers_.bind(this)); |
| 224 this.tracker.add( | 227 this.tracker.add( |
| 225 this.destinationStore_, | 228 this.destinationStore_, |
| 226 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE, | 229 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE, |
| 227 this.updateThrobbers_.bind(this)); | 230 this.onDestinationSearchDone_.bind(this)); |
| 228 | 231 |
| 229 this.tracker.add( | 232 this.tracker.add( |
| 230 this.localList_, | 233 this.localList_, |
| 231 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, | 234 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, |
| 232 this.onManageLocalDestinationsActivated_.bind(this)); | 235 this.onManageLocalDestinationsActivated_.bind(this)); |
| 233 this.tracker.add( | 236 this.tracker.add( |
| 234 this.cloudList_, | 237 this.cloudList_, |
| 235 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, | 238 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, |
| 236 this.onManageCloudDestinationsActivated_.bind(this)); | 239 this.onManageCloudDestinationsActivated_.bind(this)); |
| 237 | 240 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 /** | 308 /** |
| 306 * Renders all of the destinations in the destination store. | 309 * Renders all of the destinations in the destination store. |
| 307 * @private | 310 * @private |
| 308 */ | 311 */ |
| 309 renderDestinations_: function() { | 312 renderDestinations_: function() { |
| 310 var recentDestinations = []; | 313 var recentDestinations = []; |
| 311 var localDestinations = []; | 314 var localDestinations = []; |
| 312 var cloudDestinations = []; | 315 var cloudDestinations = []; |
| 313 var unregisteredCloudDestinations = []; | 316 var unregisteredCloudDestinations = []; |
| 314 | 317 |
| 315 this.destinationStore_.destinations.forEach(function(destination) { | 318 var destinations = |
| 319 this.destinationStore_.destinations(this.userInfo_.activeUser); |
| 320 destinations.forEach(function(destination) { |
| 316 if (destination.isRecent) { | 321 if (destination.isRecent) { |
| 317 recentDestinations.push(destination); | 322 recentDestinations.push(destination); |
| 318 } | 323 } |
| 319 if (destination.isLocal || | 324 if (destination.isLocal || |
| 320 destination.origin == print_preview.Destination.Origin.DEVICE) { | 325 destination.origin == print_preview.Destination.Origin.DEVICE) { |
| 321 localDestinations.push(destination); | 326 localDestinations.push(destination); |
| 322 } else { | 327 } else { |
| 323 if (destination.connectionStatus == | 328 if (destination.connectionStatus == |
| 324 print_preview.Destination.ConnectionStatus.UNREGISTERED) { | 329 print_preview.Destination.ConnectionStatus.UNREGISTERED) { |
| 325 unregisteredCloudDestinations.push(destination); | 330 unregisteredCloudDestinations.push(destination); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 this.localList_.setIsThrobberVisible( | 406 this.localList_.setIsThrobberVisible( |
| 402 this.destinationStore_.isLocalDestinationSearchInProgress); | 407 this.destinationStore_.isLocalDestinationSearchInProgress); |
| 403 this.cloudList_.setIsThrobberVisible( | 408 this.cloudList_.setIsThrobberVisible( |
| 404 this.destinationStore_.isCloudDestinationSearchInProgress); | 409 this.destinationStore_.isCloudDestinationSearchInProgress); |
| 405 this.recentList_.setIsThrobberVisible( | 410 this.recentList_.setIsThrobberVisible( |
| 406 this.destinationStore_.isLocalDestinationSearchInProgress && | 411 this.destinationStore_.isLocalDestinationSearchInProgress && |
| 407 this.destinationStore_.isCloudDestinationSearchInProgress); | 412 this.destinationStore_.isCloudDestinationSearchInProgress); |
| 408 this.reflowLists_(); | 413 this.reflowLists_(); |
| 409 }, | 414 }, |
| 410 | 415 |
| 411 | |
| 412 /** | 416 /** |
| 413 * Updates the account selection UI. | 417 * Called when user's logged in accounts change. Updates the UI. |
| 414 * @param {string} email Email of the logged in user. | 418 * @private |
| 415 * @param {!Array.<string>} accounts List of logged in user accounts. | |
| 416 */ | 419 */ |
| 417 setAccounts_: function(email, accounts) { | 420 onUsersChanged_: function() { |
| 418 var loggedIn = !!email; | 421 var loggedIn = this.userInfo_.loggedIn; |
| 419 if (loggedIn) { | 422 if (loggedIn) { |
| 420 var accountSelectEl = this.getChildElement('.account-select'); | 423 var accountSelectEl = this.getChildElement('.account-select'); |
| 421 accountSelectEl.innerHTML = ''; | 424 accountSelectEl.innerHTML = ''; |
| 422 accounts.forEach(function(account) { | 425 this.userInfo_.users.forEach(function(account) { |
| 423 var option = document.createElement('option'); | 426 var option = document.createElement('option'); |
| 424 option.text = account; | 427 option.text = account; |
| 425 option.value = account; | 428 option.value = account; |
| 426 accountSelectEl.add(option); | 429 accountSelectEl.add(option); |
| 427 }); | 430 }); |
| 428 var option = document.createElement('option'); | 431 var option = document.createElement('option'); |
| 429 option.text = localStrings.getString('addAccountTitle'); | 432 option.text = localStrings.getString('addAccountTitle'); |
| 430 option.value = ''; | 433 option.value = ''; |
| 431 accountSelectEl.add(option); | 434 accountSelectEl.add(option); |
| 432 | 435 |
| 433 accountSelectEl.selectedIndex = accounts.indexOf(email); | 436 accountSelectEl.selectedIndex = |
| 437 this.userInfo_.users.indexOf(this.userInfo_.activeUser); |
| 434 } | 438 } |
| 435 | 439 |
| 436 setIsVisible(this.getChildElement('.user-info'), loggedIn); | 440 setIsVisible(this.getChildElement('.user-info'), loggedIn); |
| 437 setIsVisible(this.getChildElement('.cloud-list'), loggedIn); | 441 setIsVisible(this.getChildElement('.cloud-list'), loggedIn); |
| 438 setIsVisible(this.getChildElement('.cloudprint-promo'), !loggedIn); | 442 setIsVisible(this.getChildElement('.cloudprint-promo'), !loggedIn); |
| 439 this.reflowLists_(); | 443 this.reflowLists_(); |
| 440 }, | 444 }, |
| 441 | 445 |
| 442 /** | 446 /** |
| 443 * Called when a destination search should be executed. Filters the | 447 * Called when a destination search should be executed. Filters the |
| (...skipping 29 matching lines...) Expand all Loading... |
| 473 this.metrics_.incrementDestinationSearchBucket( | 477 this.metrics_.incrementDestinationSearchBucket( |
| 474 print_preview.Metrics.DestinationSearchBucket.DESTINATION_SELECTED); | 478 print_preview.Metrics.DestinationSearchBucket.DESTINATION_SELECTED); |
| 475 }, | 479 }, |
| 476 | 480 |
| 477 /** | 481 /** |
| 478 * Called when a destination is selected. Selected destination are marked as | 482 * Called when a destination is selected. Selected destination are marked as |
| 479 * recent, so we have to update our recent destinations list. | 483 * recent, so we have to update our recent destinations list. |
| 480 * @private | 484 * @private |
| 481 */ | 485 */ |
| 482 onDestinationStoreSelect_: function() { | 486 onDestinationStoreSelect_: function() { |
| 483 var destinations = this.destinationStore_.destinations; | 487 var destinations = |
| 488 this.destinationStore_.destinations(this.userInfo_.activeUser); |
| 484 var recentDestinations = []; | 489 var recentDestinations = []; |
| 485 destinations.forEach(function(destination) { | 490 destinations.forEach(function(destination) { |
| 486 if (destination.isRecent) { | 491 if (destination.isRecent) { |
| 487 recentDestinations.push(destination); | 492 recentDestinations.push(destination); |
| 488 } | 493 } |
| 489 }); | 494 }); |
| 490 this.recentList_.updateDestinations(recentDestinations); | 495 this.recentList_.updateDestinations(recentDestinations); |
| 491 this.reflowLists_(); | 496 this.reflowLists_(); |
| 492 }, | 497 }, |
| 493 | 498 |
| 494 /** | 499 /** |
| 495 * Called when destinations are inserted into the store. Rerenders | 500 * Called when destinations are inserted into the store. Rerenders |
| 496 * destinations. | 501 * destinations. |
| 497 * @private | 502 * @private |
| 498 */ | 503 */ |
| 499 onDestinationsInserted_: function() { | 504 onDestinationsInserted_: function() { |
| 500 this.renderDestinations_(); | 505 this.renderDestinations_(); |
| 501 this.reflowLists_(); | 506 this.reflowLists_(); |
| 502 }, | 507 }, |
| 503 | 508 |
| 504 /** | 509 /** |
| 510 * Called when destinations are inserted into the store. Rerenders |
| 511 * destinations. |
| 512 * @private |
| 513 */ |
| 514 onDestinationSearchDone_: function() { |
| 515 this.updateThrobbers_(); |
| 516 this.renderDestinations_(); |
| 517 this.reflowLists_(); |
| 518 }, |
| 519 |
| 520 /** |
| 505 * Called when the manage cloud printers action is activated. | 521 * Called when the manage cloud printers action is activated. |
| 506 * @private | 522 * @private |
| 507 */ | 523 */ |
| 508 onManageCloudDestinationsActivated_: function() { | 524 onManageCloudDestinationsActivated_: function() { |
| 509 cr.dispatchSimpleEvent( | 525 cr.dispatchSimpleEvent( |
| 510 this, | 526 this, |
| 511 print_preview.DestinationSearch.EventType.MANAGE_CLOUD_DESTINATIONS); | 527 print_preview.DestinationSearch.EventType.MANAGE_CLOUD_DESTINATIONS); |
| 512 }, | 528 }, |
| 513 | 529 |
| 514 /** | 530 /** |
| (...skipping 21 matching lines...) Expand all Loading... |
| 536 * Called when item in the Accounts list is selected. Initiates active user | 552 * Called when item in the Accounts list is selected. Initiates active user |
| 537 * switch or, for 'Add account...' item, opens Google sign-in page. | 553 * switch or, for 'Add account...' item, opens Google sign-in page. |
| 538 * @private | 554 * @private |
| 539 */ | 555 */ |
| 540 onAccountChange_: function() { | 556 onAccountChange_: function() { |
| 541 var accountSelectEl = this.getChildElement('.account-select'); | 557 var accountSelectEl = this.getChildElement('.account-select'); |
| 542 var account = | 558 var account = |
| 543 accountSelectEl.options[accountSelectEl.selectedIndex].value; | 559 accountSelectEl.options[accountSelectEl.selectedIndex].value; |
| 544 if (account) { | 560 if (account) { |
| 545 this.userInfo_.activeUser = account; | 561 this.userInfo_.activeUser = account; |
| 562 this.destinationStore_.reloadUserCookieBasedDestinations(); |
| 546 } else { | 563 } else { |
| 547 cr.dispatchSimpleEvent(this, DestinationSearch.EventType.ADD_ACCOUNT); | 564 cr.dispatchSimpleEvent(this, DestinationSearch.EventType.ADD_ACCOUNT); |
| 548 // Set selection back to the active user. | 565 // Set selection back to the active user. |
| 549 for (var i = 0; i < accountSelectEl.options.length; i++) { | 566 for (var i = 0; i < accountSelectEl.options.length; i++) { |
| 550 if (accountSelectEl.options[i].value == this.userInfo_.activeUser) { | 567 if (accountSelectEl.options[i].value == this.userInfo_.activeUser) { |
| 551 accountSelectEl.selectedIndex = i; | 568 accountSelectEl.selectedIndex = i; |
| 552 break; | 569 break; |
| 553 } | 570 } |
| 554 } | 571 } |
| 555 } | 572 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 577 | 594 |
| 578 /** | 595 /** |
| 579 * Called when an animation ends on the page. | 596 * Called when an animation ends on the page. |
| 580 * @private | 597 * @private |
| 581 */ | 598 */ |
| 582 onAnimationEnd_: function() { | 599 onAnimationEnd_: function() { |
| 583 this.getChildElement('.page').classList.remove('pulse'); | 600 this.getChildElement('.page').classList.remove('pulse'); |
| 584 }, | 601 }, |
| 585 | 602 |
| 586 /** | 603 /** |
| 587 * Called when user's logged in accounts change. Updates the UI. | |
| 588 * @private | |
| 589 */ | |
| 590 onUsersChanged_: function() { | |
| 591 this.setAccounts_(this.userInfo_.activeUser, this.userInfo_.users); | |
| 592 }, | |
| 593 | |
| 594 /** | |
| 595 * Called when the window is resized. Reflows layout of destination lists. | 604 * Called when the window is resized. Reflows layout of destination lists. |
| 596 * @private | 605 * @private |
| 597 */ | 606 */ |
| 598 onWindowResize_: function() { | 607 onWindowResize_: function() { |
| 599 this.reflowLists_(); | 608 this.reflowLists_(); |
| 600 } | 609 } |
| 601 }; | 610 }; |
| 602 | 611 |
| 603 // Export | 612 // Export |
| 604 return { | 613 return { |
| 605 DestinationSearch: DestinationSearch | 614 DestinationSearch: DestinationSearch |
| 606 }; | 615 }; |
| 607 }); | 616 }); |
| OLD | NEW |