| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Whether or not a UMA histogram for the register promo being shown was | 61 * Whether or not a UMA histogram for the register promo being shown was |
| 62 * already recorded. | 62 * already recorded. |
| 63 * @type {boolean} | 63 * @type {boolean} |
| 64 * @private | 64 * @private |
| 65 */ | 65 */ |
| 66 this.registerPromoShownMetricRecorded_ = false; | 66 this.registerPromoShownMetricRecorded_ = false; |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Child overlay used for resolving a provisional destination. The overlay |
| 70 * is shown when the user attempts to select a provisional destination. |
| 71 * Set only when a destination is being resolved. |
| 72 * @private {?print_preview.ProvisionalDestinationResolver} |
| 73 */ |
| 74 this.provisionalDestinationResolver_ = null; |
| 75 |
| 76 /** |
| 69 * Search box used to search through the destination lists. | 77 * Search box used to search through the destination lists. |
| 70 * @type {!print_preview.SearchBox} | 78 * @type {!print_preview.SearchBox} |
| 71 * @private | 79 * @private |
| 72 */ | 80 */ |
| 73 this.searchBox_ = new print_preview.SearchBox( | 81 this.searchBox_ = new print_preview.SearchBox( |
| 74 loadTimeData.getString('searchBoxPlaceholder')); | 82 loadTimeData.getString('searchBoxPlaceholder')); |
| 75 this.addChild(this.searchBox_); | 83 this.addChild(this.searchBox_); |
| 76 | 84 |
| 77 /** | 85 /** |
| 78 * Destination list containing recent destinations. | 86 * Destination list containing recent destinations. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 this.reflowLists_(); | 154 this.reflowLists_(); |
| 147 this.metrics_.record( | 155 this.metrics_.record( |
| 148 print_preview.Metrics.DestinationSearchBucket.DESTINATION_SHOWN); | 156 print_preview.Metrics.DestinationSearchBucket.DESTINATION_SHOWN); |
| 149 | 157 |
| 150 this.destinationStore_.startLoadAllDestinations(); | 158 this.destinationStore_.startLoadAllDestinations(); |
| 151 this.invitationStore_.startLoadingInvitations(); | 159 this.invitationStore_.startLoadingInvitations(); |
| 152 } else { | 160 } else { |
| 153 // Collapse all destination lists | 161 // Collapse all destination lists |
| 154 this.localList_.setIsShowAll(false); | 162 this.localList_.setIsShowAll(false); |
| 155 this.cloudList_.setIsShowAll(false); | 163 this.cloudList_.setIsShowAll(false); |
| 164 if (this.provisionalDestinationResolver_) |
| 165 this.provisionalDestinationResolver_.cancel(); |
| 156 this.resetSearch_(); | 166 this.resetSearch_(); |
| 157 } | 167 } |
| 158 }, | 168 }, |
| 159 | 169 |
| 160 /** @override */ | 170 /** @override */ |
| 161 onCancelInternal: function() { | 171 onCancelInternal: function() { |
| 162 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. | 172 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. |
| 163 DESTINATION_CLOSED_UNCHANGED); | 173 DESTINATION_CLOSED_UNCHANGED); |
| 164 }, | 174 }, |
| 165 | 175 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 print_preview.DestinationStore.EventType.DESTINATION_SELECT, | 235 print_preview.DestinationStore.EventType.DESTINATION_SELECT, |
| 226 this.onDestinationStoreSelect_.bind(this)); | 236 this.onDestinationStoreSelect_.bind(this)); |
| 227 this.tracker.add( | 237 this.tracker.add( |
| 228 this.destinationStore_, | 238 this.destinationStore_, |
| 229 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_STARTED, | 239 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_STARTED, |
| 230 this.updateThrobbers_.bind(this)); | 240 this.updateThrobbers_.bind(this)); |
| 231 this.tracker.add( | 241 this.tracker.add( |
| 232 this.destinationStore_, | 242 this.destinationStore_, |
| 233 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE, | 243 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE, |
| 234 this.onDestinationSearchDone_.bind(this)); | 244 this.onDestinationSearchDone_.bind(this)); |
| 245 this.tracker.add( |
| 246 this.destinationStore_, |
| 247 print_preview.DestinationStore.EventType |
| 248 .PROVISIONAL_DESTINATION_RESOLVED, |
| 249 this.onDestinationsInserted_.bind(this)); |
| 235 | 250 |
| 236 this.tracker.add( | 251 this.tracker.add( |
| 237 this.invitationStore_, | 252 this.invitationStore_, |
| 238 print_preview.InvitationStore.EventType.INVITATION_SEARCH_DONE, | 253 print_preview.InvitationStore.EventType.INVITATION_SEARCH_DONE, |
| 239 this.updateInvitations_.bind(this)); | 254 this.updateInvitations_.bind(this)); |
| 240 this.tracker.add( | 255 this.tracker.add( |
| 241 this.invitationStore_, | 256 this.invitationStore_, |
| 242 print_preview.InvitationStore.EventType.INVITATION_PROCESSED, | 257 print_preview.InvitationStore.EventType.INVITATION_PROCESSED, |
| 243 this.updateInvitations_.bind(this)); | 258 this.updateInvitations_.bind(this)); |
| 244 | 259 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 * Called when a destination search should be executed. Filters the | 552 * Called when a destination search should be executed. Filters the |
| 538 * destination lists with the given query. | 553 * destination lists with the given query. |
| 539 * @param {Event} evt Contains the search query. | 554 * @param {Event} evt Contains the search query. |
| 540 * @private | 555 * @private |
| 541 */ | 556 */ |
| 542 onSearch_: function(evt) { | 557 onSearch_: function(evt) { |
| 543 this.filterLists_(evt.queryRegExp); | 558 this.filterLists_(evt.queryRegExp); |
| 544 }, | 559 }, |
| 545 | 560 |
| 546 /** | 561 /** |
| 562 * Handler for {@code print_preview.DestinationListItem.EventType.SELECT} |
| 563 * event, which is called when a destinationi list item is selected. |
| 564 * @param {Event} evt Contains the selected destination. |
| 565 * @private |
| 566 */ |
| 567 onDestinationSelect_: function(evt) { |
| 568 this.handleOnDestinationSelect_(evt.destination); |
| 569 }, |
| 570 |
| 571 /** |
| 547 * Called when a destination is selected. Clears the search and hides the | 572 * Called when a destination is selected. Clears the search and hides the |
| 548 * widget. | 573 * widget. If The destination is provisional, it runs provisional |
| 549 * @param {Event} evt Contains the selected destination. | 574 * destination resolver first. |
| 575 * @param {!print_preview.Destination} destination The selected destination. |
| 550 * @private | 576 * @private |
| 551 */ | 577 */ |
| 552 onDestinationSelect_: function(evt) { | 578 handleOnDestinationSelect_: function(destination) { |
| 579 if (destination.isProvisional) { |
| 580 assert(!this.provisionalDestinationResolver_, |
| 581 'Provisional destination resolver already exists.'); |
| 582 this.provisionalDestinationResolver_ = |
| 583 print_preview.ProvisionalDestinationResolver.create( |
| 584 this.destinationStore_, destination); |
| 585 assert(!!this.provisionalDestinationResolver_, |
| 586 'Unable to create provisional destination resolver'); |
| 587 |
| 588 var lastFocusedElement = document.activeElement; |
| 589 this.addChild(this.provisionalDestinationResolver_); |
| 590 this.provisionalDestinationResolver_.run(this.getElement()) |
| 591 .then( |
| 592 /** |
| 593 * @param {!print_preview.Destination} resolvedDestination |
| 594 * Destination to which the provisional destination was |
| 595 * resolved. |
| 596 */ |
| 597 function(resolvedDestination) { |
| 598 this.handleOnDestinationSelect_(resolvedDestination); |
| 599 }.bind(this)) |
| 600 .catch( |
| 601 function() { |
| 602 console.log('Failed to resolve provisional destination: ' + |
| 603 destination.id); |
| 604 }) |
| 605 .then( |
| 606 function() { |
| 607 this.removeChild(this.provisionalDestinationResolver_); |
| 608 this.provisionalDestinationResolver_ = null; |
| 609 |
| 610 // Restore focus to the previosly focused element if it's |
| 611 // still shown in the search. |
| 612 if (lastFocusedElement && |
| 613 this.getIsVisible() && |
| 614 getIsVisible(lastFocusedElement) && |
| 615 this.getElement().contains(lastFocusedElement)) { |
| 616 lastFocusedElement.focus(); |
| 617 } |
| 618 }.bind(this)); |
| 619 return; |
| 620 } |
| 621 |
| 553 this.setIsVisible(false); | 622 this.setIsVisible(false); |
| 554 this.destinationStore_.selectDestination(evt.destination); | 623 this.destinationStore_.selectDestination(destination); |
| 555 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. | 624 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. |
| 556 DESTINATION_CLOSED_CHANGED); | 625 DESTINATION_CLOSED_CHANGED); |
| 557 }, | 626 }, |
| 558 | 627 |
| 559 /** | 628 /** |
| 560 * Called when a destination is selected. Selected destination are marked as | 629 * Called when a destination is selected. Selected destination are marked as |
| 561 * recent, so we have to update our recent destinations list. | 630 * recent, so we have to update our recent destinations list. |
| 562 * @private | 631 * @private |
| 563 */ | 632 */ |
| 564 onDestinationStoreSelect_: function() { | 633 onDestinationStoreSelect_: function() { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 onWindowResize_: function() { | 757 onWindowResize_: function() { |
| 689 this.reflowLists_(); | 758 this.reflowLists_(); |
| 690 } | 759 } |
| 691 }; | 760 }; |
| 692 | 761 |
| 693 // Export | 762 // Export |
| 694 return { | 763 return { |
| 695 DestinationSearch: DestinationSearch | 764 DestinationSearch: DestinationSearch |
| 696 }; | 765 }; |
| 697 }); | 766 }); |
| OLD | NEW |