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 * Creates a LayoutSettings object. This object encapsulates all settings and | 9 * Creates a LayoutSettings object. This object encapsulates all settings and |
10 * logic related to layout mode (portrait/landscape). | 10 * logic related to layout mode (portrait/landscape). |
11 * @param {!print_preview.ticket_items.Landscape} landscapeTicketItem Used to | 11 * @param {!print_preview.ticket_items.Landscape} landscapeTicketItem Used to |
12 * get the layout written to the print ticket. | 12 * get the layout written to the print ticket. |
13 * @constructor | 13 * @constructor |
14 * @extends {print_preview.SettingsSection} | 14 * @extends {print_preview.SettingsSection} |
15 */ | 15 */ |
16 function LayoutSettings(landscapeTicketItem) { | 16 function LayoutSettings(landscapeTicketItem) { |
17 print_preview.SettingsSection.call(this); | 17 print_preview.SettingsSection.call(this); |
18 | 18 |
19 /** | 19 /** |
20 * Used to get the layout written to the print ticket. | 20 * Used to get the layout written to the print ticket. |
21 * @type {!print_preview.ticket_items.Landscape} | 21 * @type {!print_preview.ticket_items.Landscape} |
22 * @private | 22 * @private |
23 */ | 23 */ |
24 this.landscapeTicketItem_ = landscapeTicketItem; | 24 this.landscapeTicketItem_ = landscapeTicketItem; |
25 }; | 25 } |
26 | 26 |
27 LayoutSettings.prototype = { | 27 LayoutSettings.prototype = { |
28 __proto__: print_preview.SettingsSection.prototype, | 28 __proto__: print_preview.SettingsSection.prototype, |
29 | 29 |
30 /** @override */ | 30 /** @override */ |
31 isAvailable: function() { | 31 isAvailable: function() { |
32 return this.landscapeTicketItem_.isCapabilityAvailable(); | 32 return this.landscapeTicketItem_.isCapabilityAvailable(); |
33 }, | 33 }, |
34 | 34 |
35 /** @override */ | 35 /** @override */ |
36 hasCollapsibleContent: function() { | 36 hasCollapsibleContent: function() { |
37 return false; | 37 return false; |
38 }, | 38 }, |
39 | 39 |
40 /** @override */ | 40 /** @override */ |
41 set isEnabled(isEnabled) { | 41 set isEnabled(isEnabled) { |
42 this.select_.disabled = !isEnabled; | 42 this.select_.disabled = !isEnabled; |
43 }, | 43 }, |
44 | 44 |
45 /** @override */ | 45 /** @override */ |
46 enterDocument: function() { | 46 enterDocument: function() { |
47 print_preview.SettingsSection.prototype.enterDocument.call(this); | 47 print_preview.SettingsSection.prototype.enterDocument.call(this); |
48 this.tracker.add( | 48 this.tracker.add( |
49 this.select_, 'change', this.onSelectChange_.bind(this)); | 49 assert(this.select_), 'change', this.onSelectChange_.bind(this)); |
50 this.tracker.add( | 50 this.tracker.add( |
51 this.landscapeTicketItem_, | 51 this.landscapeTicketItem_, |
52 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 52 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
53 this.onLandscapeTicketItemChange_.bind(this)); | 53 this.onLandscapeTicketItemChange_.bind(this)); |
54 }, | 54 }, |
55 | 55 |
56 /** | 56 /** |
57 * Called when the select element is changed. Updates the print ticket | 57 * Called when the select element is changed. Updates the print ticket |
58 * layout selection. | 58 * layout selection. |
59 * @private | 59 * @private |
60 */ | 60 */ |
61 onSelectChange_: function() { | 61 onSelectChange_: function() { |
62 var select = this.select_; | 62 var select = this.select_; |
63 var isLandscape = | 63 var isLandscape = |
64 select.options[select.selectedIndex].value == 'landscape'; | 64 select.options[select.selectedIndex].value == 'landscape'; |
65 this.landscapeTicketItem_.updateValue(isLandscape); | 65 this.landscapeTicketItem_.updateValue(isLandscape); |
66 }, | 66 }, |
67 | 67 |
68 /** | 68 /** |
69 * @return {HTMLSelectElement} Select element containing the layout options. | 69 * @return {HTMLSelectElement} Select element containing the layout options. |
70 * @private | 70 * @private |
71 */ | 71 */ |
72 get select_() { | 72 get select_() { |
73 return this.getChildElement('.layout-settings-select'); | 73 return /** @type {HTMLSelectElement} */( |
| 74 this.getChildElement('.layout-settings-select')); |
74 }, | 75 }, |
75 | 76 |
76 /** | 77 /** |
77 * Called when the print ticket store changes state. Updates the state of | 78 * Called when the print ticket store changes state. Updates the state of |
78 * the radio buttons and hides the setting if necessary. | 79 * the radio buttons and hides the setting if necessary. |
79 * @private | 80 * @private |
80 */ | 81 */ |
81 onLandscapeTicketItemChange_: function() { | 82 onLandscapeTicketItemChange_: function() { |
82 if (this.isAvailable()) { | 83 if (this.isAvailable()) { |
83 var select = this.select_; | 84 var select = this.select_; |
84 var valueToSelect = | 85 var valueToSelect = |
85 this.landscapeTicketItem_.getValue() ? 'landscape' : 'portrait'; | 86 this.landscapeTicketItem_.getValue() ? 'landscape' : 'portrait'; |
86 for (var i = 0; i < select.options.length; i++) { | 87 for (var i = 0; i < select.options.length; i++) { |
87 if (select.options[i].value == valueToSelect) { | 88 if (select.options[i].value == valueToSelect) { |
88 select.selectedIndex = i; | 89 select.selectedIndex = i; |
89 break; | 90 break; |
90 } | 91 } |
91 } | 92 } |
92 } | 93 } |
93 this.updateUiStateInternal(); | 94 this.updateUiStateInternal(); |
94 } | 95 } |
95 }; | 96 }; |
96 | 97 |
97 // Export | 98 // Export |
98 return { | 99 return { |
99 LayoutSettings: LayoutSettings | 100 LayoutSettings: LayoutSettings |
100 }; | 101 }; |
101 }); | 102 }); |
OLD | NEW |