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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 'Trying to create a Google Cloud Print print ticket for a ' + | 369 'Trying to create a Google Cloud Print print ticket for a ' + |
370 'destination with no print capabilities'); | 370 'destination with no print capabilities'); |
371 var cjt = { | 371 var cjt = { |
372 version: '1.0', | 372 version: '1.0', |
373 print: {} | 373 print: {} |
374 }; | 374 }; |
375 if (this.collate.isCapabilityAvailable() && this.collate.isUserEdited()) { | 375 if (this.collate.isCapabilityAvailable() && this.collate.isUserEdited()) { |
376 cjt.print.collate = {collate: this.collate.getValue()}; | 376 cjt.print.collate = {collate: this.collate.getValue()}; |
377 } | 377 } |
378 if (this.color.isCapabilityAvailable() && this.color.isUserEdited()) { | 378 if (this.color.isCapabilityAvailable() && this.color.isUserEdited()) { |
379 var colorType = this.color.getValue() ? | 379 var selectedOption = this.color.getSelectedOption(); |
380 'STANDARD_COLOR' : 'STANDARD_MONOCHROME'; | 380 if (!selectedOption) { |
381 // Find option with this colorType to read its vendor_id. | |
382 var selectedOptions = destination.capabilities.printer.color.option. | |
383 filter(function(option) { | |
384 return option.type == colorType; | |
385 }); | |
386 if (selectedOptions.length == 0) { | |
387 console.error('Could not find correct color option'); | 381 console.error('Could not find correct color option'); |
388 } else { | 382 } else { |
389 cjt.print.color = {type: colorType}; | 383 cjt.print.color = {type: selectedOption.type}; |
390 if (selectedOptions[0].hasOwnProperty('vendor_id')) { | 384 if (selectedOption.hasOwnProperty('vendor_id')) { |
391 cjt.print.color.vendor_id = selectedOptions[0].vendor_id; | 385 cjt.print.color.vendor_id = selectedOption.vendor_id; |
392 } | 386 } |
393 } | 387 } |
394 } | 388 } |
395 if (this.copies.isCapabilityAvailable() && this.copies.isUserEdited()) { | 389 if (this.copies.isCapabilityAvailable() && this.copies.isUserEdited()) { |
396 cjt.print.copies = {copies: this.copies.getValueAsNumber()}; | 390 cjt.print.copies = {copies: this.copies.getValueAsNumber()}; |
397 } | 391 } |
398 if (this.duplex.isCapabilityAvailable() && this.duplex.isUserEdited()) { | 392 if (this.duplex.isCapabilityAvailable() && this.duplex.isUserEdited()) { |
399 cjt.print.duplex = | 393 cjt.print.duplex = |
400 {type: this.duplex.getValue() ? 'LONG_EDGE' : 'NO_DUPLEX'}; | 394 {type: this.duplex.getValue() ? 'LONG_EDGE' : 'NO_DUPLEX'}; |
401 } | 395 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 onDocumentInfoChange_: function() { | 483 onDocumentInfoChange_: function() { |
490 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.DOCUMENT_CHANGE); | 484 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.DOCUMENT_CHANGE); |
491 }, | 485 }, |
492 }; | 486 }; |
493 | 487 |
494 // Export | 488 // Export |
495 return { | 489 return { |
496 PrintTicketStore: PrintTicketStore | 490 PrintTicketStore: PrintTicketStore |
497 }; | 491 }; |
498 }); | 492 }); |
OLD | NEW |