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.SettingsSection}
16 function LayoutSettings(landscapeTicketItem) {
17 print_preview.SettingsSection.call(this);
20 * Used to get the layout written to the print ticket.
21 * @type {!print_preview.ticket_items.Landscape}
24 this.landscapeTicketItem_ = landscapeTicketItem;
27 LayoutSettings.prototype = {
28 __proto__: print_preview.SettingsSection.prototype,
31 isAvailable: function() {
32 return this.landscapeTicketItem_.isCapabilityAvailable();
36 hasCollapsibleContent: function() {
41 set isEnabled(isEnabled) {
42 this.select_.disabled = !isEnabled;
46 enterDocument: function() {
47 print_preview.SettingsSection.prototype.enterDocument.call(this);
49 this.select_, 'change', this.onSelectChange_.bind(this));
51 this.landscapeTicketItem_,
52 print_preview.ticket_items.TicketItem.EventType.CHANGE,
53 this.onLandscapeTicketItemChange_.bind(this));
57 * Called when the select element is changed. Updates the print ticket
61 onSelectChange_: function() {
62 var select = this.select_;
64 select.options[select.selectedIndex].value == 'landscape';
65 this.landscapeTicketItem_.updateValue(isLandscape);
69 * @return {HTMLSelectElement} Select element containing the layout options.
73 return this.getChildElement('.layout-settings-select');
77 * Called when the print ticket store changes state. Updates the state of
78 * the radio buttons and hides the setting if necessary.
81 onLandscapeTicketItemChange_: function() {
82 if (this.isAvailable()) {
83 var select = this.select_;
85 this.landscapeTicketItem_.getValue() ? 'landscape' : 'portrait';
86 for (var i = 0; i < select.options.length; i++) {
87 if (select.options[i].value == valueToSelect) {
88 select.selectedIndex = i;
93 this.updateUiStateInternal();
99 LayoutSettings: LayoutSettings