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
3 // found in the LICENSE file.
5 cr.define('print_preview', function() {
9 * UI component that renders checkboxes for various print options.
10 * @param {!print_preview.ticket_items.Duplex} duplex Duplex ticket item.
11 * @param {!print_preview.ticket_items.FitToPage} fitToPage Fit-to-page ticket
13 * @param {!print_preview.ticket_items.CssBackground} cssBackground CSS
14 * background ticket item.
15 * @param {!print_preview.ticket_items.SelectionOnly} selectionOnly Selection
17 * @param {!print_preview.ticket_items.HeaderFooter} headerFooter Header
20 * @extends {print_preview.Component}
22 function OtherOptionsSettings(
23 duplex, fitToPage, cssBackground, selectionOnly, headerFooter) {
24 print_preview.Component.call(this);
27 * Duplex ticket item, used to read/write the duplex selection.
28 * @type {!print_preview.ticket_items.Duplex}
31 this.duplexTicketItem_ = duplex;
34 * Fit-to-page ticket item, used to read/write the fit-to-page selection.
35 * @type {!print_preview.ticket_items.FitToPage}
38 this.fitToPageTicketItem_ = fitToPage;
41 * Enable CSS backgrounds ticket item, used to read/write.
42 * @type {!print_preview.ticket_items.CssBackground}
45 this.cssBackgroundTicketItem_ = cssBackground;
48 * Print selection only ticket item, used to read/write.
49 * @type {!print_preview.ticket_items.SelectionOnly}
52 this.selectionOnlyTicketItem_ = selectionOnly;
55 * Header-footer ticket item, used to read/write.
56 * @type {!print_preview.ticket_items.HeaderFooter}
59 this.headerFooterTicketItem_ = headerFooter;
62 * Header footer container element.
66 this.headerFooterContainer_ = null;
69 * Header footer checkbox.
70 * @type {HTMLInputElement}
73 this.headerFooterCheckbox_ = null;
76 * Fit-to-page container element.
80 this.fitToPageContainer_ = null;
83 * Fit-to-page checkbox.
84 * @type {HTMLInputElement}
87 this.fitToPageCheckbox_ = null;
90 * Duplex container element.
94 this.duplexContainer_ = null;
98 * @type {HTMLInputElement}
101 this.duplexCheckbox_ = null;
104 * Print CSS backgrounds container element.
105 * @type {HTMLElement}
108 this.cssBackgroundContainer_ = null;
111 * Print CSS backgrounds checkbox.
112 * @type {HTMLInputElement}
115 this.cssBackgroundCheckbox_ = null;
118 * Print selection only container element.
119 * @type {HTMLElement}
122 this.selectionOnlyContainer_ = null;
125 * Print selection only checkbox.
126 * @type {HTMLInputElement}
129 this.selectionOnlyCheckbox_ = null;
132 OtherOptionsSettings.prototype = {
133 __proto__: print_preview.Component.prototype,
135 /** @param {boolean} isEnabled Whether the settings is enabled. */
136 set isEnabled(isEnabled) {
137 this.headerFooterCheckbox_.disabled = !isEnabled;
138 this.fitToPageCheckbox_.disabled = !isEnabled;
139 this.duplexCheckbox_.disabled = !isEnabled;
140 this.cssBackgroundCheckbox_.disabled = !isEnabled;
144 enterDocument: function() {
145 print_preview.Component.prototype.enterDocument.call(this);
147 this.headerFooterCheckbox_,
149 this.onHeaderFooterCheckboxClick_.bind(this));
151 this.fitToPageCheckbox_,
153 this.onFitToPageCheckboxClick_.bind(this));
155 this.duplexCheckbox_,
157 this.onDuplexCheckboxClick_.bind(this));
159 this.cssBackgroundCheckbox_,
161 this.onCssBackgroundCheckboxClick_.bind(this));
163 this.selectionOnlyCheckbox_,
165 this.onSelectionOnlyCheckboxClick_.bind(this));
167 this.duplexTicketItem_,
168 print_preview.ticket_items.TicketItem.EventType.CHANGE,
169 this.onDuplexChange_.bind(this));
171 this.fitToPageTicketItem_,
172 print_preview.ticket_items.TicketItem.EventType.CHANGE,
173 this.onFitToPageChange_.bind(this));
175 this.cssBackgroundTicketItem_,
176 print_preview.ticket_items.TicketItem.EventType.CHANGE,
177 this.onCssBackgroundChange_.bind(this));
179 this.selectionOnlyTicketItem_,
180 print_preview.ticket_items.TicketItem.EventType.CHANGE,
181 this.onSelectionOnlyChange_.bind(this));
183 this.headerFooterTicketItem_,
184 print_preview.ticket_items.TicketItem.EventType.CHANGE,
185 this.onHeaderFooterChange_.bind(this));
189 exitDocument: function() {
190 print_preview.Component.prototype.exitDocument.call(this);
191 this.headerFooterContainer_ = null;
192 this.headerFooterCheckbox_ = null;
193 this.fitToPageContainer_ = null;
194 this.fitToPageCheckbox_ = null;
195 this.duplexContainer_ = null;
196 this.duplexCheckbox_ = null;
197 this.cssBackgroundContainer_ = null;
198 this.cssBackgroundCheckbox_ = null;
199 this.selectionOnlyContainer_ = null;
200 this.selectionOnlyCheckbox_ = null;
204 decorateInternal: function() {
205 this.headerFooterContainer_ = this.getElement().querySelector(
206 '.header-footer-container');
207 this.headerFooterCheckbox_ = this.headerFooterContainer_.querySelector(
208 '.header-footer-checkbox');
209 this.fitToPageContainer_ = this.getElement().querySelector(
210 '.fit-to-page-container');
211 this.fitToPageCheckbox_ = this.fitToPageContainer_.querySelector(
212 '.fit-to-page-checkbox');
213 this.duplexContainer_ = this.getElement().querySelector(
214 '.duplex-container');
215 this.duplexCheckbox_ = this.duplexContainer_.querySelector(
217 this.cssBackgroundContainer_ = this.getElement().querySelector(
218 '.css-background-container');
219 this.cssBackgroundCheckbox_ = this.cssBackgroundContainer_.querySelector(
220 '.css-background-checkbox');
221 this.selectionOnlyContainer_ = this.getElement().querySelector(
222 '.selection-only-container');
223 this.selectionOnlyCheckbox_ = this.selectionOnlyContainer_.querySelector(
224 '.selection-only-checkbox');
228 * Updates the state of the entire other options settings area.
231 updateContainerState_: function() {
232 if (this.headerFooterTicketItem_.isCapabilityAvailable() ||
233 this.fitToPageTicketItem_.isCapabilityAvailable() ||
234 this.duplexTicketItem_.isCapabilityAvailable() ||
235 this.cssBackgroundTicketItem_.isCapabilityAvailable() ||
236 this.selectionOnlyTicketItem_.isCapabilityAvailable()) {
237 fadeInOption(this.getElement());
239 fadeOutOption(this.getElement());
244 * Called when the header-footer checkbox is clicked. Updates the print
248 onHeaderFooterCheckboxClick_: function() {
249 this.headerFooterTicketItem_.updateValue(
250 this.headerFooterCheckbox_.checked);
254 * Called when the fit-to-page checkbox is clicked. Updates the print
258 onFitToPageCheckboxClick_: function() {
259 this.fitToPageTicketItem_.updateValue(this.fitToPageCheckbox_.checked);
263 * Called when the duplex checkbox is clicked. Updates the print ticket.
266 onDuplexCheckboxClick_: function() {
267 this.duplexTicketItem_.updateValue(this.duplexCheckbox_.checked);
271 * Called when the print CSS backgrounds checkbox is clicked. Updates the
272 * print ticket store.
275 onCssBackgroundCheckboxClick_: function() {
276 this.cssBackgroundTicketItem_.updateValue(
277 this.cssBackgroundCheckbox_.checked);
281 * Called when the print selection only is clicked. Updates the
282 * print ticket store.
285 onSelectionOnlyCheckboxClick_: function() {
286 this.selectionOnlyTicketItem_.updateValue(
287 this.selectionOnlyCheckbox_.checked);
291 * Called when the duplex ticket item has changed. Updates the duplex
295 onDuplexChange_: function() {
296 setIsVisible(this.duplexContainer_,
297 this.duplexTicketItem_.isCapabilityAvailable());
298 this.duplexCheckbox_.checked = this.duplexTicketItem_.getValue();
299 this.updateContainerState_();
303 * Called when the fit-to-page ticket item has changed. Updates the
304 * fit-to-page checkbox.
307 onFitToPageChange_: function() {
308 setIsVisible(this.fitToPageContainer_,
309 this.fitToPageTicketItem_.isCapabilityAvailable());
310 this.fitToPageCheckbox_.checked = this.fitToPageTicketItem_.getValue();
311 this.updateContainerState_();
315 * Called when the CSS background ticket item has changed. Updates the
316 * CSS background checkbox.
319 onCssBackgroundChange_: function() {
320 setIsVisible(this.cssBackgroundContainer_,
321 this.cssBackgroundTicketItem_.isCapabilityAvailable());
322 this.cssBackgroundCheckbox_.checked =
323 this.cssBackgroundTicketItem_.getValue();
324 this.updateContainerState_();
328 * Called when the print selection only ticket item has changed. Updates the
329 * CSS background checkbox.
332 onSelectionOnlyChange_: function() {
333 setIsVisible(this.selectionOnlyContainer_,
334 this.selectionOnlyTicketItem_.isCapabilityAvailable());
335 this.selectionOnlyCheckbox_.checked =
336 this.selectionOnlyTicketItem_.getValue();
337 this.updateContainerState_();
341 * Called when the header-footer ticket item has changed. Updates the
342 * header-footer checkbox.
345 onHeaderFooterChange_: function() {
346 setIsVisible(this.headerFooterContainer_,
347 this.headerFooterTicketItem_.isCapabilityAvailable());
348 this.headerFooterCheckbox_.checked =
349 this.headerFooterTicketItem_.getValue();
350 this.updateContainerState_();
356 OtherOptionsSettings: OtherOptionsSettings