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.SettingsSection}
22 function OtherOptionsSettings(
23 duplex
, fitToPage
, cssBackground
, selectionOnly
, headerFooter
) {
24 print_preview
.SettingsSection
.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
.SettingsSection
.prototype,
136 isAvailable: function() {
137 return this.headerFooterTicketItem_
.isCapabilityAvailable() ||
138 this.fitToPageTicketItem_
.isCapabilityAvailable() ||
139 this.duplexTicketItem_
.isCapabilityAvailable() ||
140 this.cssBackgroundTicketItem_
.isCapabilityAvailable() ||
141 this.selectionOnlyTicketItem_
.isCapabilityAvailable();
145 hasCollapsibleContent: function() {
146 return this.headerFooterTicketItem_
.isCapabilityAvailable() ||
147 this.fitToPageTicketItem_
.isCapabilityAvailable() ||
148 this.cssBackgroundTicketItem_
.isCapabilityAvailable() ||
149 this.selectionOnlyTicketItem_
.isCapabilityAvailable();
153 set isEnabled(isEnabled
) {
154 this.headerFooterCheckbox_
.disabled
= !isEnabled
;
155 this.fitToPageCheckbox_
.disabled
= !isEnabled
;
156 this.duplexCheckbox_
.disabled
= !isEnabled
;
157 this.cssBackgroundCheckbox_
.disabled
= !isEnabled
;
161 enterDocument: function() {
162 print_preview
.SettingsSection
.prototype.enterDocument
.call(this);
164 this.headerFooterCheckbox_
,
166 this.onHeaderFooterCheckboxClick_
.bind(this));
168 this.fitToPageCheckbox_
,
170 this.onFitToPageCheckboxClick_
.bind(this));
172 this.duplexCheckbox_
,
174 this.onDuplexCheckboxClick_
.bind(this));
176 this.cssBackgroundCheckbox_
,
178 this.onCssBackgroundCheckboxClick_
.bind(this));
180 this.selectionOnlyCheckbox_
,
182 this.onSelectionOnlyCheckboxClick_
.bind(this));
184 this.duplexTicketItem_
,
185 print_preview
.ticket_items
.TicketItem
.EventType
.CHANGE
,
186 this.onDuplexChange_
.bind(this));
188 this.fitToPageTicketItem_
,
189 print_preview
.ticket_items
.TicketItem
.EventType
.CHANGE
,
190 this.onFitToPageChange_
.bind(this));
192 this.cssBackgroundTicketItem_
,
193 print_preview
.ticket_items
.TicketItem
.EventType
.CHANGE
,
194 this.onCssBackgroundChange_
.bind(this));
196 this.selectionOnlyTicketItem_
,
197 print_preview
.ticket_items
.TicketItem
.EventType
.CHANGE
,
198 this.onSelectionOnlyChange_
.bind(this));
200 this.headerFooterTicketItem_
,
201 print_preview
.ticket_items
.TicketItem
.EventType
.CHANGE
,
202 this.onHeaderFooterChange_
.bind(this));
206 exitDocument: function() {
207 print_preview
.SettingsSection
.prototype.exitDocument
.call(this);
208 this.headerFooterContainer_
= null;
209 this.headerFooterCheckbox_
= null;
210 this.fitToPageContainer_
= null;
211 this.fitToPageCheckbox_
= null;
212 this.duplexContainer_
= null;
213 this.duplexCheckbox_
= null;
214 this.cssBackgroundContainer_
= null;
215 this.cssBackgroundCheckbox_
= null;
216 this.selectionOnlyContainer_
= null;
217 this.selectionOnlyCheckbox_
= null;
221 decorateInternal: function() {
222 this.headerFooterContainer_
= this.getElement().querySelector(
223 '.header-footer-container');
224 this.headerFooterCheckbox_
= this.headerFooterContainer_
.querySelector(
225 '.header-footer-checkbox');
226 this.fitToPageContainer_
= this.getElement().querySelector(
227 '.fit-to-page-container');
228 this.fitToPageCheckbox_
= this.fitToPageContainer_
.querySelector(
229 '.fit-to-page-checkbox');
230 this.duplexContainer_
= this.getElement().querySelector(
231 '.duplex-container');
232 this.duplexCheckbox_
= this.duplexContainer_
.querySelector(
234 this.cssBackgroundContainer_
= this.getElement().querySelector(
235 '.css-background-container');
236 this.cssBackgroundCheckbox_
= this.cssBackgroundContainer_
.querySelector(
237 '.css-background-checkbox');
238 this.selectionOnlyContainer_
= this.getElement().querySelector(
239 '.selection-only-container');
240 this.selectionOnlyCheckbox_
= this.selectionOnlyContainer_
.querySelector(
241 '.selection-only-checkbox');
245 updateUiStateInternal: function() {
246 if (this.isAvailable()) {
247 setIsVisible(this.headerFooterContainer_
,
248 this.headerFooterTicketItem_
.isCapabilityAvailable() &&
249 !this.collapseContent
);
250 setIsVisible(this.fitToPageContainer_
,
251 this.fitToPageTicketItem_
.isCapabilityAvailable() &&
252 !this.collapseContent
);
253 setIsVisible(this.duplexContainer_
,
254 this.duplexTicketItem_
.isCapabilityAvailable());
255 setIsVisible(this.cssBackgroundContainer_
,
256 this.cssBackgroundTicketItem_
.isCapabilityAvailable() &&
257 !this.collapseContent
);
258 setIsVisible(this.selectionOnlyContainer_
,
259 this.selectionOnlyTicketItem_
.isCapabilityAvailable() &&
260 !this.collapseContent
);
262 print_preview
.SettingsSection
.prototype.updateUiStateInternal
.call(this);
266 isSectionVisibleInternal: function() {
267 return this.collapseContent
?
268 this.duplexTicketItem_
.isCapabilityAvailable() : this.isAvailable();
272 * Called when the header-footer checkbox is clicked. Updates the print
276 onHeaderFooterCheckboxClick_: function() {
277 this.headerFooterTicketItem_
.updateValue(
278 this.headerFooterCheckbox_
.checked
);
282 * Called when the fit-to-page checkbox is clicked. Updates the print
286 onFitToPageCheckboxClick_: function() {
287 this.fitToPageTicketItem_
.updateValue(this.fitToPageCheckbox_
.checked
);
291 * Called when the duplex checkbox is clicked. Updates the print ticket.
294 onDuplexCheckboxClick_: function() {
295 this.duplexTicketItem_
.updateValue(this.duplexCheckbox_
.checked
);
299 * Called when the print CSS backgrounds checkbox is clicked. Updates the
300 * print ticket store.
303 onCssBackgroundCheckboxClick_: function() {
304 this.cssBackgroundTicketItem_
.updateValue(
305 this.cssBackgroundCheckbox_
.checked
);
309 * Called when the print selection only is clicked. Updates the
310 * print ticket store.
313 onSelectionOnlyCheckboxClick_: function() {
314 this.selectionOnlyTicketItem_
.updateValue(
315 this.selectionOnlyCheckbox_
.checked
);
319 * Called when the duplex ticket item has changed. Updates the duplex
323 onDuplexChange_: function() {
324 this.duplexCheckbox_
.checked
= this.duplexTicketItem_
.getValue();
325 this.updateUiStateInternal();
329 * Called when the fit-to-page ticket item has changed. Updates the
330 * fit-to-page checkbox.
333 onFitToPageChange_: function() {
334 this.fitToPageCheckbox_
.checked
= this.fitToPageTicketItem_
.getValue();
335 this.updateUiStateInternal();
339 * Called when the CSS background ticket item has changed. Updates the
340 * CSS background checkbox.
343 onCssBackgroundChange_: function() {
344 this.cssBackgroundCheckbox_
.checked
=
345 this.cssBackgroundTicketItem_
.getValue();
346 this.updateUiStateInternal();
350 * Called when the print selection only ticket item has changed. Updates the
351 * CSS background checkbox.
354 onSelectionOnlyChange_: function() {
355 this.selectionOnlyCheckbox_
.checked
=
356 this.selectionOnlyTicketItem_
.getValue();
357 this.updateUiStateInternal();
361 * Called when the header-footer ticket item has changed. Updates the
362 * header-footer checkbox.
365 onHeaderFooterChange_: function() {
366 this.headerFooterCheckbox_
.checked
=
367 this.headerFooterTicketItem_
.getValue();
368 this.updateUiStateInternal();
374 OtherOptionsSettings
: OtherOptionsSettings