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);
50 this.portraitRadioButton_,
52 this.onLayoutButtonClick_.bind(this));
54 this.landscapeRadioButton_,
56 this.onLayoutButtonClick_.bind(this));
58 this.landscapeTicketItem_,
59 print_preview.ticket_items.TicketItem.EventType.CHANGE,
60 this.onLandscapeTicketItemChange_.bind(this));
64 * @return {HTMLInputElement} The portrait orientation radio button.
67 get portraitRadioButton_() {
68 return this.getElement().getElementsByClassName(
69 LayoutSettings.Classes_.PORTRAIT_RADIO)[0];
73 * @return {HTMLInputElement} The landscape orientation radio button.
76 get landscapeRadioButton_() {
77 return this.getElement().getElementsByClassName(
78 LayoutSettings.Classes_.LANDSCAPE_RADIO)[0];
82 * Called when one of the radio buttons is clicked. Updates the print ticket
86 onLayoutButtonClick_: function() {
87 this.landscapeTicketItem_.updateValue(this.landscapeRadioButton_.checked);
91 * Called when the print ticket store changes state. Updates the state of
92 * the radio buttons and hides the setting if necessary.
95 onLandscapeTicketItemChange_: function() {
96 if (this.landscapeTicketItem_.isCapabilityAvailable()) {
97 var isLandscapeEnabled = this.landscapeTicketItem_.getValue();
98 this.portraitRadioButton_.checked = !isLandscapeEnabled;
99 this.landscapeRadioButton_.checked = isLandscapeEnabled;
100 fadeInOption(this.getElement());
102 fadeOutOption(this.getElement());
109 LayoutSettings: LayoutSettings