| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 */ | 89 */ |
| 90 this.recentList_ = new print_preview.RecentDestinationList(this); | 90 this.recentList_ = new print_preview.RecentDestinationList(this); |
| 91 this.addChild(this.recentList_); | 91 this.addChild(this.recentList_); |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * Destination list containing local destinations. | 94 * Destination list containing local destinations. |
| 95 * @type {!print_preview.DestinationList} | 95 * @type {!print_preview.DestinationList} |
| 96 * @private | 96 * @private |
| 97 */ | 97 */ |
| 98 this.localList_ = new print_preview.DestinationList( | 98 this.localList_ = new print_preview.DestinationList( |
| 99 this, | 99 this, loadTimeData.getString('localDestinationsTitle'), |
| 100 loadTimeData.getString('localDestinationsTitle'), | |
| 101 loadTimeData.getBoolean('showLocalManageButton') ? | 100 loadTimeData.getBoolean('showLocalManageButton') ? |
| 102 loadTimeData.getString('manage') : null); | 101 loadTimeData.getString('manage') : |
| 102 null); |
| 103 this.addChild(this.localList_); | 103 this.addChild(this.localList_); |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * Destination list containing cloud destinations. | 106 * Destination list containing cloud destinations. |
| 107 * @type {!print_preview.DestinationList} | 107 * @type {!print_preview.DestinationList} |
| 108 * @private | 108 * @private |
| 109 */ | 109 */ |
| 110 this.cloudList_ = new print_preview.CloudDestinationList(this); | 110 this.cloudList_ = new print_preview.CloudDestinationList(this); |
| 111 this.addChild(this.cloudList_); | 111 this.addChild(this.cloudList_); |
| 112 }; | 112 }; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 this.localList_.setIsShowAll(false); | 166 this.localList_.setIsShowAll(false); |
| 167 this.cloudList_.setIsShowAll(false); | 167 this.cloudList_.setIsShowAll(false); |
| 168 if (this.provisionalDestinationResolver_) | 168 if (this.provisionalDestinationResolver_) |
| 169 this.provisionalDestinationResolver_.cancel(); | 169 this.provisionalDestinationResolver_.cancel(); |
| 170 this.resetSearch_(); | 170 this.resetSearch_(); |
| 171 } | 171 } |
| 172 }, | 172 }, |
| 173 | 173 |
| 174 /** @override */ | 174 /** @override */ |
| 175 onCancelInternal: function() { | 175 onCancelInternal: function() { |
| 176 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. | 176 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket |
| 177 DESTINATION_CLOSED_UNCHANGED); | 177 .DESTINATION_CLOSED_UNCHANGED); |
| 178 }, | 178 }, |
| 179 | 179 |
| 180 /** Shows the Google Cloud Print promotion banner. */ | 180 /** Shows the Google Cloud Print promotion banner. */ |
| 181 showCloudPrintPromo: function() { | 181 showCloudPrintPromo: function() { |
| 182 setIsVisible(this.getChildElement('.cloudprint-promo'), true); | 182 setIsVisible(this.getChildElement('.cloudprint-promo'), true); |
| 183 if (this.getIsVisible()) { | 183 if (this.getIsVisible()) { |
| 184 this.metrics_.record( | 184 this.metrics_.record( |
| 185 print_preview.Metrics.DestinationSearchBucket.SIGNIN_PROMPT); | 185 print_preview.Metrics.DestinationSearchBucket.SIGNIN_PROMPT); |
| 186 chrome.send( | 186 chrome.send( |
| 187 'metricsHandler:recordAction', | 187 'metricsHandler:recordAction', |
| 188 ['Signin_Impression_FromCloudPrint']); | 188 ['Signin_Impression_FromCloudPrint']); |
| 189 } | 189 } |
| 190 this.reflowLists_(); | 190 this.reflowLists_(); |
| 191 }, | 191 }, |
| 192 | 192 |
| 193 /** @override */ | 193 /** @override */ |
| 194 enterDocument: function() { | 194 enterDocument: function() { |
| 195 print_preview.Overlay.prototype.enterDocument.call(this); | 195 print_preview.Overlay.prototype.enterDocument.call(this); |
| 196 | 196 |
| 197 this.tracker.add( | 197 this.tracker.add( |
| 198 this.getChildElement('.account-select'), | 198 this.getChildElement('.account-select'), 'change', |
| 199 'change', | |
| 200 this.onAccountChange_.bind(this)); | 199 this.onAccountChange_.bind(this)); |
| 201 | 200 |
| 202 this.tracker.add( | 201 this.tracker.add( |
| 203 this.getChildElement('.sign-in'), | 202 this.getChildElement('.sign-in'), 'click', |
| 204 'click', | |
| 205 this.onSignInActivated_.bind(this)); | 203 this.onSignInActivated_.bind(this)); |
| 206 | 204 |
| 207 this.tracker.add( | 205 this.tracker.add( |
| 208 this.getChildElement('.invitation-accept-button'), | 206 this.getChildElement('.invitation-accept-button'), 'click', |
| 209 'click', | |
| 210 this.onInvitationProcessButtonClick_.bind(this, true /*accept*/)); | 207 this.onInvitationProcessButtonClick_.bind(this, true /*accept*/)); |
| 211 this.tracker.add( | 208 this.tracker.add( |
| 212 this.getChildElement('.invitation-reject-button'), | 209 this.getChildElement('.invitation-reject-button'), 'click', |
| 213 'click', | |
| 214 this.onInvitationProcessButtonClick_.bind(this, false /*accept*/)); | 210 this.onInvitationProcessButtonClick_.bind(this, false /*accept*/)); |
| 215 | 211 |
| 216 this.tracker.add( | 212 this.tracker.add( |
| 217 this.getChildElement('.cloudprint-promo > .close-button'), | 213 this.getChildElement('.cloudprint-promo > .close-button'), 'click', |
| 218 'click', | |
| 219 this.onCloudprintPromoCloseButtonClick_.bind(this)); | 214 this.onCloudprintPromoCloseButtonClick_.bind(this)); |
| 220 this.tracker.add( | 215 this.tracker.add( |
| 221 this.searchBox_, | 216 this.searchBox_, print_preview.SearchBox.EventType.SEARCH, |
| 222 print_preview.SearchBox.EventType.SEARCH, | |
| 223 this.onSearch_.bind(this)); | 217 this.onSearch_.bind(this)); |
| 224 this.tracker.add( | 218 this.tracker.add( |
| 225 this, | 219 this, print_preview.DestinationListItem.EventType.SELECT, |
| 226 print_preview.DestinationListItem.EventType.SELECT, | |
| 227 this.onDestinationSelect_.bind(this)); | 220 this.onDestinationSelect_.bind(this)); |
| 228 this.tracker.add( | 221 this.tracker.add( |
| 229 this, | 222 this, |
| 230 print_preview.DestinationListItem.EventType.REGISTER_PROMO_CLICKED, | 223 print_preview.DestinationListItem.EventType.REGISTER_PROMO_CLICKED, |
| 231 function() { | 224 function() { |
| 232 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. | 225 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket |
| 233 REGISTER_PROMO_SELECTED); | 226 .REGISTER_PROMO_SELECTED); |
| 234 }.bind(this)); | 227 }.bind(this)); |
| 235 | 228 |
| 236 this.tracker.add( | 229 this.tracker.add( |
| 237 this.destinationStore_, | 230 this.destinationStore_, |
| 238 print_preview.DestinationStore.EventType.DESTINATIONS_INSERTED, | 231 print_preview.DestinationStore.EventType.DESTINATIONS_INSERTED, |
| 239 this.onDestinationsInserted_.bind(this)); | 232 this.onDestinationsInserted_.bind(this)); |
| 240 this.tracker.add( | 233 this.tracker.add( |
| 241 this.destinationStore_, | 234 this.destinationStore_, |
| 242 print_preview.DestinationStore.EventType.DESTINATION_SELECT, | 235 print_preview.DestinationStore.EventType.DESTINATION_SELECT, |
| 243 this.onDestinationStoreSelect_.bind(this)); | 236 this.onDestinationStoreSelect_.bind(this)); |
| 244 this.tracker.add( | 237 this.tracker.add( |
| 245 this.destinationStore_, | 238 this.destinationStore_, |
| 246 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_STARTED, | 239 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_STARTED, |
| 247 this.updateThrobbers_.bind(this)); | 240 this.updateThrobbers_.bind(this)); |
| 248 this.tracker.add( | 241 this.tracker.add( |
| 249 this.destinationStore_, | 242 this.destinationStore_, |
| 250 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE, | 243 print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE, |
| 251 this.onDestinationSearchDone_.bind(this)); | 244 this.onDestinationSearchDone_.bind(this)); |
| 252 this.tracker.add( | 245 this.tracker.add( |
| 253 this.destinationStore_, | 246 this.destinationStore_, print_preview.DestinationStore.EventType |
| 254 print_preview.DestinationStore.EventType | 247 .PROVISIONAL_DESTINATION_RESOLVED, |
| 255 .PROVISIONAL_DESTINATION_RESOLVED, | |
| 256 this.onDestinationsInserted_.bind(this)); | 248 this.onDestinationsInserted_.bind(this)); |
| 257 | 249 |
| 258 this.tracker.add( | 250 this.tracker.add( |
| 259 this.invitationStore_, | 251 this.invitationStore_, |
| 260 print_preview.InvitationStore.EventType.INVITATION_SEARCH_DONE, | 252 print_preview.InvitationStore.EventType.INVITATION_SEARCH_DONE, |
| 261 this.updateInvitations_.bind(this)); | 253 this.updateInvitations_.bind(this)); |
| 262 this.tracker.add( | 254 this.tracker.add( |
| 263 this.invitationStore_, | 255 this.invitationStore_, |
| 264 print_preview.InvitationStore.EventType.INVITATION_PROCESSED, | 256 print_preview.InvitationStore.EventType.INVITATION_PROCESSED, |
| 265 this.updateInvitations_.bind(this)); | 257 this.updateInvitations_.bind(this)); |
| 266 | 258 |
| 267 this.tracker.add( | 259 this.tracker.add( |
| 268 this.localList_, | 260 this.localList_, |
| 269 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, | 261 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, |
| 270 this.onManageLocalDestinationsActivated_.bind(this)); | 262 this.onManageLocalDestinationsActivated_.bind(this)); |
| 271 this.tracker.add( | 263 this.tracker.add( |
| 272 this.cloudList_, | 264 this.cloudList_, |
| 273 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, | 265 print_preview.DestinationList.EventType.ACTION_LINK_ACTIVATED, |
| 274 this.onManageCloudDestinationsActivated_.bind(this)); | 266 this.onManageCloudDestinationsActivated_.bind(this)); |
| 275 | 267 |
| 276 this.tracker.add( | 268 this.tracker.add( |
| 277 this.userInfo_, | 269 this.userInfo_, print_preview.UserInfo.EventType.USERS_CHANGED, |
| 278 print_preview.UserInfo.EventType.USERS_CHANGED, | |
| 279 this.onUsersChanged_.bind(this)); | 270 this.onUsersChanged_.bind(this)); |
| 280 | 271 |
| 281 this.tracker.add( | 272 this.tracker.add( |
| 282 this.getChildElement('.button-strip .cancel-button'), | 273 this.getChildElement('.button-strip .cancel-button'), 'click', |
| 283 'click', | |
| 284 this.cancel.bind(this)); | 274 this.cancel.bind(this)); |
| 285 | 275 |
| 286 this.tracker.add(window, 'resize', this.onWindowResize_.bind(this)); | 276 this.tracker.add(window, 'resize', this.onWindowResize_.bind(this)); |
| 287 | 277 |
| 288 this.updateThrobbers_(); | 278 this.updateThrobbers_(); |
| 289 | 279 |
| 290 // Render any destinations already in the store. | 280 // Render any destinations already in the store. |
| 291 this.renderDestinations_(); | 281 this.renderDestinations_(); |
| 292 }, | 282 }, |
| 293 | 283 |
| 294 /** @override */ | 284 /** @override */ |
| 295 decorateInternal: function() { | 285 decorateInternal: function() { |
| 296 this.searchBox_.render(this.getChildElement('.search-box-container')); | 286 this.searchBox_.render(this.getChildElement('.search-box-container')); |
| 297 this.recentList_.render(this.getChildElement('.recent-list')); | 287 this.recentList_.render(this.getChildElement('.recent-list')); |
| 298 this.localList_.render(this.getChildElement('.local-list')); | 288 this.localList_.render(this.getChildElement('.local-list')); |
| 299 this.cloudList_.render(this.getChildElement('.cloud-list')); | 289 this.cloudList_.render(this.getChildElement('.cloud-list')); |
| 300 this.getChildElement('.promo-text').innerHTML = loadTimeData.getStringF( | 290 this.getChildElement('.promo-text').innerHTML = loadTimeData.getStringF( |
| 301 'cloudPrintPromotion', | 291 'cloudPrintPromotion', '<a is="action-link" class="sign-in">', |
| 302 '<a is="action-link" class="sign-in">', | |
| 303 '</a>'); | 292 '</a>'); |
| 304 this.getChildElement('.account-select-label').textContent = | 293 this.getChildElement('.account-select-label').textContent = |
| 305 loadTimeData.getString('accountSelectTitle'); | 294 loadTimeData.getString('accountSelectTitle'); |
| 306 }, | 295 }, |
| 307 | 296 |
| 308 /** | 297 /** |
| 309 * @return {number} Height available for destination lists, in pixels. | 298 * @return {number} Height available for destination lists, in pixels. |
| 310 * @private | 299 * @private |
| 311 */ | 300 */ |
| 312 getAvailableListsHeight_: function() { | 301 getAvailableListsHeight_: function() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 this.destinationStore_.destinations(this.userInfo_.activeUser); | 343 this.destinationStore_.destinations(this.userInfo_.activeUser); |
| 355 destinations.forEach(function(destination) { | 344 destinations.forEach(function(destination) { |
| 356 if (destination.isRecent) { | 345 if (destination.isRecent) { |
| 357 recentDestinations.push(destination); | 346 recentDestinations.push(destination); |
| 358 } | 347 } |
| 359 if (destination.isLocal || | 348 if (destination.isLocal || |
| 360 destination.origin == print_preview.Destination.Origin.DEVICE) { | 349 destination.origin == print_preview.Destination.Origin.DEVICE) { |
| 361 localDestinations.push(destination); | 350 localDestinations.push(destination); |
| 362 } else { | 351 } else { |
| 363 if (destination.connectionStatus == | 352 if (destination.connectionStatus == |
| 364 print_preview.Destination.ConnectionStatus.UNREGISTERED) { | 353 print_preview.Destination.ConnectionStatus.UNREGISTERED) { |
| 365 unregisteredCloudDestinations.push(destination); | 354 unregisteredCloudDestinations.push(destination); |
| 366 } else { | 355 } else { |
| 367 cloudDestinations.push(destination); | 356 cloudDestinations.push(destination); |
| 368 } | 357 } |
| 369 } | 358 } |
| 370 }); | 359 }); |
| 371 | 360 |
| 372 if (unregisteredCloudDestinations.length != 0 && | 361 if (unregisteredCloudDestinations.length != 0 && |
| 373 !this.registerPromoShownMetricRecorded_) { | 362 !this.registerPromoShownMetricRecorded_) { |
| 374 this.metrics_.record( | 363 this.metrics_.record( |
| 375 print_preview.Metrics.DestinationSearchBucket.REGISTER_PROMO_SHOWN); | 364 print_preview.Metrics.DestinationSearchBucket.REGISTER_PROMO_SHOWN); |
| 376 this.registerPromoShownMetricRecorded_ = true; | 365 this.registerPromoShownMetricRecorded_ = true; |
| 377 } | 366 } |
| 378 | 367 |
| 379 var finalCloudDestinations = unregisteredCloudDestinations.slice( | 368 var finalCloudDestinations = |
| 380 0, DestinationSearch.MAX_PROMOTED_UNREGISTERED_PRINTERS_).concat( | 369 unregisteredCloudDestinations |
| 381 cloudDestinations, | 370 .slice(0, DestinationSearch.MAX_PROMOTED_UNREGISTERED_PRINTERS_) |
| 382 unregisteredCloudDestinations.slice( | 371 .concat( |
| 383 DestinationSearch.MAX_PROMOTED_UNREGISTERED_PRINTERS_)); | 372 cloudDestinations, |
| 373 unregisteredCloudDestinations.slice( |
| 374 DestinationSearch.MAX_PROMOTED_UNREGISTERED_PRINTERS_)); |
| 384 | 375 |
| 385 this.recentList_.updateDestinations(recentDestinations); | 376 this.recentList_.updateDestinations(recentDestinations); |
| 386 this.localList_.updateDestinations(localDestinations); | 377 this.localList_.updateDestinations(localDestinations); |
| 387 this.cloudList_.updateDestinations(finalCloudDestinations); | 378 this.cloudList_.updateDestinations(finalCloudDestinations); |
| 388 }, | 379 }, |
| 389 | 380 |
| 390 /** | 381 /** |
| 391 * Reflows the destination lists according to the available height. | 382 * Reflows the destination lists according to the available height. |
| 392 * @private | 383 * @private |
| 393 */ | 384 */ |
| 394 reflowLists_: function() { | 385 reflowLists_: function() { |
| 395 if (!this.getIsVisible()) { | 386 if (!this.getIsVisible()) { |
| 396 return; | 387 return; |
| 397 } | 388 } |
| 398 | 389 |
| 399 var hasCloudList = getIsVisible(this.getChildElement('.cloud-list')); | 390 var hasCloudList = getIsVisible(this.getChildElement('.cloud-list')); |
| 400 var lists = [this.recentList_, this.localList_]; | 391 var lists = [this.recentList_, this.localList_]; |
| 401 if (hasCloudList) { | 392 if (hasCloudList) { |
| 402 lists.push(this.cloudList_); | 393 lists.push(this.cloudList_); |
| 403 } | 394 } |
| 404 | 395 |
| 405 var getListsTotalHeight = function(lists, counts) { | 396 var getListsTotalHeight = function(lists, counts) { |
| 406 return lists.reduce(function(sum, list, index) { | 397 return lists.reduce(function(sum, list, index) { |
| 407 var container = list.getContainerElement(); | 398 var container = list.getContainerElement(); |
| 408 return sum + list.getEstimatedHeightInPixels(counts[index]) + | 399 return sum + list.getEstimatedHeightInPixels(counts[index]) + |
| 409 parseInt(window.getComputedStyle(container).paddingBottom, 10); | 400 parseInt(window.getComputedStyle(container).paddingBottom, 10); |
| 410 }, 0); | 401 }, 0); |
| 411 }; | 402 }; |
| 412 var getCounts = function(lists, count) { | 403 var getCounts = function(lists, count) { |
| 413 return lists.map(function(list) { return count; }); | 404 return lists.map(function(list) { |
| 405 return count; |
| 406 }); |
| 414 }; | 407 }; |
| 415 | 408 |
| 416 var availableHeight = this.getAvailableListsHeight_(); | 409 var availableHeight = this.getAvailableListsHeight_(); |
| 417 var listsEl = this.getChildElement('.lists'); | 410 var listsEl = this.getChildElement('.lists'); |
| 418 listsEl.style.maxHeight = availableHeight + 'px'; | 411 listsEl.style.maxHeight = availableHeight + 'px'; |
| 419 | 412 |
| 420 var maxListLength = lists.reduce(function(prevCount, list) { | 413 var maxListLength = lists.reduce(function(prevCount, list) { |
| 421 return Math.max(prevCount, list.getDestinationsCount()); | 414 return Math.max(prevCount, list.getDestinationsCount()); |
| 422 }, 0); | 415 }, 0); |
| 423 for (var i = 1; i <= maxListLength; i++) { | 416 for (var i = 1; i <= maxListLength; i++) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 this.destinationStore_.isCloudDestinationSearchInProgress); | 464 this.destinationStore_.isCloudDestinationSearchInProgress); |
| 472 this.reflowLists_(); | 465 this.reflowLists_(); |
| 473 }, | 466 }, |
| 474 | 467 |
| 475 /** | 468 /** |
| 476 * Updates printer sharing invitations UI. | 469 * Updates printer sharing invitations UI. |
| 477 * @private | 470 * @private |
| 478 */ | 471 */ |
| 479 updateInvitations_: function() { | 472 updateInvitations_: function() { |
| 480 var invitations = this.userInfo_.activeUser ? | 473 var invitations = this.userInfo_.activeUser ? |
| 481 this.invitationStore_.invitations(this.userInfo_.activeUser) : []; | 474 this.invitationStore_.invitations(this.userInfo_.activeUser) : |
| 475 []; |
| 482 if (invitations.length > 0) { | 476 if (invitations.length > 0) { |
| 483 if (this.invitation_ != invitations[0]) { | 477 if (this.invitation_ != invitations[0]) { |
| 484 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. | 478 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket |
| 485 INVITATION_AVAILABLE); | 479 .INVITATION_AVAILABLE); |
| 486 } | 480 } |
| 487 this.invitation_ = invitations[0]; | 481 this.invitation_ = invitations[0]; |
| 488 this.showInvitation_(this.invitation_); | 482 this.showInvitation_(this.invitation_); |
| 489 } else { | 483 } else { |
| 490 this.invitation_ = null; | 484 this.invitation_ = null; |
| 491 } | 485 } |
| 492 setIsVisible( | 486 setIsVisible( |
| 493 this.getChildElement('.invitation-container'), !!this.invitation_); | 487 this.getChildElement('.invitation-container'), !!this.invitation_); |
| 494 this.reflowLists_(); | 488 this.reflowLists_(); |
| 495 }, | 489 }, |
| 496 | 490 |
| 497 /** | 491 /** |
| 498 * @param {!printe_preview.Invitation} invitation Invitation to show. | 492 * @param {!printe_preview.Invitation} invitation Invitation to show. |
| 499 * @private | 493 * @private |
| 500 */ | 494 */ |
| 501 showInvitation_: function(invitation) { | 495 showInvitation_: function(invitation) { |
| 502 var invitationText = ''; | 496 var invitationText = ''; |
| 503 if (invitation.asGroupManager) { | 497 if (invitation.asGroupManager) { |
| 504 invitationText = loadTimeData.getStringF( | 498 invitationText = loadTimeData.getStringF( |
| 505 'groupPrinterSharingInviteText', | 499 'groupPrinterSharingInviteText', HTMLEscape(invitation.sender), |
| 506 HTMLEscape(invitation.sender), | |
| 507 HTMLEscape(invitation.destination.displayName), | 500 HTMLEscape(invitation.destination.displayName), |
| 508 HTMLEscape(invitation.receiver)); | 501 HTMLEscape(invitation.receiver)); |
| 509 } else { | 502 } else { |
| 510 invitationText = loadTimeData.getStringF( | 503 invitationText = loadTimeData.getStringF( |
| 511 'printerSharingInviteText', | 504 'printerSharingInviteText', HTMLEscape(invitation.sender), |
| 512 HTMLEscape(invitation.sender), | |
| 513 HTMLEscape(invitation.destination.displayName)); | 505 HTMLEscape(invitation.destination.displayName)); |
| 514 } | 506 } |
| 515 this.getChildElement('.invitation-text').innerHTML = invitationText; | 507 this.getChildElement('.invitation-text').innerHTML = invitationText; |
| 516 | 508 |
| 517 var acceptButton = this.getChildElement('.invitation-accept-button'); | 509 var acceptButton = this.getChildElement('.invitation-accept-button'); |
| 518 acceptButton.textContent = loadTimeData.getString( | 510 acceptButton.textContent = loadTimeData.getString( |
| 519 invitation.asGroupManager ? 'acceptForGroup' : 'accept'); | 511 invitation.asGroupManager ? 'acceptForGroup' : 'accept'); |
| 520 acceptButton.disabled = !!this.invitationStore_.invitationInProgress; | 512 acceptButton.disabled = !!this.invitationStore_.invitationInProgress; |
| 521 this.getChildElement('.invitation-reject-button').disabled = | 513 this.getChildElement('.invitation-reject-button').disabled = |
| 522 !!this.invitationStore_.invitationInProgress; | 514 !!this.invitationStore_.invitationInProgress; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 | 569 |
| 578 /** | 570 /** |
| 579 * Called when a destination is selected. Clears the search and hides the | 571 * Called when a destination is selected. Clears the search and hides the |
| 580 * widget. If The destination is provisional, it runs provisional | 572 * widget. If The destination is provisional, it runs provisional |
| 581 * destination resolver first. | 573 * destination resolver first. |
| 582 * @param {!print_preview.Destination} destination The selected destination. | 574 * @param {!print_preview.Destination} destination The selected destination. |
| 583 * @private | 575 * @private |
| 584 */ | 576 */ |
| 585 handleOnDestinationSelect_: function(destination) { | 577 handleOnDestinationSelect_: function(destination) { |
| 586 if (destination.isProvisional) { | 578 if (destination.isProvisional) { |
| 587 assert(!this.provisionalDestinationResolver_, | 579 assert( |
| 588 'Provisional destination resolver already exists.'); | 580 !this.provisionalDestinationResolver_, |
| 581 'Provisional destination resolver already exists.'); |
| 589 this.provisionalDestinationResolver_ = | 582 this.provisionalDestinationResolver_ = |
| 590 print_preview.ProvisionalDestinationResolver.create( | 583 print_preview.ProvisionalDestinationResolver.create( |
| 591 this.destinationStore_, destination); | 584 this.destinationStore_, destination); |
| 592 assert(!!this.provisionalDestinationResolver_, | 585 assert( |
| 593 'Unable to create provisional destination resolver'); | 586 !!this.provisionalDestinationResolver_, |
| 587 'Unable to create provisional destination resolver'); |
| 594 | 588 |
| 595 var lastFocusedElement = document.activeElement; | 589 var lastFocusedElement = document.activeElement; |
| 596 this.addChild(this.provisionalDestinationResolver_); | 590 this.addChild(this.provisionalDestinationResolver_); |
| 597 this.provisionalDestinationResolver_.run(this.getElement()) | 591 this.provisionalDestinationResolver_.run(this.getElement()) |
| 598 .then( | 592 .then( |
| 599 /** | 593 /** |
| 600 * @param {!print_preview.Destination} resolvedDestination | 594 * @param {!print_preview.Destination} resolvedDestination |
| 601 * Destination to which the provisional destination was | 595 * Destination to which the provisional destination was |
| 602 * resolved. | 596 * resolved. |
| 603 */ | 597 */ |
| 604 function(resolvedDestination) { | 598 function(resolvedDestination) { |
| 605 this.handleOnDestinationSelect_(resolvedDestination); | 599 this.handleOnDestinationSelect_(resolvedDestination); |
| 606 }.bind(this)) | 600 }.bind(this)) |
| 607 .catch( | 601 .catch(function() { |
| 608 function() { | 602 console.log( |
| 609 console.log('Failed to resolve provisional destination: ' + | 603 'Failed to resolve provisional destination: ' + |
| 610 destination.id); | 604 destination.id); |
| 611 }) | 605 }) |
| 612 .then( | 606 .then(function() { |
| 613 function() { | 607 this.removeChild(this.provisionalDestinationResolver_); |
| 614 this.removeChild(this.provisionalDestinationResolver_); | 608 this.provisionalDestinationResolver_ = null; |
| 615 this.provisionalDestinationResolver_ = null; | |
| 616 | 609 |
| 617 // Restore focus to the previosly focused element if it's | 610 // Restore focus to the previosly focused element if it's |
| 618 // still shown in the search. | 611 // still shown in the search. |
| 619 if (lastFocusedElement && | 612 if (lastFocusedElement && this.getIsVisible() && |
| 620 this.getIsVisible() && | 613 getIsVisible(lastFocusedElement) && |
| 621 getIsVisible(lastFocusedElement) && | 614 this.getElement().contains(lastFocusedElement)) { |
| 622 this.getElement().contains(lastFocusedElement)) { | 615 lastFocusedElement.focus(); |
| 623 lastFocusedElement.focus(); | 616 } |
| 624 } | 617 }.bind(this)); |
| 625 }.bind(this)); | |
| 626 return; | 618 return; |
| 627 } | 619 } |
| 628 | 620 |
| 629 this.setIsVisible(false); | 621 this.setIsVisible(false); |
| 630 this.destinationStore_.selectDestination(destination); | 622 this.destinationStore_.selectDestination(destination); |
| 631 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket. | 623 this.metrics_.record(print_preview.Metrics.DestinationSearchBucket |
| 632 DESTINATION_CLOSED_CHANGED); | 624 .DESTINATION_CLOSED_CHANGED); |
| 633 }, | 625 }, |
| 634 | 626 |
| 635 /** | 627 /** |
| 636 * Called when a destination is selected. Selected destination are marked as | 628 * Called when a destination is selected. Selected destination are marked as |
| 637 * recent, so we have to update our recent destinations list. | 629 * recent, so we have to update our recent destinations list. |
| 638 * @private | 630 * @private |
| 639 */ | 631 */ |
| 640 onDestinationStoreSelect_: function() { | 632 onDestinationStoreSelect_: function() { |
| 641 var destinations = | 633 var destinations = |
| 642 this.destinationStore_.destinations(this.userInfo_.activeUser); | 634 this.destinationStore_.destinations(this.userInfo_.activeUser); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 print_preview.Metrics.DestinationSearchBucket.ADD_ACCOUNT_SELECTED); | 725 print_preview.Metrics.DestinationSearchBucket.ADD_ACCOUNT_SELECTED); |
| 734 } | 726 } |
| 735 }, | 727 }, |
| 736 | 728 |
| 737 /** | 729 /** |
| 738 * Called when the printer sharing invitation Accept/Reject button is | 730 * Called when the printer sharing invitation Accept/Reject button is |
| 739 * clicked. | 731 * clicked. |
| 740 * @private | 732 * @private |
| 741 */ | 733 */ |
| 742 onInvitationProcessButtonClick_: function(accept) { | 734 onInvitationProcessButtonClick_: function(accept) { |
| 743 this.metrics_.record(accept ? | 735 this.metrics_.record( |
| 744 print_preview.Metrics.DestinationSearchBucket.INVITATION_ACCEPTED : | 736 accept ? |
| 745 print_preview.Metrics.DestinationSearchBucket.INVITATION_REJECTED); | 737 print_preview.Metrics.DestinationSearchBucket |
| 738 .INVITATION_ACCEPTED : |
| 739 print_preview.Metrics.DestinationSearchBucket |
| 740 .INVITATION_REJECTED); |
| 746 this.invitationStore_.processInvitation(this.invitation_, accept); | 741 this.invitationStore_.processInvitation(this.invitation_, accept); |
| 747 this.updateInvitations_(); | 742 this.updateInvitations_(); |
| 748 }, | 743 }, |
| 749 | 744 |
| 750 /** | 745 /** |
| 751 * Called when the close button on the cloud print promo is clicked. Hides | 746 * Called when the close button on the cloud print promo is clicked. Hides |
| 752 * the promo. | 747 * the promo. |
| 753 * @private | 748 * @private |
| 754 */ | 749 */ |
| 755 onCloudprintPromoCloseButtonClick_: function() { | 750 onCloudprintPromoCloseButtonClick_: function() { |
| 756 setIsVisible(this.getChildElement('.cloudprint-promo'), false); | 751 setIsVisible(this.getChildElement('.cloudprint-promo'), false); |
| 757 this.reflowLists_(); | 752 this.reflowLists_(); |
| 758 }, | 753 }, |
| 759 | 754 |
| 760 /** | 755 /** |
| 761 * Called when the window is resized. Reflows layout of destination lists. | 756 * Called when the window is resized. Reflows layout of destination lists. |
| 762 * @private | 757 * @private |
| 763 */ | 758 */ |
| 764 onWindowResize_: function() { | 759 onWindowResize_: function() { |
| 765 this.reflowLists_(); | 760 this.reflowLists_(); |
| 766 } | 761 } |
| 767 }; | 762 }; |
| 768 | 763 |
| 769 // Export | 764 // Export |
| 770 return { | 765 return {DestinationSearch: DestinationSearch}; |
| 771 DestinationSearch: DestinationSearch | |
| 772 }; | |
| 773 }); | 766 }); |
| OLD | NEW |