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 MarginSettings object. This object encapsulates all settings and | 9 * Creates a MarginSettings object. This object encapsulates all settings and |
10 * logic related to the margins mode. | 10 * logic related to the margins mode. |
11 * @param {!print_preview.ticket_items.MarginsType} marginsTypeTicketItem Used | 11 * @param {!print_preview.ticket_items.MarginsType} marginsTypeTicketItem Used |
12 * to read and write the margins type ticket item. | 12 * to read and write the margins type ticket item. |
13 * @constructor | 13 * @constructor |
14 * @extends {print_preview.SettingsSection} | 14 * @extends {print_preview.SettingsSection} |
15 */ | 15 */ |
16 function MarginSettings(marginsTypeTicketItem) { | 16 function MarginSettings(marginsTypeTicketItem) { |
17 print_preview.SettingsSection.call(this); | 17 print_preview.SettingsSection.call(this); |
18 | 18 |
19 /** | 19 /** |
20 * Used to read and write the margins type ticket item. | 20 * Used to read and write the margins type ticket item. |
21 * @type {!print_preview.ticket_items.MarginsType} | 21 * @type {!print_preview.ticket_items.MarginsType} |
22 * @private | 22 * @private |
23 */ | 23 */ |
24 this.marginsTypeTicketItem_ = marginsTypeTicketItem; | 24 this.marginsTypeTicketItem_ = marginsTypeTicketItem; |
25 }; | 25 } |
26 | 26 |
27 /** | 27 /** |
28 * CSS classes used by the margin settings component. | 28 * CSS classes used by the margin settings component. |
29 * @enum {string} | 29 * @enum {string} |
30 * @private | 30 * @private |
31 */ | 31 */ |
32 MarginSettings.Classes_ = { | 32 MarginSettings.Classes_ = { |
33 SELECT: 'margin-settings-select' | 33 SELECT: 'margin-settings-select' |
34 }; | 34 }; |
35 | 35 |
(...skipping 12 matching lines...) Expand all Loading... |
48 | 48 |
49 /** @override */ | 49 /** @override */ |
50 set isEnabled(isEnabled) { | 50 set isEnabled(isEnabled) { |
51 this.select_.disabled = !isEnabled; | 51 this.select_.disabled = !isEnabled; |
52 }, | 52 }, |
53 | 53 |
54 /** @override */ | 54 /** @override */ |
55 enterDocument: function() { | 55 enterDocument: function() { |
56 print_preview.SettingsSection.prototype.enterDocument.call(this); | 56 print_preview.SettingsSection.prototype.enterDocument.call(this); |
57 this.tracker.add( | 57 this.tracker.add( |
58 this.select_, 'change', this.onSelectChange_.bind(this)); | 58 assert(this.select_), 'change', this.onSelectChange_.bind(this)); |
59 this.tracker.add( | 59 this.tracker.add( |
60 this.marginsTypeTicketItem_, | 60 this.marginsTypeTicketItem_, |
61 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 61 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
62 this.onMarginsTypeTicketItemChange_.bind(this)); | 62 this.onMarginsTypeTicketItemChange_.bind(this)); |
63 }, | 63 }, |
64 | 64 |
65 /** | 65 /** |
66 * @return {HTMLSelectElement} Select element containing the margin options. | 66 * @return {HTMLSelectElement} Select element containing the margin options. |
67 * @private | 67 * @private |
68 */ | 68 */ |
69 get select_() { | 69 get select_() { |
70 return this.getElement().getElementsByClassName( | 70 return this.getElement().getElementsByClassName( |
71 MarginSettings.Classes_.SELECT)[0]; | 71 MarginSettings.Classes_.SELECT)[0]; |
72 }, | 72 }, |
73 | 73 |
74 /** | 74 /** |
75 * Called when the select element is changed. Updates the print ticket | 75 * Called when the select element is changed. Updates the print ticket |
76 * margin type. | 76 * margin type. |
77 * @private | 77 * @private |
78 */ | 78 */ |
79 onSelectChange_: function() { | 79 onSelectChange_: function() { |
80 var select = this.select_; | 80 var select = this.select_; |
81 var marginsType = | 81 var marginsType = |
82 /** @type {!print_preview.ticket_items.MarginsType.Value} */ ( | 82 /** @type {!print_preview.ticket_items.MarginsTypeValue} */ ( |
83 select.selectedIndex); | 83 select.selectedIndex); |
84 this.marginsTypeTicketItem_.updateValue(marginsType); | 84 this.marginsTypeTicketItem_.updateValue(marginsType); |
85 }, | 85 }, |
86 | 86 |
87 /** | 87 /** |
88 * Called when the print ticket store changes. Selects the corresponding | 88 * Called when the print ticket store changes. Selects the corresponding |
89 * select option. | 89 * select option. |
90 * @private | 90 * @private |
91 */ | 91 */ |
92 onMarginsTypeTicketItemChange_: function() { | 92 onMarginsTypeTicketItemChange_: function() { |
93 if (this.isAvailable()) { | 93 if (this.isAvailable()) { |
94 var select = this.select_; | 94 var select = this.select_; |
95 var marginsType = this.marginsTypeTicketItem_.getValue(); | 95 var marginsType = |
| 96 /** @type {!print_preview.ticket_items.MarginsTypeValue} */ ( |
| 97 this.marginsTypeTicketItem_.getValue()); |
96 var selectedMarginsType = | 98 var selectedMarginsType = |
97 /** @type {!print_preview.ticket_items.MarginsType.Value} */ ( | 99 /** @type {!print_preview.ticket_items.MarginsTypeValue} */ ( |
98 select.selectedIndex); | 100 select.selectedIndex); |
99 if (marginsType != selectedMarginsType) { | 101 if (marginsType != selectedMarginsType) { |
100 select.options[selectedMarginsType].selected = false; | 102 select.options[selectedMarginsType].selected = false; |
101 select.options[marginsType].selected = true; | 103 select.options[marginsType].selected = true; |
102 } | 104 } |
103 } | 105 } |
104 this.updateUiStateInternal(); | 106 this.updateUiStateInternal(); |
105 } | 107 } |
106 }; | 108 }; |
107 | 109 |
108 // Export | 110 // Export |
109 return { | 111 return { |
110 MarginSettings: MarginSettings | 112 MarginSettings: MarginSettings |
111 }; | 113 }; |
112 }); | 114 }); |
OLD | NEW |