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

Side by Side Diff: chrome/browser/resources/print_preview/search/destination_search.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 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 /** 68 /**
69 * Child overlay used for resolving a provisional destination. The overlay 69 * Child overlay used for resolving a provisional destination. The overlay
70 * is shown when the user attempts to select a provisional destination. 70 * is shown when the user attempts to select a provisional destination.
71 * Set only when a destination is being resolved. 71 * Set only when a destination is being resolved.
72 * @private {?print_preview.ProvisionalDestinationResolver} 72 * @private {?print_preview.ProvisionalDestinationResolver}
73 */ 73 */
74 this.provisionalDestinationResolver_ = null; 74 this.provisionalDestinationResolver_ = null;
75 75
76 /** 76 /**
77 * The destination that is currently in configuration.
78 * @private {?print_preview.Destination}
79 */
80 this.destinationInConfiguring_ = null;
81
82 /**
77 * Search box used to search through the destination lists. 83 * Search box used to search through the destination lists.
78 * @type {!print_preview.SearchBox} 84 * @type {!print_preview.SearchBox}
79 * @private 85 * @private
80 */ 86 */
81 this.searchBox_ = new print_preview.SearchBox( 87 this.searchBox_ = new print_preview.SearchBox(
82 loadTimeData.getString('searchBoxPlaceholder')); 88 loadTimeData.getString('searchBoxPlaceholder'));
83 this.addChild(this.searchBox_); 89 this.addChild(this.searchBox_);
84 90
85 /** 91 /**
86 * Destination list containing recent destinations. 92 * Destination list containing recent destinations.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 this.tracker.add( 222 this.tracker.add(
217 this.getChildElement('.cloudprint-promo > .close-button'), 223 this.getChildElement('.cloudprint-promo > .close-button'),
218 'click', 224 'click',
219 this.onCloudprintPromoCloseButtonClick_.bind(this)); 225 this.onCloudprintPromoCloseButtonClick_.bind(this));
220 this.tracker.add( 226 this.tracker.add(
221 this.searchBox_, 227 this.searchBox_,
222 print_preview.SearchBox.EventType.SEARCH, 228 print_preview.SearchBox.EventType.SEARCH,
223 this.onSearch_.bind(this)); 229 this.onSearch_.bind(this));
224 this.tracker.add( 230 this.tracker.add(
225 this, 231 this,
232 print_preview.DestinationListItem.EventType.CONFIGURE_REQUEST,
233 this.onDestinationConfigureRequest_.bind(this));
234 this.tracker.add(
235 this,
226 print_preview.DestinationListItem.EventType.SELECT, 236 print_preview.DestinationListItem.EventType.SELECT,
227 this.onDestinationSelect_.bind(this)); 237 this.onDestinationSelect_.bind(this));
228 this.tracker.add( 238 this.tracker.add(
229 this, 239 this,
230 print_preview.DestinationListItem.EventType.REGISTER_PROMO_CLICKED, 240 print_preview.DestinationListItem.EventType.REGISTER_PROMO_CLICKED,
231 function() { 241 function() {
232 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. 242 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket.
233 REGISTER_PROMO_SELECTED); 243 REGISTER_PROMO_SELECTED);
234 }.bind(this)); 244 }.bind(this));
235 245
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 561
552 setIsVisible(this.getChildElement('.user-info'), loggedIn); 562 setIsVisible(this.getChildElement('.user-info'), loggedIn);
553 setIsVisible(this.getChildElement('.cloud-list'), loggedIn); 563 setIsVisible(this.getChildElement('.cloud-list'), loggedIn);
554 setIsVisible(this.getChildElement('.cloudprint-promo'), !loggedIn); 564 setIsVisible(this.getChildElement('.cloudprint-promo'), !loggedIn);
555 this.updateInvitations_(); 565 this.updateInvitations_();
556 }, 566 },
557 567
558 /** 568 /**
559 * Called when a destination search should be executed. Filters the 569 * Called when a destination search should be executed. Filters the
560 * destination lists with the given query. 570 * destination lists with the given query.
561 * @param {Event} evt Contains the search query. 571 * @param {!Event} event Contains the search query.
562 * @private 572 * @private
563 */ 573 */
564 onSearch_: function(evt) { 574 onSearch_: function(event) {
565 this.filterLists_(evt.queryRegExp); 575 this.filterLists_(event.queryRegExp);
576 },
577
578 /**
579 * Handler for {@code print_preview.DestinationListItem.EventType.
580 * CONFIGURE_REQUEST} event, which is called to check a destination list
581 * item needs to be setup on Chrome OS before being selected. Note we do not
582 * allow configuring more than one destination at the same time.
583 * @param {!CustomEvent} event Contains the destination needs to be setup.
584 * @private
585 */
586 onDestinationConfigureRequest_: function(event) {
587 var destination = event.detail.destination;
588 var destinationItem = destination.isLocal ?
589 this.localList_.getDestinationItem(destination.id) :
590 this.cloudList_.getDestinationItem(destination.id);
591 assert(destinationItem != null,
592 'User does not select a valid destination item.');
593
594 // Another printer setup is in process or the printer doesn't need to be
595 // set up. Reject the setup request directly.
596 if (this.destinationInConfiguring_ != null ||
597 destination.origin != print_preview.Destination.Origin.CROS ||
598 destination.capabilities != null) {
599 destinationItem.onConfigureRequestRejected(
600 this.destinationInConfiguring_ != null);
601 } else {
602 destinationItem.onConfigureRequestAccepted();
603 this.handleConfigureDestination_(destination);
604 }
605 },
606
607 /**
608 * Called When a destination needs to be setup.
609 * @param {!print_preview.Destination} destination The destination needs to
610 * be setup.
611 * @private
612 */
613 handleConfigureDestination_: function(destination) {
614 assert(destination.origin == print_preview.Destination.Origin.CROS,
615 'Only local printer on Chrome OS requires setup.');
616 this.destinationInConfiguring_ = destination;
617 this.destinationStore_.resolveCrosDestination(destination).then(
618 /**
619 * @param {!print_preview.PrinterSetupResponse} response.
620 */
621 function(response) {
622 this.destinationInConfiguring_ = null;
623 this.localList_.getDestinationItem(destination.id)
624 .onConfigureResolved(response);
625 }.bind(this),
626 function() {
627 this.destinationInConfiguring_ = null;
628 this.localList_.getDestinationItem(destination.id)
629 .onConfigureResolved({printerId: destination.id,
630 success: false});
631 }.bind(this));
566 }, 632 },
567 633
568 /** 634 /**
569 * Handler for {@code print_preview.DestinationListItem.EventType.SELECT} 635 * Handler for {@code print_preview.DestinationListItem.EventType.SELECT}
570 * event, which is called when a destinationi list item is selected. 636 * event, which is called when a destination list item is selected.
571 * @param {Event} evt Contains the selected destination. 637 * @param {Event} event Contains the selected destination.
572 * @private 638 * @private
573 */ 639 */
574 onDestinationSelect_: function(evt) { 640 onDestinationSelect_: function(event) {
575 this.handleOnDestinationSelect_(evt.destination); 641 this.handleOnDestinationSelect_(event.destination);
576 }, 642 },
577 643
578 /** 644 /**
579 * Called when a destination is selected. Clears the search and hides the 645 * Called when a destination is selected. Clears the search and hides the
580 * widget. If The destination is provisional, it runs provisional 646 * widget. If The destination is provisional, it runs provisional
581 * destination resolver first. 647 * destination resolver first.
582 * @param {!print_preview.Destination} destination The selected destination. 648 * @param {!print_preview.Destination} destination The selected destination.
583 * @private 649 * @private
584 */ 650 */
585 handleOnDestinationSelect_: function(destination) { 651 handleOnDestinationSelect_: function(destination) {
586 if (destination.origin == print_preview.Destination.Origin.CROS &&
587 !destination.capabilities) {
588 // local printers on CrOS require setup.
589 assert(!this.printerConfigurer_);
590 this.printerConfigurer_ = new print_preview.CrosDestinationResolver(
591 this.destinationStore_, destination);
592 this.addChild(this.printerConfigurer_);
593 this.printerConfigurer_.run(this.getElement()).
594 then(
595 /**
596 * @param {!print_preview.PrinterSetupResponse} result
597 * An object containing the printerId and capabilities.
598 */
599 function(result) {
600 assert(result.printerId == destination.id);
601 destination.capabilities = result.capabilities;
602 this.handleOnDestinationSelect_(destination);
603 }.bind(this),
604 function() {
605 console.warn(
606 'Failed to setup destination: ' + destination.id);
607 }).
608 then(function() {
609 this.removeChild(this.printerConfigurer_);
610 this.printerConfigurer_ = null;
611 }.bind(this));
612 return;
613 }
614
615 if (destination.isProvisional) { 652 if (destination.isProvisional) {
616 assert(!this.provisionalDestinationResolver_, 653 assert(!this.provisionalDestinationResolver_,
617 'Provisional destination resolver already exists.'); 654 'Provisional destination resolver already exists.');
618 this.provisionalDestinationResolver_ = 655 this.provisionalDestinationResolver_ =
619 print_preview.ProvisionalDestinationResolver.create( 656 print_preview.ProvisionalDestinationResolver.create(
620 this.destinationStore_, destination); 657 this.destinationStore_, destination);
621 assert(!!this.provisionalDestinationResolver_, 658 assert(!!this.provisionalDestinationResolver_,
622 'Unable to create provisional destination resolver'); 659 'Unable to create provisional destination resolver');
623 660
624 var lastFocusedElement = document.activeElement; 661 var lastFocusedElement = document.activeElement;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 onWindowResize_: function() { 830 onWindowResize_: function() {
794 this.reflowLists_(); 831 this.reflowLists_();
795 } 832 }
796 }; 833 };
797 834
798 // Export 835 // Export
799 return { 836 return {
800 DestinationSearch: DestinationSearch 837 DestinationSearch: DestinationSearch
801 }; 838 };
802 }); 839 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698