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 // TODO(rltoscano): Maybe clear print ticket when destination changes. Or | 8 // TODO(rltoscano): Maybe clear print ticket when destination changes. Or |
9 // better yet, carry over any print ticket state that is possible. I.e. if | 9 // better yet, carry over any print ticket state that is possible. I.e. if |
10 // destination changes, the new destination might not support duplex anymore, | 10 // destination changes, the new destination might not support duplex anymore, |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 return JSON.stringify(cjt); | 383 return JSON.stringify(cjt); |
384 }, | 384 }, |
385 | 385 |
386 /** | 386 /** |
387 * Adds event listeners for the print ticket store. | 387 * Adds event listeners for the print ticket store. |
388 * @private | 388 * @private |
389 */ | 389 */ |
390 addEventListeners_: function() { | 390 addEventListeners_: function() { |
391 this.tracker_.add( | 391 this.tracker_.add( |
392 this.destinationStore_, | 392 this.destinationStore_, |
| 393 print_preview.DestinationStore.EventType.DESTINATION_SELECT, |
| 394 this.onDestinationSelect_.bind(this)); |
| 395 |
| 396 this.tracker_.add( |
| 397 this.destinationStore_, |
393 print_preview.DestinationStore.EventType. | 398 print_preview.DestinationStore.EventType. |
394 SELECTED_DESTINATION_CAPABILITIES_READY, | 399 SELECTED_DESTINATION_CAPABILITIES_READY, |
395 this.onSelectedDestinationCapabilitiesReady_.bind(this)); | 400 this.onSelectedDestinationCapabilitiesReady_.bind(this)); |
396 | 401 |
397 this.tracker_.add( | 402 this.tracker_.add( |
398 this.destinationStore_, | 403 this.destinationStore_, |
399 print_preview.DestinationStore.EventType. | 404 print_preview.DestinationStore.EventType. |
400 CACHED_SELECTED_DESTINATION_INFO_READY, | 405 CACHED_SELECTED_DESTINATION_INFO_READY, |
401 this.onSelectedDestinationCapabilitiesReady_.bind(this)); | 406 this.onSelectedDestinationCapabilitiesReady_.bind(this)); |
402 | 407 |
403 // TODO(rltoscano): Print ticket store shouldn't be re-dispatching these | 408 // TODO(rltoscano): Print ticket store shouldn't be re-dispatching these |
404 // events, the consumers of the print ticket store events should listen | 409 // events, the consumers of the print ticket store events should listen |
405 // for the events from document info instead. Will move this when | 410 // for the events from document info instead. Will move this when |
406 // consumers are all migrated. | 411 // consumers are all migrated. |
407 this.tracker_.add( | 412 this.tracker_.add( |
408 this.documentInfo_, | 413 this.documentInfo_, |
409 print_preview.DocumentInfo.EventType.CHANGE, | 414 print_preview.DocumentInfo.EventType.CHANGE, |
410 this.onDocumentInfoChange_.bind(this)); | 415 this.onDocumentInfoChange_.bind(this)); |
411 }, | 416 }, |
412 | 417 |
413 /** | 418 /** |
| 419 * Called when the destination selected. |
| 420 * @private |
| 421 */ |
| 422 onDestinationSelect_: function() { |
| 423 // Reset user selection for certain ticket items. |
| 424 if (this.capabilitiesHolder_.get() != null) { |
| 425 this.customMargins_.updateValue(null); |
| 426 if (this.marginsType_.getValue() == |
| 427 print_preview.ticket_items.MarginsType.Value.CUSTOM) { |
| 428 this.marginsType_.updateValue( |
| 429 print_preview.ticket_items.MarginsType.Value.DEFAULT); |
| 430 } |
| 431 } |
| 432 }, |
| 433 |
| 434 /** |
414 * Called when the capabilities of the selected destination are ready. | 435 * Called when the capabilities of the selected destination are ready. |
415 * @private | 436 * @private |
416 */ | 437 */ |
417 onSelectedDestinationCapabilitiesReady_: function() { | 438 onSelectedDestinationCapabilitiesReady_: function() { |
418 var caps = this.destinationStore_.selectedDestination.capabilities; | 439 var caps = this.destinationStore_.selectedDestination.capabilities; |
419 var isFirstUpdate = this.capabilitiesHolder_.get() == null; | 440 var isFirstUpdate = this.capabilitiesHolder_.get() == null; |
420 this.capabilitiesHolder_.set(caps); | 441 this.capabilitiesHolder_.set(caps); |
421 if (isFirstUpdate) { | 442 if (isFirstUpdate) { |
422 this.isInitialized_ = true; | 443 this.isInitialized_ = true; |
423 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.INITIALIZE); | 444 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.INITIALIZE); |
424 } else { | 445 } else { |
425 // Reset user selection for certain ticket items. | |
426 this.customMargins_.updateValue(null); | |
427 | |
428 if (this.marginsType_.getValue() == | |
429 print_preview.ticket_items.MarginsType.Value.CUSTOM) { | |
430 this.marginsType_.updateValue( | |
431 print_preview.ticket_items.MarginsType.Value.DEFAULT); | |
432 } | |
433 cr.dispatchSimpleEvent( | 446 cr.dispatchSimpleEvent( |
434 this, PrintTicketStore.EventType.CAPABILITIES_CHANGE); | 447 this, PrintTicketStore.EventType.CAPABILITIES_CHANGE); |
435 } | 448 } |
436 }, | 449 }, |
437 | 450 |
438 /** | 451 /** |
439 * Called when document data model has changed. Dispatches a print ticket | 452 * Called when document data model has changed. Dispatches a print ticket |
440 * store event. | 453 * store event. |
441 * @private | 454 * @private |
442 */ | 455 */ |
443 onDocumentInfoChange_: function() { | 456 onDocumentInfoChange_: function() { |
444 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.DOCUMENT_CHANGE); | 457 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.DOCUMENT_CHANGE); |
445 }, | 458 }, |
446 }; | 459 }; |
447 | 460 |
448 // Export | 461 // Export |
449 return { | 462 return { |
450 PrintTicketStore: PrintTicketStore | 463 PrintTicketStore: PrintTicketStore |
451 }; | 464 }; |
452 }); | 465 }); |
OLD | NEW |