[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / browser / resources / print_preview / settings / margin_settings.js
blob2357ea8851c160f0071765551827ad6f840aaf5d
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() {
6 'use strict';
8 /**
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.
13 * @constructor
14 * @extends {print_preview.SettingsSection}
16 function MarginSettings(marginsTypeTicketItem) {
17 print_preview.SettingsSection.call(this);
19 /**
20 * Used to read and write the margins type ticket item.
21 * @type {!print_preview.ticket_items.MarginsType}
22 * @private
24 this.marginsTypeTicketItem_ = marginsTypeTicketItem;
27 /**
28 * CSS classes used by the margin settings component.
29 * @enum {string}
30 * @private
32 MarginSettings.Classes_ = {
33 SELECT: 'margin-settings-select'
36 MarginSettings.prototype = {
37 __proto__: print_preview.SettingsSection.prototype,
39 /** @override */
40 isAvailable: function() {
41 return this.marginsTypeTicketItem_.isCapabilityAvailable();
44 /** @override */
45 hasCollapsibleContent: function() {
46 return this.isAvailable();
49 /** @override */
50 set isEnabled(isEnabled) {
51 this.select_.disabled = !isEnabled;
54 /** @override */
55 enterDocument: function() {
56 print_preview.SettingsSection.prototype.enterDocument.call(this);
57 this.tracker.add(
58 this.select_, 'change', this.onSelectChange_.bind(this));
59 this.tracker.add(
60 this.marginsTypeTicketItem_,
61 print_preview.ticket_items.TicketItem.EventType.CHANGE,
62 this.onMarginsTypeTicketItemChange_.bind(this));
65 /**
66 * @return {HTMLSelectElement} Select element containing the margin options.
67 * @private
69 get select_() {
70 return this.getElement().getElementsByClassName(
71 MarginSettings.Classes_.SELECT)[0];
74 /**
75 * Called when the select element is changed. Updates the print ticket
76 * margin type.
77 * @private
79 onSelectChange_: function() {
80 var select = this.select_;
81 var marginsType =
82 /** @type {!print_preview.ticket_items.MarginsType.Value} */ (
83 select.selectedIndex);
84 this.marginsTypeTicketItem_.updateValue(marginsType);
87 /**
88 * Called when the print ticket store changes. Selects the corresponding
89 * select option.
90 * @private
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();
108 // Export
109 return {
110 MarginSettings: MarginSettings