Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1262)

Side by Side Diff: chrome/browser/resources/print_preview/settings/margin_settings.js

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve conflicts Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 cr.define('print_preview', function() {
6 'use strict';
7
8 /**
9 * Creates a MarginSettings object. This object encapsulates all settings and
10 * logic related to the margins mode.
11 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get
12 * ticket margins value.
13 * @constructor
14 * @extends {print_preview.Component}
15 */
16 function MarginSettings(printTicketStore) {
17 print_preview.Component.call(this);
18
19 /**
20 * Used to get ticket margins value.
21 * @type {!print_preview.PrintTicketStore}
22 * @private
23 */
24 this.printTicketStore_ = printTicketStore;
25 };
26
27 /**
28 * CSS classes used by the margin settings component.
29 * @enum {string}
30 * @private
31 */
32 MarginSettings.Classes_ = {
33 SELECT: 'margin-settings-select'
34 };
35
36 MarginSettings.prototype = {
37 __proto__: print_preview.Component.prototype,
38
39 /** @param {boolean} isEnabled Whether this component is enabled. */
40 set isEnabled(isEnabled) {
41 this.select_.disabled = !isEnabled;
42 },
43
44 /** @override */
45 enterDocument: function() {
46 print_preview.Component.prototype.enterDocument.call(this);
47 this.tracker.add(
48 this.select_, 'change', this.onSelectChange_.bind(this));
49 this.tracker.add(
50 this.printTicketStore_,
51 print_preview.PrintTicketStore.EventType.DOCUMENT_CHANGE,
52 this.onPrintTicketStoreChange_.bind(this));
53 this.tracker.add(
54 this.printTicketStore_,
55 print_preview.PrintTicketStore.EventType.TICKET_CHANGE,
56 this.onPrintTicketStoreChange_.bind(this));
57 this.tracker.add(
58 this.printTicketStore_,
59 print_preview.PrintTicketStore.EventType.CAPABILITIES_CHANGE,
60 this.onPrintTicketStoreChange_.bind(this));
61 },
62
63 /**
64 * @return {HTMLSelectElement} Select element containing the margin options.
65 * @private
66 */
67 get select_() {
68 return this.getElement().getElementsByClassName(
69 MarginSettings.Classes_.SELECT)[0];
70 },
71
72 /**
73 * Called when the select element is changed. Updates the print ticket
74 * margin type.
75 * @private
76 */
77 onSelectChange_: function() {
78 var select = this.select_;
79 var marginsType =
80 /** @type {print_preview.ticket_items.MarginsType.Value} */ (
81 select.selectedIndex);
82 this.printTicketStore_.updateMarginsType(marginsType);
83 },
84
85 /**
86 * Called when the print ticket store changes. Selects the corresponding
87 * select option.
88 * @private
89 */
90 onPrintTicketStoreChange_: function() {
91 if (this.printTicketStore_.hasMarginsCapability()) {
92 var select = this.select_;
93 var marginsType = this.printTicketStore_.getMarginsType();
94 var selectedMarginsType =
95 /** @type {print_preview.ticket_items.MarginsType.Value} */ (
96 select.selectedIndex);
97 if (marginsType != selectedMarginsType) {
98 select.options[selectedMarginsType].selected = false;
99 select.options[marginsType].selected = true;
100 }
101 fadeInOption(this.getElement());
102 } else {
103 fadeOutOption(this.getElement());
104 }
105 }
106 };
107
108 // Export
109 return {
110 MarginSettings: MarginSettings
111 };
112 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698