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

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

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix fit-to-page tests 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 * UI component that renders checkboxes for various print options.
10 * @param {!print_preview.PrintTicketStore} printTicketStore Used to monitor
11 * the state of the print ticket.
12 * @constructor
13 * @extends {print_preview.Component}
14 */
15 function OtherOptionsSettings(printTicketStore) {
16 print_preview.Component.call(this);
17
18 /**
19 * Used to monitor the state of the print ticket.
20 * @type {!print_preview.PrintTicketStore}
21 * @private
22 */
23 this.printTicketStore_ = printTicketStore;
24
25 /**
26 * Header footer container element.
27 * @type {HTMLElement}
28 * @private
29 */
30 this.headerFooterEl_ = null;
31
32 /**
33 * Header footer checkbox.
34 * @type {HTMLInputElement}
35 * @private
36 */
37 this.headerFooterCheckbox_ = null;
38
39 /**
40 * Fit-to-page container element.
41 * @type {HTMLElement}
42 * @private
43 */
44 this.fitToPageEl_ = null;
45
46 /**
47 * Fit-to-page checkbox.
48 * @type {HTMLInputElement}
49 * @private
50 */
51 this.fitToPageCheckbox_ = null;
52 };
53
54 /**
55 * CSS classes used by the other options component.
56 * @enum {string}
57 * @private
58 */
59 OtherOptionsSettings.Classes_ = {
60 FIT_TO_PAGE: 'other-options-settings-fit-to-page',
61 FIT_TO_PAGE_CHECKBOX: 'other-options-settings-fit-to-page-checkbox',
62 HEADER_FOOTER: 'other-options-settings-header-footer',
63 HEADER_FOOTER_CHECKBOX: 'other-options-settings-header-footer-checkbox'
64 };
65
66 OtherOptionsSettings.prototype = {
67 __proto__: print_preview.Component.prototype,
68
69 set isEnabled(isEnabled) {
70 this.headerFooterCheckbox_.disabled = !isEnabled;
71 this.fitToPageCheckbox_.disabled = !isEnabled;
72 },
73
74 /** @override */
75 enterDocument: function() {
76 print_preview.Component.prototype.enterDocument.call(this);
77 this.tracker.add(
78 this.headerFooterCheckbox_,
79 'click',
80 this.onHeaderFooterCheckboxClick_.bind(this));
81 this.tracker.add(
82 this.fitToPageCheckbox_,
83 'click',
84 this.onFitToPageCheckboxClick_.bind(this));
85 this.tracker.add(
86 this.printTicketStore_,
87 print_preview.PrintTicketStore.EventType.INITIALIZE,
88 this.onPrintTicketStoreChange_.bind(this));
89 this.tracker.add(
90 this.printTicketStore_,
91 print_preview.PrintTicketStore.EventType.DOCUMENT_CHANGE,
92 this.onPrintTicketStoreChange_.bind(this));
93 this.tracker.add(
94 this.printTicketStore_,
95 print_preview.PrintTicketStore.EventType.CAPABILITIES_CHANGE,
96 this.onPrintTicketStoreChange_.bind(this));
97 this.tracker.add(
98 this.printTicketStore_,
99 print_preview.PrintTicketStore.EventType.TICKET_CHANGE,
100 this.onPrintTicketStoreChange_.bind(this));
101 },
102
103 /** @override */
104 exitDocument: function() {
105 print_preview.Component.prototype.exitDocument.call(this);
106 this.headerFooterEl_ = null;
107 this.headerFooterCheckbox_ = null;
108 this.fitToPageEl_ = null;
109 this.fitToPageCheckbox_ = null;
110 },
111
112 /** @override */
113 decorateInternal: function() {
114 this.headerFooterEl_ = this.getElement().getElementsByClassName(
115 OtherOptionsSettings.Classes_.HEADER_FOOTER)[0];
116 this.headerFooterCheckbox_ = this.getElement().getElementsByClassName(
117 OtherOptionsSettings.Classes_.HEADER_FOOTER_CHECKBOX)[0];
118 this.fitToPageEl_ = this.getElement().getElementsByClassName(
119 OtherOptionsSettings.Classes_.FIT_TO_PAGE)[0];
120 this.fitToPageCheckbox_ = this.getElement().getElementsByClassName(
121 OtherOptionsSettings.Classes_.FIT_TO_PAGE_CHECKBOX)[0];
122 },
123
124 /**
125 * Called when the header-footer checkbox is clicked. Updates the print
126 * ticket.
127 * @private
128 */
129 onHeaderFooterCheckboxClick_: function() {
130 this.printTicketStore_.updateHeaderFooter(
131 this.headerFooterCheckbox_.checked);
132 },
133
134 /**
135 * Called when the fit-to-page checkbox is clicked. Updates the print
136 * ticket.
137 * @private
138 */
139 onFitToPageCheckboxClick_: function() {
140 this.printTicketStore_.updateFitToPage(
141 this.fitToPageCheckbox_.checked);
142 },
143
144 /**
145 * Called when the print ticket store has changed. Hides or shows the
146 * setting.
147 * @private
148 */
149 onPrintTicketStoreChange_: function() {
150 setIsVisible(
151 this.headerFooterEl_,
152 this.printTicketStore_.hasHeaderFooterCapability());
153 this.headerFooterCheckbox_.checked =
154 this.printTicketStore_.isHeaderFooterEnabled();
155 setIsVisible(
156 this.fitToPageEl_, this.printTicketStore_.hasFitToPageCapability());
kmadhusu 2012/05/18 20:13:46 nit: First argument can fit in the first line. Ple
157 this.fitToPageCheckbox_.checked =
158 this.printTicketStore_.isFitToPageEnabled();
159
160 if (this.printTicketStore_.hasHeaderFooterCapability() ||
161 this.printTicketStore_.hasFitToPageCapability()) {
162 fadeInOption(this.getElement());
163 } else {
164 fadeOutOption(this.getElement());
165 }
166 }
167 };
168
169 // Export
170 return {
171 OtherOptionsSettings: OtherOptionsSettings
172 };
173 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698