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 * Creates a LayoutSettings object. This object encapsulates all settings and
10 * logic related to layout mode (portrait/landscape).
11 * @param {!print_preview.ticket_items.Landscape} landscapeTicketItem Used to
12 * get the layout written to the print ticket.
14 * @extends {print_preview.Component}
16 function LayoutSettings(landscapeTicketItem) {
17 print_preview.Component.call(this);
20 * Used to get the layout written to the print ticket.
21 * @type {!print_preview.ticket_items.Landscape}
24 this.landscapeTicketItem_ = landscapeTicketItem;
28 * CSS classes used by the layout settings.
32 LayoutSettings.Classes_ = {
33 LANDSCAPE_RADIO: 'layout-settings-landscape-radio',
34 PORTRAIT_RADIO: 'layout-settings-portrait-radio'
37 LayoutSettings.prototype = {
38 __proto__: print_preview.Component.prototype,
40 /** @param {boolean} isEnabled Whether this component is enabled. */
41 set isEnabled(isEnabled) {
42 this.landscapeRadioButton_.disabled = !isEnabled;
43 this.portraitRadioButton_.disabled = !isEnabled;
47 enterDocument: function() {
48 print_preview.Component.prototype.enterDocument.call(this);
49 fadeOutOption(this.getElement(), true);
51 this.portraitRadioButton_,
53 this.onLayoutButtonClick_.bind(this));
55 this.landscapeRadioButton_,
57 this.onLayoutButtonClick_.bind(this));
59 this.landscapeTicketItem_,
60 print_preview.ticket_items.TicketItem.EventType.CHANGE,
61 this.onLandscapeTicketItemChange_.bind(this));
65 * @return {HTMLInputElement} The portrait orientation radio button.
68 get portraitRadioButton_() {
69 return this.getElement().getElementsByClassName(
70 LayoutSettings.Classes_.PORTRAIT_RADIO)[0];
74 * @return {HTMLInputElement} The landscape orientation radio button.
77 get landscapeRadioButton_() {
78 return this.getElement().getElementsByClassName(
79 LayoutSettings.Classes_.LANDSCAPE_RADIO)[0];
83 * Called when one of the radio buttons is clicked. Updates the print ticket
87 onLayoutButtonClick_: function() {
88 this.landscapeTicketItem_.updateValue(this.landscapeRadioButton_.checked);
92 * Called when the print ticket store changes state. Updates the state of
93 * the radio buttons and hides the setting if necessary.
96 onLandscapeTicketItemChange_: function() {
97 if (this.landscapeTicketItem_.isCapabilityAvailable()) {
98 var isLandscapeEnabled = this.landscapeTicketItem_.getValue();
99 this.portraitRadioButton_.checked = !isLandscapeEnabled;
100 this.landscapeRadioButton_.checked = isLandscapeEnabled;
101 fadeInOption(this.getElement());
103 fadeOutOption(this.getElement());
110 LayoutSettings: LayoutSettings