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

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

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback Created 8 years, 8 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 HeaderFooterSettings object. This object encapsulates all
10 * settings and logic related to the headers and footers checkbox.
11 *
12 * @param {!print_preview.PrintTicketStore} printTicketStore Used to monitor
13 * the state of the print ticket.
14 * @constructor
15 * @extends {print_preview.Component}
16 */
17 function HeaderFooterSettings(printTicketStore) {
18 print_preview.Component.call(this);
19
20 /**
21 * Used to monitor the state of the print ticket.
22 * @type {!print_preview.PrintTicketStore}
23 * @private
24 */
25 this.printTicketStore_ = printTicketStore;
26 };
27
28 /**
29 * CSS classes used by the header footer settings.
30 * @enum {string}
31 * @private
32 */
33 HeaderFooterSettings.Classes_ = {
34 CHECKBOX: 'header-footer-settings-checkbox'
35 };
36
37 HeaderFooterSettings.prototype = {
38 __proto__: print_preview.Component.prototype,
39
40 set isEnabled(isEnabled) {
41 this.checkbox_.disabled = !isEnabled;
42 },
43
44 /** @override */
45 enterDocument: function() {
46 print_preview.Component.prototype.enterDocument.call(this);
47 this.addEventListeners_();
48 },
49
50 /**
51 * @return {HTMLInputElement} The header-footer checkbox element.
52 * @private
53 */
54 get checkbox_() {
55 return this.getElement().getElementsByClassName(
56 HeaderFooterSettings.Classes_.CHECKBOX)[0];
57 },
58
59 /**
60 * Adding listeners to header footer related controls.
61 * @private
62 */
63 addEventListeners_: function() {
64 this.tracker.add(
65 this.checkbox_, 'click', this.onCheckboxClick_.bind(this));
66 this.tracker.add(
67 this.printTicketStore_,
68 print_preview.PrintTicketStore.Event.DOCUMENT_CHANGE,
69 this.onPrintTicketStoreChange_.bind(this));
70 this.tracker.add(
71 this.printTicketStore_,
72 print_preview.PrintTicketStore.Event.CAPABILITIES_CHANGE,
73 this.onPrintTicketStoreChange_.bind(this));
74 this.tracker.add(
75 this.printTicketStore_,
76 print_preview.PrintTicketStore.Event.TICKET_CHANGE,
77 this.onPrintTicketStoreChange_.bind(this));
78 },
79
80 /**
81 * Called when the checkbox is clicked. Updates the print ticket.
82 * @private
83 */
84 onCheckboxClick_: function() {
85 this.printTicketStore_.updateHeaderFooter(this.checkbox_.checked);
86 },
87
88 /**
89 * Called when the print ticket store has changed. Hides or shows the
90 * setting.
91 * @private
92 */
93 onPrintTicketStoreChange_: function() {
94 if (this.printTicketStore_.hasHeaderFooterCapability()) {
95 this.checkbox_.checked = this.printTicketStore_.isHeaderFooterEnabled();
96 fadeInOption(this.getElement());
97 } else {
98 fadeOutOption(this.getElement());
99 }
100 }
101 };
102
103 // Export
104 return {
105 HeaderFooterSettings: HeaderFooterSettings
106 };
107 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698