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

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

Issue 587013003: Add Print Preview UI to accept and reject printer sharing invitations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
11 * destination to print to. When a destination is selected, it is written to 11 * destination to print to. When a destination is selected, it is written to
12 * the destination store. 12 * the destination store.
13 * @param {!print_preview.DestinationStore} destinationStore Data store 13 * @param {!print_preview.DestinationStore} destinationStore Data store
14 * containing the destinations to search through. 14 * containing the destinations to search through.
15 * @param {!print_preview.InvitationStore} invitationStore Data store
16 * holding printer sharing invitations.
15 * @param {!print_preview.UserInfo} userInfo Event target that contains 17 * @param {!print_preview.UserInfo} userInfo Event target that contains
16 * information about the logged in user. 18 * information about the logged in user.
17 * @constructor 19 * @constructor
18 * @extends {print_preview.Overlay} 20 * @extends {print_preview.Overlay}
19 */ 21 */
20 function DestinationSearch(destinationStore, userInfo) { 22 function DestinationSearch(destinationStore, invitationStore, userInfo) {
21 print_preview.Overlay.call(this); 23 print_preview.Overlay.call(this);
22 24
23 /** 25 /**
24 * Data store containing the destinations to search through. 26 * Data store containing the destinations to search through.
25 * @type {!print_preview.DestinationStore} 27 * @type {!print_preview.DestinationStore}
26 * @private 28 * @private
27 */ 29 */
28 this.destinationStore_ = destinationStore; 30 this.destinationStore_ = destinationStore;
29 31
30 /** 32 /**
33 * Data store holding printer sharing invitations.
34 * @type {!print_preview.DestinationStore}
35 * @private
36 */
37 this.invitationStore_ = invitationStore;
38
39 /**
31 * Event target that contains information about the logged in user. 40 * Event target that contains information about the logged in user.
32 * @type {!print_preview.UserInfo} 41 * @type {!print_preview.UserInfo}
33 * @private 42 * @private
34 */ 43 */
35 this.userInfo_ = userInfo; 44 this.userInfo_ = userInfo;
36 45
37 /** 46 /**
47 * Currently displayed printer sharing invitation.
48 * @type {print_preview.Invitation}
49 * @private
50 */
51 this.invitation_ = null;
52
53 /**
38 * Used to record usage statistics. 54 * Used to record usage statistics.
39 * @type {!print_preview.DestinationSearchMetricsContext} 55 * @type {!print_preview.DestinationSearchMetricsContext}
40 * @private 56 * @private
41 */ 57 */
42 this.metrics_ = new print_preview.DestinationSearchMetricsContext(); 58 this.metrics_ = new print_preview.DestinationSearchMetricsContext();
43 59
44 /** 60 /**
45 * 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
46 * already recorded. 62 * already recorded.
47 * @type {boolean} 63 * @type {boolean}
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 this.searchBox_.focus(); 147 this.searchBox_.focus();
132 if (getIsVisible(this.getChildElement('.cloudprint-promo'))) { 148 if (getIsVisible(this.getChildElement('.cloudprint-promo'))) {
133 this.metrics_.record( 149 this.metrics_.record(
134 print_preview.Metrics.DestinationSearchBucket.SIGNIN_PROMPT); 150 print_preview.Metrics.DestinationSearchBucket.SIGNIN_PROMPT);
135 } 151 }
136 if (this.userInfo_.initialized) 152 if (this.userInfo_.initialized)
137 this.onUsersChanged_(); 153 this.onUsersChanged_();
138 this.reflowLists_(); 154 this.reflowLists_();
139 this.metrics_.record( 155 this.metrics_.record(
140 print_preview.Metrics.DestinationSearchBucket.DESTINATION_SHOWN); 156 print_preview.Metrics.DestinationSearchBucket.DESTINATION_SHOWN);
157
158 this.destinationStore_.startLoadAllDestinations();
159 this.invitationStore_.startLoadingInvitations();
141 } else { 160 } else {
142 // Collapse all destination lists 161 // Collapse all destination lists
143 this.localList_.setIsShowAll(false); 162 this.localList_.setIsShowAll(false);
144 this.cloudList_.setIsShowAll(false); 163 this.cloudList_.setIsShowAll(false);
145 this.resetSearch_(); 164 this.resetSearch_();
146 } 165 }
147 }, 166 },
148 167
149 /** @override */ 168 /** @override */
150 onCancelInternal: function() { 169 onCancelInternal: function() {
(...skipping 19 matching lines...) Expand all
170 this.getChildElement('.account-select'), 189 this.getChildElement('.account-select'),
171 'change', 190 'change',
172 this.onAccountChange_.bind(this)); 191 this.onAccountChange_.bind(this));
173 192
174 this.tracker.add( 193 this.tracker.add(
175 this.getChildElement('.sign-in'), 194 this.getChildElement('.sign-in'),
176 'click', 195 'click',
177 this.onSignInActivated_.bind(this)); 196 this.onSignInActivated_.bind(this));
178 197
179 this.tracker.add( 198 this.tracker.add(
199 this.getChildElement('.invitation-accept-button'),
200 'click',
201 this.onInvitationProcessButtonClick_.bind(this, true /*accept*/));
202 this.tracker.add(
203 this.getChildElement('.invitation-reject-button'),
204 'click',
205 this.onInvitationProcessButtonClick_.bind(this, false /*accept*/));
206
207 this.tracker.add(
180 this.getChildElement('.cloudprint-promo > .close-button'), 208 this.getChildElement('.cloudprint-promo > .close-button'),
181 'click', 209 'click',
182 this.onCloudprintPromoCloseButtonClick_.bind(this)); 210 this.onCloudprintPromoCloseButtonClick_.bind(this));
183 this.tracker.add( 211 this.tracker.add(
184 this.searchBox_, 212 this.searchBox_,
185 print_preview.SearchBox.EventType.SEARCH, 213 print_preview.SearchBox.EventType.SEARCH,
186 this.onSearch_.bind(this)); 214 this.onSearch_.bind(this));
187 this.tracker.add( 215 this.tracker.add(
188 this, 216 this,
189 print_preview.DestinationListItem.EventType.SELECT, 217 print_preview.DestinationListItem.EventType.SELECT,
(...skipping 17 matching lines...) Expand all
207 this.tracker.add( 235 this.tracker.add(
208 this.destinationStore_, 236 this.destinationStore_,
209 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_STARTED, 237 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_STARTED,
210 this.updateThrobbers_.bind(this)); 238 this.updateThrobbers_.bind(this));
211 this.tracker.add( 239 this.tracker.add(
212 this.destinationStore_, 240 this.destinationStore_,
213 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE, 241 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE,
214 this.onDestinationSearchDone_.bind(this)); 242 this.onDestinationSearchDone_.bind(this));
215 243
216 this.tracker.add( 244 this.tracker.add(
245 this.invitationStore_,
246 print_preview.InvitationStore.EventType.INVITATION_SEARCH_DONE,
247 this.updateInvitations_.bind(this));
248 this.tracker.add(
249 this.invitationStore_,
250 print_preview.InvitationStore.EventType.INVITATION_PROCESSED,
251 this.updateInvitations_.bind(this));
252
253 this.tracker.add(
217 this.localList_, 254 this.localList_,
218 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, 255 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED,
219 this.onManageLocalDestinationsActivated_.bind(this)); 256 this.onManageLocalDestinationsActivated_.bind(this));
220 this.tracker.add( 257 this.tracker.add(
221 this.cloudList_, 258 this.cloudList_,
222 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, 259 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED,
223 this.onManageCloudDestinationsActivated_.bind(this)); 260 this.onManageCloudDestinationsActivated_.bind(this));
224 261
225 this.tracker.add( 262 this.tracker.add(
226 this.userInfo_, 263 this.userInfo_,
(...skipping 25 matching lines...) Expand all
252 /** 289 /**
253 * @return {number} Height available for destination lists, in pixels. 290 * @return {number} Height available for destination lists, in pixels.
254 * @private 291 * @private
255 */ 292 */
256 getAvailableListsHeight_: function() { 293 getAvailableListsHeight_: function() {
257 var elStyle = window.getComputedStyle(this.getElement()); 294 var elStyle = window.getComputedStyle(this.getElement());
258 return this.getElement().offsetHeight - 295 return this.getElement().offsetHeight -
259 parseInt(elStyle.getPropertyValue('padding-top')) - 296 parseInt(elStyle.getPropertyValue('padding-top')) -
260 parseInt(elStyle.getPropertyValue('padding-bottom')) - 297 parseInt(elStyle.getPropertyValue('padding-bottom')) -
261 this.getChildElement('.lists').offsetTop - 298 this.getChildElement('.lists').offsetTop -
299 this.getChildElement('.invitation-container').offsetHeight -
262 this.getChildElement('.cloudprint-promo').offsetHeight; 300 this.getChildElement('.cloudprint-promo').offsetHeight;
263 }, 301 },
264 302
265 /** 303 /**
266 * Filters all destination lists with the given query. 304 * Filters all destination lists with the given query.
267 * @param {RegExp} query Query to filter destination lists by. 305 * @param {RegExp} query Query to filter destination lists by.
268 * @private 306 * @private
269 */ 307 */
270 filterLists_: function(query) { 308 filterLists_: function(query) {
271 this.recentList_.updateSearchQuery(query); 309 this.recentList_.updateSearchQuery(query);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 this.destinationStore_.isLocalDestinationSearchInProgress); 445 this.destinationStore_.isLocalDestinationSearchInProgress);
408 this.cloudList_.setIsThrobberVisible( 446 this.cloudList_.setIsThrobberVisible(
409 this.destinationStore_.isCloudDestinationSearchInProgress); 447 this.destinationStore_.isCloudDestinationSearchInProgress);
410 this.recentList_.setIsThrobberVisible( 448 this.recentList_.setIsThrobberVisible(
411 this.destinationStore_.isLocalDestinationSearchInProgress && 449 this.destinationStore_.isLocalDestinationSearchInProgress &&
412 this.destinationStore_.isCloudDestinationSearchInProgress); 450 this.destinationStore_.isCloudDestinationSearchInProgress);
413 this.reflowLists_(); 451 this.reflowLists_();
414 }, 452 },
415 453
416 /** 454 /**
455 * Updates printer sharing invitations UI.
456 * @private
457 */
458 updateInvitations_: function() {
459 var invitations = this.userInfo_.activeUser ?
460 this.invitationStore_.invitations(this.userInfo_.activeUser) : [];
461 if (invitations.length > 0) {
462 this.invitation_ = invitations[0];
463 this.showInvitation_(this.invitation_);
464 } else {
465 this.invitation_ = null;
466 }
467 setIsVisible(
468 this.getChildElement('.invitation-container'), !!this.invitation_);
469 this.reflowLists_();
470 },
471
472 /**
473 * @param {!printe_preview.Invitation} invitation Invitation to show.
474 * @private
475 */
476 showInvitation_: function(invitation) {
477 var invitationText = '';
478 if (invitation.asGroupManager) {
479 invitationText = localStrings.getStringF(
480 'groupPrinterSharingInviteText',
481 invitation.sender,
482 invitation.destination.displayName,
483 invitation.receiver);
484 } else {
485 invitationText = localStrings.getStringF(
486 'printerSharingInviteText',
487 invitation.sender,
488 invitation.destination.displayName);
489 }
490 this.getChildElement('.invitation-text').innerHTML = invitationText;
491
492 var acceptButton = this.getChildElement('.invitation-accept-button');
493 acceptButton.textContent = localStrings.getString(
494 invitation.asGroupManager ? 'acceptForGroup' : 'accept');
495 acceptButton.disabled = !!this.invitationStore_.invitationInProgress;
496 this.getChildElement('.invitation-reject-button').disabled =
497 !!this.invitationStore_.invitationInProgress;
498 setIsVisible(
499 this.getChildElement('#invitation-process-throbber'),
500 !!this.invitationStore_.invitationInProgress);
501 },
502
503 /**
417 * Called when user's logged in accounts change. Updates the UI. 504 * Called when user's logged in accounts change. Updates the UI.
418 * @private 505 * @private
419 */ 506 */
420 onUsersChanged_: function() { 507 onUsersChanged_: function() {
421 var loggedIn = this.userInfo_.loggedIn; 508 var loggedIn = this.userInfo_.loggedIn;
422 if (loggedIn) { 509 if (loggedIn) {
423 var accountSelectEl = this.getChildElement('.account-select'); 510 var accountSelectEl = this.getChildElement('.account-select');
424 accountSelectEl.innerHTML = ''; 511 accountSelectEl.innerHTML = '';
425 this.userInfo_.users.forEach(function(account) { 512 this.userInfo_.users.forEach(function(account) {
426 var option = document.createElement('option'); 513 var option = document.createElement('option');
427 option.text = account; 514 option.text = account;
428 option.value = account; 515 option.value = account;
429 accountSelectEl.add(option); 516 accountSelectEl.add(option);
430 }); 517 });
431 var option = document.createElement('option'); 518 var option = document.createElement('option');
432 option.text = localStrings.getString('addAccountTitle'); 519 option.text = localStrings.getString('addAccountTitle');
433 option.value = ''; 520 option.value = '';
434 accountSelectEl.add(option); 521 accountSelectEl.add(option);
435 522
436 accountSelectEl.selectedIndex = 523 accountSelectEl.selectedIndex =
437 this.userInfo_.users.indexOf(this.userInfo_.activeUser); 524 this.userInfo_.users.indexOf(this.userInfo_.activeUser);
438 } 525 }
439 526
440 setIsVisible(this.getChildElement('.user-info'), loggedIn); 527 setIsVisible(this.getChildElement('.user-info'), loggedIn);
441 setIsVisible(this.getChildElement('.cloud-list'), loggedIn); 528 setIsVisible(this.getChildElement('.cloud-list'), loggedIn);
442 setIsVisible(this.getChildElement('.cloudprint-promo'), !loggedIn); 529 setIsVisible(this.getChildElement('.cloudprint-promo'), !loggedIn);
443 this.reflowLists_(); 530 this.updateInvitations_();
444 }, 531 },
445 532
446 /** 533 /**
447 * Called when a destination search should be executed. Filters the 534 * Called when a destination search should be executed. Filters the
448 * destination lists with the given query. 535 * destination lists with the given query.
449 * @param {Event} evt Contains the search query. 536 * @param {Event} evt Contains the search query.
450 * @private 537 * @private
451 */ 538 */
452 onSearch_: function(evt) { 539 onSearch_: function(evt) {
453 this.filterLists_(evt.queryRegExp); 540 this.filterLists_(evt.queryRegExp);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 583
497 /** 584 /**
498 * Called when destinations are inserted into the store. Rerenders 585 * Called when destinations are inserted into the store. Rerenders
499 * destinations. 586 * destinations.
500 * @private 587 * @private
501 */ 588 */
502 onDestinationSearchDone_: function() { 589 onDestinationSearchDone_: function() {
503 this.updateThrobbers_(); 590 this.updateThrobbers_();
504 this.renderDestinations_(); 591 this.renderDestinations_();
505 this.reflowLists_(); 592 this.reflowLists_();
593 // In case user account information was retrieved with this search
594 // (knowing current user account is required to fetch invitations).
595 this.invitationStore_.startLoadingInvitations();
506 }, 596 },
507 597
508 /** 598 /**
509 * Called when the manage cloud printers action is activated. 599 * Called when the manage cloud printers action is activated.
510 * @private 600 * @private
511 */ 601 */
512 onManageCloudDestinationsActivated_: function() { 602 onManageCloudDestinationsActivated_: function() {
513 cr.dispatchSimpleEvent( 603 cr.dispatchSimpleEvent(
514 this, 604 this,
515 print_preview.DestinationSearch.EventType.MANAGE_CLOUD_DESTINATIONS); 605 print_preview.DestinationSearch.EventType.MANAGE_CLOUD_DESTINATIONS);
(...skipping 25 matching lines...) Expand all
541 * switch or, for 'Add account...' item, opens Google sign-in page. 631 * switch or, for 'Add account...' item, opens Google sign-in page.
542 * @private 632 * @private
543 */ 633 */
544 onAccountChange_: function() { 634 onAccountChange_: function() {
545 var accountSelectEl = this.getChildElement('.account-select'); 635 var accountSelectEl = this.getChildElement('.account-select');
546 var account = 636 var account =
547 accountSelectEl.options[accountSelectEl.selectedIndex].value; 637 accountSelectEl.options[accountSelectEl.selectedIndex].value;
548 if (account) { 638 if (account) {
549 this.userInfo_.activeUser = account; 639 this.userInfo_.activeUser = account;
550 this.destinationStore_.reloadUserCookieBasedDestinations(); 640 this.destinationStore_.reloadUserCookieBasedDestinations();
641 this.invitationStore_.startLoadingInvitations();
551 this.metrics_.record( 642 this.metrics_.record(
552 print_preview.Metrics.DestinationSearchBucket.ACCOUNT_CHANGED); 643 print_preview.Metrics.DestinationSearchBucket.ACCOUNT_CHANGED);
553 } else { 644 } else {
554 cr.dispatchSimpleEvent(this, DestinationSearch.EventType.ADD_ACCOUNT); 645 cr.dispatchSimpleEvent(this, DestinationSearch.EventType.ADD_ACCOUNT);
555 // Set selection back to the active user. 646 // Set selection back to the active user.
556 for (var i = 0; i < accountSelectEl.options.length; i++) { 647 for (var i = 0; i < accountSelectEl.options.length; i++) {
557 if (accountSelectEl.options[i].value == this.userInfo_.activeUser) { 648 if (accountSelectEl.options[i].value == this.userInfo_.activeUser) {
558 accountSelectEl.selectedIndex = i; 649 accountSelectEl.selectedIndex = i;
559 break; 650 break;
560 } 651 }
561 } 652 }
562 this.metrics_.record( 653 this.metrics_.record(
563 print_preview.Metrics.DestinationSearchBucket.ADD_ACCOUNT_SELECTED); 654 print_preview.Metrics.DestinationSearchBucket.ADD_ACCOUNT_SELECTED);
564 } 655 }
565 }, 656 },
566 657
567 /** 658 /**
659 * Called when the printer sharing invitation Accept/Reject button is
660 * clicked.
661 * @private
662 */
663 onInvitationProcessButtonClick_: function(accept) {
664 this.invitationStore_.processInvitation(this.invitation_, accept);
665 this.updateInvitations_();
666 },
667
668 /**
568 * Called when the close button on the cloud print promo is clicked. Hides 669 * Called when the close button on the cloud print promo is clicked. Hides
569 * the promo. 670 * the promo.
570 * @private 671 * @private
571 */ 672 */
572 onCloudprintPromoCloseButtonClick_: function() { 673 onCloudprintPromoCloseButtonClick_: function() {
573 setIsVisible(this.getChildElement('.cloudprint-promo'), false); 674 setIsVisible(this.getChildElement('.cloudprint-promo'), false);
574 }, 675 },
575 676
576 /** 677 /**
577 * Called when the window is resized. Reflows layout of destination lists. 678 * Called when the window is resized. Reflows layout of destination lists.
578 * @private 679 * @private
579 */ 680 */
580 onWindowResize_: function() { 681 onWindowResize_: function() {
581 this.reflowLists_(); 682 this.reflowLists_();
582 } 683 }
583 }; 684 };
584 685
585 // Export 686 // Export
586 return { 687 return {
587 DestinationSearch: DestinationSearch 688 DestinationSearch: DestinationSearch
588 }; 689 };
589 }); 690 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698