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 * Represents a single option in the Other Options settings section. | 9 * Represents a single option in the Other Options settings section. |
10 * @param {!print_preview.ticket_items.TicketItem} ticketItem The ticket item | 10 * @param {!print_preview.ticket_items.TicketItem} ticketItem The ticket item |
(...skipping 27 matching lines...) Expand all Loading... |
38 * @private {HTMLElement} | 38 * @private {HTMLElement} |
39 */ | 39 */ |
40 this.container_ = null; | 40 this.container_ = null; |
41 | 41 |
42 /** | 42 /** |
43 * The HTML checkbox input element. The checkbox child element of | 43 * The HTML checkbox input element. The checkbox child element of |
44 * container_. Populated when decorate() is called. | 44 * container_. Populated when decorate() is called. |
45 * @private {HTMLElement} | 45 * @private {HTMLElement} |
46 */ | 46 */ |
47 this.checkbox_ = null; | 47 this.checkbox_ = null; |
48 }; | 48 } |
49 | 49 |
50 CheckboxTicketItemElement.prototype = { | 50 CheckboxTicketItemElement.prototype = { |
51 | 51 |
52 /** @return {boolean} Whether the element is collapsible */ | 52 /** @return {boolean} Whether the element is collapsible */ |
53 get collapsible() { | 53 get collapsible() { |
54 return this.collapsible_; | 54 return this.collapsible_; |
55 }, | 55 }, |
56 | 56 |
57 /** | 57 /** |
58 * @return {!print_preview.ticket_items.TicketItem} The ticket item for this | 58 * @return {!print_preview.ticket_items.TicketItem} The ticket item for this |
59 * element. | 59 * element. |
60 */ | 60 */ |
61 get ticketItem() { | 61 get ticketItem() { |
62 return this.ticketItem_; | 62 return this.ticketItem_; |
63 }, | 63 }, |
64 | 64 |
65 /** @return {HTMLElement} The checkbox HTML element. */ | 65 /** @return {HTMLElement} The checkbox HTML element. */ |
66 get checkbox() { | 66 get checkbox() { |
67 return this.checkbox_; | 67 return this.checkbox_; |
68 }, | 68 }, |
69 | 69 |
70 /** Initializes container and checkbox */ | 70 /** Initializes container and checkbox */ |
71 decorate: function() { | 71 decorate: function() { |
72 this.container_ = document.getElementById(this.cssId_); | 72 this.container_ = /** @type {HTMLElement} */( |
73 this.checkbox_ = this.container_.querySelector('.checkbox'); | 73 document.getElementById(this.cssId_)); |
| 74 this.checkbox_ = /** @type {HTMLElement} */( |
| 75 this.container_.querySelector('.checkbox')); |
74 }, | 76 }, |
75 | 77 |
76 /** Resets container and checkbox. */ | 78 /** Resets container and checkbox. */ |
77 exitDocument: function() { | 79 exitDocument: function() { |
78 this.container_ = null; | 80 this.container_ = null; |
79 this.checkbox_ = null; | 81 this.checkbox_ = null; |
80 }, | 82 }, |
81 | 83 |
82 /** Called when the checkbox is clicked. Updates the ticket item value. */ | 84 /** Called when the checkbox is clicked. Updates the ticket item value. */ |
83 onCheckboxClick: function() { | 85 onCheckboxClick: function() { |
84 this.ticketItem_.updateValue(this.checkbox_.checked); | 86 this.ticketItem_.updateValue(this.checkbox_.checked); |
85 }, | 87 }, |
86 | 88 |
87 /** | 89 /** |
88 * Called when the ticket item changes. Updates the UI state. | 90 * Called when the ticket item changes. Updates the UI state. |
89 * @param {!print_preview.SettingsSection.OtherOptionsSettings} | 91 * @param {!print_preview.OtherOptionsSettings} |
90 * otherOptionsSettings The settings section that this element is part | 92 * otherOptionsSettings The settings section that this element is part |
91 * of. | 93 * of. |
92 */ | 94 */ |
93 onTicketItemChange: function(otherOptionsSettings) { | 95 onTicketItemChange: function(otherOptionsSettings) { |
94 this.checkbox_.checked = this.ticketItem_.getValue(); | 96 this.checkbox_.checked = this.ticketItem_.getValue(); |
95 otherOptionsSettings.updateUiStateInternal(); | 97 otherOptionsSettings.updateUiStateInternal(); |
96 }, | 98 }, |
97 | 99 |
98 /** | 100 /** |
99 * @param {boolean} collapseContent Whether the settings section has content | 101 * @param {boolean} collapseContent Whether the settings section has content |
100 * collapsed. | 102 * collapsed. |
101 * @return {boolean} Whether this element should be visible. | 103 * @return {boolean} Whether this element should be visible. |
102 */ | 104 */ |
103 isVisible: function(collapseContent) { | 105 isVisible: function(collapseContent) { |
104 return this.ticketItem_.isCapabilityAvailable() && | 106 return this.ticketItem_.isCapabilityAvailable() && |
105 (!this.collapsible_ || !collapseContent); | 107 (!this.collapsible_ || !collapseContent); |
106 }, | 108 }, |
107 | 109 |
108 /** | 110 /** |
109 * Sets the visibility of the element. | 111 * Sets the visibility of the element. |
110 * @param {boolean} collapseContent Whether the settings section has content | 112 * @param {boolean} collapseContent Whether the settings section has content |
111 * collapsed. | 113 * collapsed. |
112 */ | 114 */ |
113 setVisibility: function(collapseContent) { | 115 setVisibility: function(collapseContent) { |
114 setIsVisible(this.container_, this.isVisible(collapseContent)); | 116 setIsVisible(assert(this.container_), this.isVisible(collapseContent)); |
115 }, | 117 }, |
116 | 118 |
117 }; | 119 }; |
118 | 120 |
119 /** | 121 /** |
120 * UI component that renders checkboxes for various print options. | 122 * UI component that renders checkboxes for various print options. |
121 * @param {!print_preview.ticket_items.Duplex} duplex Duplex ticket item. | 123 * @param {!print_preview.ticket_items.Duplex} duplex Duplex ticket item. |
122 * @param {!print_preview.ticket_items.FitToPage} fitToPage Fit-to-page ticket | 124 * @param {!print_preview.ticket_items.FitToPage} fitToPage Fit-to-page ticket |
123 * item. | 125 * item. |
124 * @param {!print_preview.ticket_items.CssBackground} cssBackground CSS | 126 * @param {!print_preview.ticket_items.CssBackground} cssBackground CSS |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 new CheckboxTicketItemElement(cssBackground, true, | 159 new CheckboxTicketItemElement(cssBackground, true, |
158 'css-background-container'), | 160 'css-background-container'), |
159 new CheckboxTicketItemElement(selectionOnly, true, | 161 new CheckboxTicketItemElement(selectionOnly, true, |
160 'selection-only-container') | 162 'selection-only-container') |
161 ]; | 163 ]; |
162 if (this.rasterizeEnabled_) { | 164 if (this.rasterizeEnabled_) { |
163 this.elements_.splice(4, 0, | 165 this.elements_.splice(4, 0, |
164 new CheckboxTicketItemElement(rasterize, true, | 166 new CheckboxTicketItemElement(rasterize, true, |
165 'rasterize-container')); | 167 'rasterize-container')); |
166 } | 168 } |
167 }; | 169 } |
168 | 170 |
169 OtherOptionsSettings.prototype = { | 171 OtherOptionsSettings.prototype = { |
170 __proto__: print_preview.SettingsSection.prototype, | 172 __proto__: print_preview.SettingsSection.prototype, |
171 | 173 |
172 /** @override */ | 174 /** @override */ |
173 isAvailable: function() { | 175 isAvailable: function() { |
174 return this.elements_.some(function(element) { | 176 return this.elements_.some(function(element) { |
175 return element.ticketItem.isCapabilityAvailable(); | 177 return element.ticketItem.isCapabilityAvailable(); |
176 }); | 178 }); |
177 }, | 179 }, |
(...skipping 13 matching lines...) Expand all Loading... |
191 * other elements. */ | 193 * other elements. */ |
192 for (var i = 0; i < this.elements_.length - 1; i++) | 194 for (var i = 0; i < this.elements_.length - 1; i++) |
193 this.elements_[i].checkbox.disabled = !isEnabled; | 195 this.elements_[i].checkbox.disabled = !isEnabled; |
194 }, | 196 }, |
195 | 197 |
196 /** @override */ | 198 /** @override */ |
197 enterDocument: function() { | 199 enterDocument: function() { |
198 print_preview.SettingsSection.prototype.enterDocument.call(this); | 200 print_preview.SettingsSection.prototype.enterDocument.call(this); |
199 this.elements_.forEach(function(element) { | 201 this.elements_.forEach(function(element) { |
200 this.tracker.add( | 202 this.tracker.add( |
201 element.checkbox, | 203 assert(element.checkbox), |
202 'click', | 204 'click', |
203 element.onCheckboxClick.bind(element)); | 205 element.onCheckboxClick.bind(element)); |
204 this.tracker.add( | 206 this.tracker.add( |
205 element.ticketItem, | 207 element.ticketItem, |
206 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 208 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
207 element.onTicketItemChange.bind(element, this)); | 209 element.onTicketItemChange.bind(element, this)); |
208 }, this); | 210 }, this); |
209 }, | 211 }, |
210 | 212 |
211 /** @override */ | 213 /** @override */ |
(...skipping 26 matching lines...) Expand all Loading... |
238 }, this); | 240 }, this); |
239 }, | 241 }, |
240 | 242 |
241 }; | 243 }; |
242 | 244 |
243 // Export | 245 // Export |
244 return { | 246 return { |
245 OtherOptionsSettings: OtherOptionsSettings | 247 OtherOptionsSettings: OtherOptionsSettings |
246 }; | 248 }; |
247 }); | 249 }); |
OLD | NEW |