OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.ticket_items', function() { | 5 cr.define('print_preview.ticket_items', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * DPI ticket item. | 9 * DPI ticket item. |
10 * @param {!print_preview.AppState} appState App state used to persist DPI | 10 * @param {!print_preview.AppState} appState App state used to persist DPI |
11 * selection. | 11 * selection. |
12 * @param {!print_preview.DestinationStore} destinationStore Destination store | 12 * @param {!print_preview.DestinationStore} destinationStore Destination store |
13 * used to determine if a destination has the DPI capability. | 13 * used to determine if a destination has the DPI capability. |
14 * @constructor | 14 * @constructor |
15 * @extends {print_preview.ticket_items.TicketItem} | 15 * @extends {print_preview.ticket_items.TicketItem} |
16 */ | 16 */ |
17 function Dpi(appState, destinationStore) { | 17 function Dpi(appState, destinationStore) { |
18 print_preview.ticket_items.TicketItem.call( | 18 print_preview.ticket_items.TicketItem.call( |
19 this, | 19 this, appState, print_preview.AppStateField.DPI, destinationStore); |
20 appState, | |
21 print_preview.AppStateField.DPI, | |
22 destinationStore); | |
23 } | 20 } |
24 | 21 |
25 Dpi.prototype = { | 22 Dpi.prototype = { |
26 __proto__: print_preview.ticket_items.TicketItem.prototype, | 23 __proto__: print_preview.ticket_items.TicketItem.prototype, |
27 | 24 |
28 /** @override */ | 25 /** @override */ |
29 wouldValueBeValid: function(value) { | 26 wouldValueBeValid: function(value) { |
30 if (!this.isCapabilityAvailable()) | 27 if (!this.isCapabilityAvailable()) |
31 return false; | 28 return false; |
32 return this.capability.option.some(function(option) { | 29 return this.capability.option.some(function(option) { |
33 return option.horizontal_dpi == value.horizontal_dpi && | 30 return option.horizontal_dpi == value.horizontal_dpi && |
34 option.vertical_dpi == value.vertical_dpi && | 31 option.vertical_dpi == value.vertical_dpi && |
35 option.vendor_id == value.vendor_id; | 32 option.vendor_id == value.vendor_id; |
36 }); | 33 }); |
37 }, | 34 }, |
38 | 35 |
39 /** @override */ | 36 /** @override */ |
40 isCapabilityAvailable: function() { | 37 isCapabilityAvailable: function() { |
41 return !!this.capability && | 38 return !!this.capability && !!this.capability.option && |
42 !!this.capability.option && | 39 this.capability.option.length > 1; |
43 this.capability.option.length > 1; | |
44 }, | 40 }, |
45 | 41 |
46 /** @override */ | 42 /** @override */ |
47 isValueEqual: function(value) { | 43 isValueEqual: function(value) { |
48 var myValue = this.getValue(); | 44 var myValue = this.getValue(); |
49 return myValue.horizontal_dpi == value.horizontal_dpi && | 45 return myValue.horizontal_dpi == value.horizontal_dpi && |
50 myValue.vertical_dpi == value.vertical_dpi && | 46 myValue.vertical_dpi == value.vertical_dpi && |
51 myValue.vendor_id == value.vendor_id; | 47 myValue.vendor_id == value.vendor_id; |
52 }, | 48 }, |
53 | 49 |
54 /** @return {Object} DPI capability of the selected destination. */ | 50 /** @return {Object} DPI capability of the selected destination. */ |
55 get capability() { | 51 get capability() { |
56 var destination = this.getSelectedDestInternal(); | 52 var destination = this.getSelectedDestInternal(); |
57 return (destination && | 53 return (destination && destination.capabilities && |
58 destination.capabilities && | |
59 destination.capabilities.printer && | 54 destination.capabilities.printer && |
60 destination.capabilities.printer.dpi) || | 55 destination.capabilities.printer.dpi) || |
61 null; | 56 null; |
62 }, | 57 }, |
63 | 58 |
64 /** @override */ | 59 /** @override */ |
65 getDefaultValueInternal: function() { | 60 getDefaultValueInternal: function() { |
66 var defaultOptions = this.capability.option.filter(function(option) { | 61 var defaultOptions = this.capability.option.filter(function(option) { |
67 return option.is_default; | 62 return option.is_default; |
68 }); | 63 }); |
69 return defaultOptions.length > 0 ? defaultOptions[0] : null; | 64 return defaultOptions.length > 0 ? defaultOptions[0] : null; |
70 }, | 65 }, |
71 | 66 |
72 /** @override */ | 67 /** @override */ |
73 getCapabilityNotAvailableValueInternal: function() { | 68 getCapabilityNotAvailableValueInternal: function() { |
74 return {}; | 69 return {}; |
75 } | 70 } |
76 }; | 71 }; |
77 | 72 |
78 // Export | 73 // Export |
79 return { | 74 return {Dpi: Dpi}; |
80 Dpi: Dpi | |
81 }; | |
82 }); | 75 }); |
OLD | NEW |