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 MarginSettings object. This object encapsulates all settings and
10 * logic related to the margins mode.
11 * @param {!print_preview.ticket_items.MarginsType} marginsTypeTicketItem Used
12 * to read and write the margins type ticket item.
14 * @extends {print_preview.SettingsSection}
16 function MarginSettings(marginsTypeTicketItem
) {
17 print_preview
.SettingsSection
.call(this);
20 * Used to read and write the margins type ticket item.
21 * @type {!print_preview.ticket_items.MarginsType}
24 this.marginsTypeTicketItem_
= marginsTypeTicketItem
;
28 * CSS classes used by the margin settings component.
32 MarginSettings
.Classes_
= {
33 SELECT
: 'margin-settings-select'
36 MarginSettings
.prototype = {
37 __proto__
: print_preview
.SettingsSection
.prototype,
40 isAvailable: function() {
41 return this.marginsTypeTicketItem_
.isCapabilityAvailable();
45 hasCollapsibleContent: function() {
46 return this.isAvailable();
50 set isEnabled(isEnabled
) {
51 this.select_
.disabled
= !isEnabled
;
55 enterDocument: function() {
56 print_preview
.SettingsSection
.prototype.enterDocument
.call(this);
58 this.select_
, 'change', this.onSelectChange_
.bind(this));
60 this.marginsTypeTicketItem_
,
61 print_preview
.ticket_items
.TicketItem
.EventType
.CHANGE
,
62 this.onMarginsTypeTicketItemChange_
.bind(this));
66 * @return {HTMLSelectElement} Select element containing the margin options.
70 return this.getElement().getElementsByClassName(
71 MarginSettings
.Classes_
.SELECT
)[0];
75 * Called when the select element is changed. Updates the print ticket
79 onSelectChange_: function() {
80 var select
= this.select_
;
82 /** @type {!print_preview.ticket_items.MarginsType.Value} */ (
83 select
.selectedIndex
);
84 this.marginsTypeTicketItem_
.updateValue(marginsType
);
88 * Called when the print ticket store changes. Selects the corresponding
92 onMarginsTypeTicketItemChange_: function() {
93 if (this.isAvailable()) {
94 var select
= this.select_
;
95 var marginsType
= this.marginsTypeTicketItem_
.getValue();
96 var selectedMarginsType
=
97 /** @type {!print_preview.ticket_items.MarginsType.Value} */ (
98 select
.selectedIndex
);
99 if (marginsType
!= selectedMarginsType
) {
100 select
.options
[selectedMarginsType
].selected
= false;
101 select
.options
[marginsType
].selected
= true;
104 this.updateUiStateInternal();
110 MarginSettings
: MarginSettings