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

Side by Side Diff: chrome/browser/resources/print_preview/search/destination_search.js

Issue 233623003: Remember and restore the account last used destination is registered for. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 this.onUsersChanged_();
150 this.reflowLists_(); 151 this.reflowLists_();
151 } else { 152 } else {
152 this.getElement().classList.add('transparent'); 153 this.getElement().classList.add('transparent');
153 // Collapse all destination lists 154 // Collapse all destination lists
154 this.localList_.setIsShowAll(false); 155 this.localList_.setIsShowAll(false);
155 this.cloudList_.setIsShowAll(false); 156 this.cloudList_.setIsShowAll(false);
156 this.searchBox_.setQuery(''); 157 this.searchBox_.setQuery('');
157 this.filterLists_(null); 158 this.filterLists_(null);
158 } 159 }
159 }, 160 },
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 this.destinationStore_, 218 this.destinationStore_,
218 print_preview.DestinationStore.EventType.DESTINATION_SELECT, 219 print_preview.DestinationStore.EventType.DESTINATION_SELECT,
219 this.onDestinationStoreSelect_.bind(this)); 220 this.onDestinationStoreSelect_.bind(this));
220 this.tracker.add( 221 this.tracker.add(
221 this.destinationStore_, 222 this.destinationStore_,
222 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_STARTED, 223 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_STARTED,
223 this.updateThrobbers_.bind(this)); 224 this.updateThrobbers_.bind(this));
224 this.tracker.add( 225 this.tracker.add(
225 this.destinationStore_, 226 this.destinationStore_,
226 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE, 227 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE,
227 this.updateThrobbers_.bind(this)); 228 this.onDestinationSearchDone_.bind(this));
228 229
229 this.tracker.add( 230 this.tracker.add(
230 this.localList_, 231 this.localList_,
231 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, 232 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED,
232 this.onManageLocalDestinationsActivated_.bind(this)); 233 this.onManageLocalDestinationsActivated_.bind(this));
233 this.tracker.add( 234 this.tracker.add(
234 this.cloudList_, 235 this.cloudList_,
235 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, 236 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED,
236 this.onManageCloudDestinationsActivated_.bind(this)); 237 this.onManageCloudDestinationsActivated_.bind(this));
237 238
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 /** 306 /**
306 * Renders all of the destinations in the destination store. 307 * Renders all of the destinations in the destination store.
307 * @private 308 * @private
308 */ 309 */
309 renderDestinations_: function() { 310 renderDestinations_: function() {
310 var recentDestinations = []; 311 var recentDestinations = [];
311 var localDestinations = []; 312 var localDestinations = [];
312 var cloudDestinations = []; 313 var cloudDestinations = [];
313 var unregisteredCloudDestinations = []; 314 var unregisteredCloudDestinations = [];
314 315
315 this.destinationStore_.destinations.forEach(function(destination) { 316 var destinations =
317 this.destinationStore_.destinations(this.userInfo_.activeUser);
318 destinations.forEach(function(destination) {
316 if (destination.isRecent) { 319 if (destination.isRecent) {
317 recentDestinations.push(destination); 320 recentDestinations.push(destination);
318 } 321 }
319 if (destination.isLocal || 322 if (destination.isLocal ||
320 destination.origin == print_preview.Destination.Origin.DEVICE) { 323 destination.origin == print_preview.Destination.Origin.DEVICE) {
321 localDestinations.push(destination); 324 localDestinations.push(destination);
322 } else { 325 } else {
323 if (destination.connectionStatus == 326 if (destination.connectionStatus ==
324 print_preview.Destination.ConnectionStatus.UNREGISTERED) { 327 print_preview.Destination.ConnectionStatus.UNREGISTERED) {
325 unregisteredCloudDestinations.push(destination); 328 unregisteredCloudDestinations.push(destination);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 this.metrics_.incrementDestinationSearchBucket( 476 this.metrics_.incrementDestinationSearchBucket(
474 print_preview.Metrics.DestinationSearchBucket.DESTINATION_SELECTED); 477 print_preview.Metrics.DestinationSearchBucket.DESTINATION_SELECTED);
475 }, 478 },
476 479
477 /** 480 /**
478 * Called when a destination is selected. Selected destination are marked as 481 * Called when a destination is selected. Selected destination are marked as
479 * recent, so we have to update our recent destinations list. 482 * recent, so we have to update our recent destinations list.
480 * @private 483 * @private
481 */ 484 */
482 onDestinationStoreSelect_: function() { 485 onDestinationStoreSelect_: function() {
483 var destinations = this.destinationStore_.destinations; 486 var destinations =
487 this.destinationStore_.destinations(this.userInfo_.activeUser);
484 var recentDestinations = []; 488 var recentDestinations = [];
485 destinations.forEach(function(destination) { 489 destinations.forEach(function(destination) {
486 if (destination.isRecent) { 490 if (destination.isRecent) {
487 recentDestinations.push(destination); 491 recentDestinations.push(destination);
488 } 492 }
489 }); 493 });
490 this.recentList_.updateDestinations(recentDestinations); 494 this.recentList_.updateDestinations(recentDestinations);
491 this.reflowLists_(); 495 this.reflowLists_();
492 }, 496 },
493 497
494 /** 498 /**
495 * Called when destinations are inserted into the store. Rerenders 499 * Called when destinations are inserted into the store. Rerenders
496 * destinations. 500 * destinations.
497 * @private 501 * @private
498 */ 502 */
499 onDestinationsInserted_: function() { 503 onDestinationsInserted_: function() {
500 this.renderDestinations_(); 504 this.renderDestinations_();
501 this.reflowLists_(); 505 this.reflowLists_();
502 }, 506 },
503 507
504 /** 508 /**
509 * Called when destinations are inserted into the store. Rerenders
510 * destinations.
511 * @private
512 */
513 onDestinationSearchDone_: function() {
514 this.updateThrobbers_();
515 this.renderDestinations_();
516 this.reflowLists_();
517 },
518
519 /**
505 * Called when the manage cloud printers action is activated. 520 * Called when the manage cloud printers action is activated.
506 * @private 521 * @private
507 */ 522 */
508 onManageCloudDestinationsActivated_: function() { 523 onManageCloudDestinationsActivated_: function() {
509 cr.dispatchSimpleEvent( 524 cr.dispatchSimpleEvent(
510 this, 525 this,
511 print_preview.DestinationSearch.EventType.MANAGE_CLOUD_DESTINATIONS); 526 print_preview.DestinationSearch.EventType.MANAGE_CLOUD_DESTINATIONS);
512 }, 527 },
513 528
514 /** 529 /**
(...skipping 21 matching lines...) Expand all
536 * Called when item in the Accounts list is selected. Initiates active user 551 * Called when item in the Accounts list is selected. Initiates active user
537 * switch or, for 'Add account...' item, opens Google sign-in page. 552 * switch or, for 'Add account...' item, opens Google sign-in page.
538 * @private 553 * @private
539 */ 554 */
540 onAccountChange_: function() { 555 onAccountChange_: function() {
541 var accountSelectEl = this.getChildElement('.account-select'); 556 var accountSelectEl = this.getChildElement('.account-select');
542 var account = 557 var account =
543 accountSelectEl.options[accountSelectEl.selectedIndex].value; 558 accountSelectEl.options[accountSelectEl.selectedIndex].value;
544 if (account) { 559 if (account) {
545 this.userInfo_.activeUser = account; 560 this.userInfo_.activeUser = account;
561 this.destinationStore_.reloadUserCookieBasedDestinations();
546 } else { 562 } else {
547 cr.dispatchSimpleEvent(this, DestinationSearch.EventType.ADD_ACCOUNT); 563 cr.dispatchSimpleEvent(this, DestinationSearch.EventType.ADD_ACCOUNT);
548 // Set selection back to the active user. 564 // Set selection back to the active user.
549 for (var i = 0; i < accountSelectEl.options.length; i++) { 565 for (var i = 0; i < accountSelectEl.options.length; i++) {
550 if (accountSelectEl.options[i].value == this.userInfo_.activeUser) { 566 if (accountSelectEl.options[i].value == this.userInfo_.activeUser) {
551 accountSelectEl.selectedIndex = i; 567 accountSelectEl.selectedIndex = i;
552 break; 568 break;
553 } 569 }
554 } 570 }
555 } 571 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 onWindowResize_: function() { 614 onWindowResize_: function() {
599 this.reflowLists_(); 615 this.reflowLists_();
600 } 616 }
601 }; 617 };
602 618
603 // Export 619 // Export
604 return { 620 return {
605 DestinationSearch: DestinationSearch 621 DestinationSearch: DestinationSearch
606 }; 622 };
607 }); 623 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698