| 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 */ | 298 */ |
| 299 init: function( | 299 init: function( |
| 300 thousandsDelimeter, decimalDelimeter, unitType, selectionOnly) { | 300 thousandsDelimeter, decimalDelimeter, unitType, selectionOnly) { |
| 301 this.measurementSystem_.setSystem(thousandsDelimeter, decimalDelimeter, | 301 this.measurementSystem_.setSystem(thousandsDelimeter, decimalDelimeter, |
| 302 unitType); | 302 unitType); |
| 303 this.selectionOnly_.updateValue(selectionOnly); | 303 this.selectionOnly_.updateValue(selectionOnly); |
| 304 | 304 |
| 305 // Initialize ticket with user's previous values. | 305 // Initialize ticket with user's previous values. |
| 306 if (this.appState_.hasField( | 306 if (this.appState_.hasField( |
| 307 print_preview.AppState.Field.IS_COLOR_ENABLED)) { | 307 print_preview.AppState.Field.IS_COLOR_ENABLED)) { |
| 308 this.color_.updateValue(this.appState_.getField( | 308 this.color_.updateValue( |
| 309 print_preview.AppState.Field.IS_COLOR_ENABLED)); | 309 /** @type {!Object} */(this.appState_.getField( |
| 310 print_preview.AppState.Field.IS_COLOR_ENABLED))); |
| 310 } | 311 } |
| 311 if (this.appState_.hasField( | 312 if (this.appState_.hasField( |
| 312 print_preview.AppState.Field.IS_DUPLEX_ENABLED)) { | 313 print_preview.AppState.Field.IS_DUPLEX_ENABLED)) { |
| 313 this.duplex_.updateValue(this.appState_.getField( | 314 this.duplex_.updateValue( |
| 314 print_preview.AppState.Field.IS_DUPLEX_ENABLED)); | 315 /** @type {!Object} */(this.appState_.getField( |
| 316 print_preview.AppState.Field.IS_DUPLEX_ENABLED))); |
| 315 } | 317 } |
| 316 if (this.appState_.hasField(print_preview.AppState.Field.MEDIA_SIZE)) { | 318 if (this.appState_.hasField(print_preview.AppState.Field.MEDIA_SIZE)) { |
| 317 this.mediaSize_.updateValue(this.appState_.getField( | 319 this.mediaSize_.updateValue( |
| 318 print_preview.AppState.Field.MEDIA_SIZE)); | 320 /** @type {!Object} */(this.appState_.getField( |
| 321 print_preview.AppState.Field.MEDIA_SIZE))); |
| 319 } | 322 } |
| 320 if (this.appState_.hasField( | 323 if (this.appState_.hasField( |
| 321 print_preview.AppState.Field.IS_LANDSCAPE_ENABLED)) { | 324 print_preview.AppState.Field.IS_LANDSCAPE_ENABLED)) { |
| 322 this.landscape_.updateValue(this.appState_.getField( | 325 this.landscape_.updateValue( |
| 323 print_preview.AppState.Field.IS_LANDSCAPE_ENABLED)); | 326 /** @type {!Object} */(this.appState_.getField( |
| 327 print_preview.AppState.Field.IS_LANDSCAPE_ENABLED))); |
| 324 } | 328 } |
| 325 // Initialize margins after landscape because landscape may reset margins. | 329 // Initialize margins after landscape because landscape may reset margins. |
| 326 if (this.appState_.hasField(print_preview.AppState.Field.MARGINS_TYPE)) { | 330 if (this.appState_.hasField(print_preview.AppState.Field.MARGINS_TYPE)) { |
| 327 this.marginsType_.updateValue( | 331 this.marginsType_.updateValue( |
| 328 this.appState_.getField(print_preview.AppState.Field.MARGINS_TYPE)); | 332 /** @type {!Object} */(this.appState_.getField( |
| 333 print_preview.AppState.Field.MARGINS_TYPE))); |
| 329 } | 334 } |
| 330 if (this.appState_.hasField( | 335 if (this.appState_.hasField( |
| 331 print_preview.AppState.Field.CUSTOM_MARGINS)) { | 336 print_preview.AppState.Field.CUSTOM_MARGINS)) { |
| 332 this.customMargins_.updateValue(this.appState_.getField( | 337 this.customMargins_.updateValue( |
| 333 print_preview.AppState.Field.CUSTOM_MARGINS)); | 338 /** @type {!Object} */(this.appState_.getField( |
| 339 print_preview.AppState.Field.CUSTOM_MARGINS))); |
| 334 } | 340 } |
| 335 if (this.appState_.hasField( | 341 if (this.appState_.hasField( |
| 336 print_preview.AppState.Field.IS_HEADER_FOOTER_ENABLED)) { | 342 print_preview.AppState.Field.IS_HEADER_FOOTER_ENABLED)) { |
| 337 this.headerFooter_.updateValue(this.appState_.getField( | 343 this.headerFooter_.updateValue( |
| 338 print_preview.AppState.Field.IS_HEADER_FOOTER_ENABLED)); | 344 /** @type {!Object} */(this.appState_.getField( |
| 345 print_preview.AppState.Field.IS_HEADER_FOOTER_ENABLED))); |
| 339 } | 346 } |
| 340 if (this.appState_.hasField( | 347 if (this.appState_.hasField( |
| 341 print_preview.AppState.Field.IS_COLLATE_ENABLED)) { | 348 print_preview.AppState.Field.IS_COLLATE_ENABLED)) { |
| 342 this.collate_.updateValue(this.appState_.getField( | 349 this.collate_.updateValue( |
| 343 print_preview.AppState.Field.IS_COLLATE_ENABLED)); | 350 /** @type {!Object} */(this.appState_.getField( |
| 351 print_preview.AppState.Field.IS_COLLATE_ENABLED))); |
| 344 } | 352 } |
| 345 if (this.appState_.hasField( | 353 if (this.appState_.hasField( |
| 346 print_preview.AppState.Field.IS_CSS_BACKGROUND_ENABLED)) { | 354 print_preview.AppState.Field.IS_CSS_BACKGROUND_ENABLED)) { |
| 347 this.cssBackground_.updateValue(this.appState_.getField( | 355 this.cssBackground_.updateValue( |
| 348 print_preview.AppState.Field.IS_CSS_BACKGROUND_ENABLED)); | 356 /** @type {!Object} */(this.appState_.getField( |
| 357 print_preview.AppState.Field.IS_CSS_BACKGROUND_ENABLED))); |
| 349 } | 358 } |
| 350 if (this.appState_.hasField( | 359 if (this.appState_.hasField( |
| 351 print_preview.AppState.Field.VENDOR_OPTIONS)) { | 360 print_preview.AppState.Field.VENDOR_OPTIONS)) { |
| 352 this.vendorItems_.updateValue(this.appState_.getField( | 361 this.vendorItems_.updateValue( |
| 353 print_preview.AppState.Field.VENDOR_OPTIONS)); | 362 /** @type {!Object.<string, string>} */(this.appState_.getField( |
| 363 print_preview.AppState.Field.VENDOR_OPTIONS))); |
| 354 } | 364 } |
| 355 }, | 365 }, |
| 356 | 366 |
| 357 /** | 367 /** |
| 358 * @return {boolean} {@code true} if the stored print ticket is valid, | 368 * @return {boolean} {@code true} if the stored print ticket is valid, |
| 359 * {@code false} otherwise. | 369 * {@code false} otherwise. |
| 360 */ | 370 */ |
| 361 isTicketValid: function() { | 371 isTicketValid: function() { |
| 362 return this.isTicketValidForPreview() && | 372 return this.isTicketValidForPreview() && |
| 363 (!this.copies_.isCapabilityAvailable() || this.copies_.isValid()) && | 373 (!this.copies_.isCapabilityAvailable() || this.copies_.isValid()) && |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 } | 501 } |
| 492 this.vendorItems_.updateValue({}); | 502 this.vendorItems_.updateValue({}); |
| 493 } | 503 } |
| 494 }, | 504 }, |
| 495 | 505 |
| 496 /** | 506 /** |
| 497 * Called when the capabilities of the selected destination are ready. | 507 * Called when the capabilities of the selected destination are ready. |
| 498 * @private | 508 * @private |
| 499 */ | 509 */ |
| 500 onSelectedDestinationCapabilitiesReady_: function() { | 510 onSelectedDestinationCapabilitiesReady_: function() { |
| 501 var caps = this.destinationStore_.selectedDestination.capabilities; | 511 var caps = assert( |
| 512 this.destinationStore_.selectedDestination.capabilities); |
| 502 var isFirstUpdate = this.capabilitiesHolder_.get() == null; | 513 var isFirstUpdate = this.capabilitiesHolder_.get() == null; |
| 503 this.capabilitiesHolder_.set(caps); | 514 this.capabilitiesHolder_.set(caps); |
| 504 if (isFirstUpdate) { | 515 if (isFirstUpdate) { |
| 505 this.isInitialized_ = true; | 516 this.isInitialized_ = true; |
| 506 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.INITIALIZE); | 517 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.INITIALIZE); |
| 507 } else { | 518 } else { |
| 508 cr.dispatchSimpleEvent( | 519 cr.dispatchSimpleEvent( |
| 509 this, PrintTicketStore.EventType.CAPABILITIES_CHANGE); | 520 this, PrintTicketStore.EventType.CAPABILITIES_CHANGE); |
| 510 } | 521 } |
| 511 }, | 522 }, |
| 512 | 523 |
| 513 /** | 524 /** |
| 514 * Called when document data model has changed. Dispatches a print ticket | 525 * Called when document data model has changed. Dispatches a print ticket |
| 515 * store event. | 526 * store event. |
| 516 * @private | 527 * @private |
| 517 */ | 528 */ |
| 518 onDocumentInfoChange_: function() { | 529 onDocumentInfoChange_: function() { |
| 519 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.DOCUMENT_CHANGE); | 530 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.DOCUMENT_CHANGE); |
| 520 }, | 531 }, |
| 521 }; | 532 }; |
| 522 | 533 |
| 523 // Export | 534 // Export |
| 524 return { | 535 return { |
| 525 PrintTicketStore: PrintTicketStore | 536 PrintTicketStore: PrintTicketStore |
| 526 }; | 537 }; |
| 527 }); | 538 }); |
| OLD | NEW |