| Index: chrome/browser/resources/print_preview/search/destination_search.js
|
| diff --git a/chrome/browser/resources/print_preview/search/destination_search.js b/chrome/browser/resources/print_preview/search/destination_search.js
|
| index 1d54473586aed1e2c199f320bbc6520465d5a59e..387535cca2a4e99953dd24a691861166718dfae8 100644
|
| --- a/chrome/browser/resources/print_preview/search/destination_search.js
|
| +++ b/chrome/browser/resources/print_preview/search/destination_search.js
|
| @@ -12,12 +12,14 @@ cr.define('print_preview', function() {
|
| * the destination store.
|
| * @param {!print_preview.DestinationStore} destinationStore Data store
|
| * containing the destinations to search through.
|
| + * @param {!print_preview.InvitationStore} invitationStore Data store
|
| + * holding printer sharing invitations.
|
| * @param {!print_preview.UserInfo} userInfo Event target that contains
|
| * information about the logged in user.
|
| * @constructor
|
| * @extends {print_preview.Overlay}
|
| */
|
| - function DestinationSearch(destinationStore, userInfo) {
|
| + function DestinationSearch(destinationStore, invitationStore, userInfo) {
|
| print_preview.Overlay.call(this);
|
|
|
| /**
|
| @@ -28,6 +30,13 @@ cr.define('print_preview', function() {
|
| this.destinationStore_ = destinationStore;
|
|
|
| /**
|
| + * Data store holding printer sharing invitations.
|
| + * @type {!print_preview.DestinationStore}
|
| + * @private
|
| + */
|
| + this.invitationStore_ = invitationStore;
|
| +
|
| + /**
|
| * Event target that contains information about the logged in user.
|
| * @type {!print_preview.UserInfo}
|
| * @private
|
| @@ -35,6 +44,13 @@ cr.define('print_preview', function() {
|
| this.userInfo_ = userInfo;
|
|
|
| /**
|
| + * Currently displayed printer sharing invitation.
|
| + * @type {print_preview.Invitation}
|
| + * @private
|
| + */
|
| + this.invitation_ = null;
|
| +
|
| + /**
|
| * Used to record usage statistics.
|
| * @type {!print_preview.DestinationSearchMetricsContext}
|
| * @private
|
| @@ -138,6 +154,9 @@ cr.define('print_preview', function() {
|
| this.reflowLists_();
|
| this.metrics_.record(
|
| print_preview.Metrics.DestinationSearchBucket.DESTINATION_SHOWN);
|
| +
|
| + this.destinationStore_.startLoadAllDestinations();
|
| + this.invitationStore_.startLoadingInvitations();
|
| } else {
|
| // Collapse all destination lists
|
| this.localList_.setIsShowAll(false);
|
| @@ -177,6 +196,15 @@ cr.define('print_preview', function() {
|
| this.onSignInActivated_.bind(this));
|
|
|
| this.tracker.add(
|
| + this.getChildElement('.invitation-accept-button'),
|
| + 'click',
|
| + this.onInvitationProcessButtonClick_.bind(this, true /*accept*/));
|
| + this.tracker.add(
|
| + this.getChildElement('.invitation-reject-button'),
|
| + 'click',
|
| + this.onInvitationProcessButtonClick_.bind(this, false /*accept*/));
|
| +
|
| + this.tracker.add(
|
| this.getChildElement('.cloudprint-promo > .close-button'),
|
| 'click',
|
| this.onCloudprintPromoCloseButtonClick_.bind(this));
|
| @@ -214,6 +242,15 @@ cr.define('print_preview', function() {
|
| this.onDestinationSearchDone_.bind(this));
|
|
|
| this.tracker.add(
|
| + this.invitationStore_,
|
| + print_preview.InvitationStore.EventType.INVITATION_SEARCH_DONE,
|
| + this.updateInvitations_.bind(this));
|
| + this.tracker.add(
|
| + this.invitationStore_,
|
| + print_preview.InvitationStore.EventType.INVITATION_PROCESSED,
|
| + this.updateInvitations_.bind(this));
|
| +
|
| + this.tracker.add(
|
| this.localList_,
|
| print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED,
|
| this.onManageLocalDestinationsActivated_.bind(this));
|
| @@ -259,6 +296,7 @@ cr.define('print_preview', function() {
|
| parseInt(elStyle.getPropertyValue('padding-top')) -
|
| parseInt(elStyle.getPropertyValue('padding-bottom')) -
|
| this.getChildElement('.lists').offsetTop -
|
| + this.getChildElement('.invitation-container').offsetHeight -
|
| this.getChildElement('.cloudprint-promo').offsetHeight;
|
| },
|
|
|
| @@ -414,6 +452,55 @@ cr.define('print_preview', function() {
|
| },
|
|
|
| /**
|
| + * Updates printer sharing invitations UI.
|
| + * @private
|
| + */
|
| + updateInvitations_: function() {
|
| + var invitations = this.userInfo_.activeUser ?
|
| + this.invitationStore_.invitations(this.userInfo_.activeUser) : [];
|
| + if (invitations.length > 0) {
|
| + this.invitation_ = invitations[0];
|
| + this.showInvitation_(this.invitation_);
|
| + } else {
|
| + this.invitation_ = null;
|
| + }
|
| + setIsVisible(
|
| + this.getChildElement('.invitation-container'), !!this.invitation_);
|
| + this.reflowLists_();
|
| + },
|
| +
|
| + /**
|
| + * @param {!printe_preview.Invitation} invitation Invitation to show.
|
| + * @private
|
| + */
|
| + showInvitation_: function(invitation) {
|
| + var invitationText = '';
|
| + if (invitation.asGroupManager) {
|
| + invitationText = localStrings.getStringF(
|
| + 'groupPrinterSharingInviteText',
|
| + invitation.sender,
|
| + invitation.destination.displayName,
|
| + invitation.receiver);
|
| + } else {
|
| + invitationText = localStrings.getStringF(
|
| + 'printerSharingInviteText',
|
| + invitation.sender,
|
| + invitation.destination.displayName);
|
| + }
|
| + this.getChildElement('.invitation-text').innerHTML = invitationText;
|
| +
|
| + var acceptButton = this.getChildElement('.invitation-accept-button');
|
| + acceptButton.textContent = localStrings.getString(
|
| + invitation.asGroupManager ? 'acceptForGroup' : 'accept');
|
| + acceptButton.disabled = !!this.invitationStore_.invitationInProgress;
|
| + this.getChildElement('.invitation-reject-button').disabled =
|
| + !!this.invitationStore_.invitationInProgress;
|
| + setIsVisible(
|
| + this.getChildElement('#invitation-process-throbber'),
|
| + !!this.invitationStore_.invitationInProgress);
|
| + },
|
| +
|
| + /**
|
| * Called when user's logged in accounts change. Updates the UI.
|
| * @private
|
| */
|
| @@ -440,7 +527,7 @@ cr.define('print_preview', function() {
|
| setIsVisible(this.getChildElement('.user-info'), loggedIn);
|
| setIsVisible(this.getChildElement('.cloud-list'), loggedIn);
|
| setIsVisible(this.getChildElement('.cloudprint-promo'), !loggedIn);
|
| - this.reflowLists_();
|
| + this.updateInvitations_();
|
| },
|
|
|
| /**
|
| @@ -503,6 +590,9 @@ cr.define('print_preview', function() {
|
| this.updateThrobbers_();
|
| this.renderDestinations_();
|
| this.reflowLists_();
|
| + // In case user account information was retrieved with this search
|
| + // (knowing current user account is required to fetch invitations).
|
| + this.invitationStore_.startLoadingInvitations();
|
| },
|
|
|
| /**
|
| @@ -548,6 +638,7 @@ cr.define('print_preview', function() {
|
| if (account) {
|
| this.userInfo_.activeUser = account;
|
| this.destinationStore_.reloadUserCookieBasedDestinations();
|
| + this.invitationStore_.startLoadingInvitations();
|
| this.metrics_.record(
|
| print_preview.Metrics.DestinationSearchBucket.ACCOUNT_CHANGED);
|
| } else {
|
| @@ -565,6 +656,16 @@ cr.define('print_preview', function() {
|
| },
|
|
|
| /**
|
| + * Called when the printer sharing invitation Accept/Reject button is
|
| + * clicked.
|
| + * @private
|
| + */
|
| + onInvitationProcessButtonClick_: function(accept) {
|
| + this.invitationStore_.processInvitation(this.invitation_, accept);
|
| + this.updateInvitations_();
|
| + },
|
| +
|
| + /**
|
| * Called when the close button on the cloud print promo is clicked. Hides
|
| * the promo.
|
| * @private
|
|
|