OLD | NEW |
---|---|
(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 LayoutSettings object. This object encapsulates all settings and | |
10 * logic related to layout mode (portrait/landscape). | |
11 * | |
12 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the | |
13 * layout written to the print ticket. | |
14 * @constructor | |
15 * @extends {print_preview.Component} | |
16 */ | |
17 function LayoutSettings(printTicketStore) { | |
18 print_preview.Component.call(this); | |
19 | |
20 /** | |
21 * Used to get the layout written to the print ticket. | |
22 * @type {!print_preview.PrintTicketStore} | |
23 * @private | |
24 */ | |
25 this.printTicketStore_ = printTicketStore; | |
26 }; | |
27 | |
28 /** | |
29 * CSS classes used by the layout settings. | |
30 * @enum {string} | |
31 * @private | |
32 */ | |
33 LayoutSettings.Classes_ = { | |
34 LANDSCAPE_RADIO: 'layout-settings-landscape-radio', | |
dpapad
2012/04/24 01:24:56
Why using classes and not id's for unique elements
Robert Toscano
2012/04/24 22:29:56
Using class names will allow the component to be m
| |
35 PORTRAIT_RADIO: 'layout-settings-portrait-radio' | |
36 }; | |
37 | |
38 LayoutSettings.prototype = { | |
39 __proto__: print_preview.Component.prototype, | |
40 | |
41 set isEnabled(isEnabled) { | |
42 this.landscapeRadioButton_.disabled = !isEnabled; | |
43 this.portraitRadioButton_.disabled = !isEnabled; | |
44 }, | |
45 | |
46 /** @override */ | |
47 enterDocument: function() { | |
48 print_preview.Component.prototype.enterDocument.call(this); | |
49 this.addEventListeners_(); | |
50 }, | |
51 | |
52 get portraitRadioButton_() { | |
53 return this.getElement().getElementsByClassName( | |
dpapad
2012/04/24 01:24:56
This could be getElementById() combined with previ
Robert Toscano
2012/04/24 22:29:56
See previous comment.
| |
54 LayoutSettings.Classes_.PORTRAIT_RADIO)[0]; | |
55 }, | |
56 | |
57 get landscapeRadioButton_() { | |
58 return this.getElement().getElementsByClassName( | |
59 LayoutSettings.Classes_.LANDSCAPE_RADIO)[0]; | |
60 }, | |
61 | |
62 /** | |
63 * Adding listeners to all layout related controls. The listeners take care | |
64 * of altering their behavior depending on |hasPendingPreviewRequest|. | |
65 * @private | |
66 */ | |
67 addEventListeners_: function() { | |
68 this.tracker.add( | |
69 this.portraitRadioButton_, | |
70 'click', | |
71 this.onLayoutButtonClick_.bind(this)); | |
72 this.tracker.add( | |
73 this.landscapeRadioButton_, | |
74 'click', | |
75 this.onLayoutButtonClick_.bind(this)); | |
76 this.tracker.add( | |
77 this.printTicketStore_, | |
78 print_preview.PrintTicketStore.DOCUMENT_CHANGE, | |
79 this.onDocumentOrCapabilitiesChange_.bind(this)); | |
80 this.tracker.add( | |
81 this.printTicketStore_, | |
82 print_preview.PrintTicketStore.CAPABILITIES_CHANGE, | |
83 this.onDocumentOrCapabilitiesChange_.bind(this)); | |
84 this.tracker.add( | |
85 this.printTicketStore_, | |
86 print_preview.PrintTicketStore.TICKET_CHANGE, | |
87 this.onTicketChange_); | |
88 }, | |
89 | |
90 /** | |
91 * Called when one of the radio buttons is clicked. Updates the print ticket | |
92 * store. | |
93 * @private | |
94 */ | |
95 onLayoutButtonClick_: function() { | |
96 this.printTicketStore_.updateOrientation( | |
97 this.landscapeRadioButton_.checked); | |
98 }, | |
99 | |
100 onDocumentOrCapabilitiesChange_: function() { | |
101 if (this.printTicketStore_.hasLayoutCapability()) { | |
102 var isLandscapeEnabled = this.printTicketStore_.isLandscapeEnabled(); | |
103 this.portraitRadioButton_.checked = !isLandscapeEnabled; | |
104 this.landscapeRadioButton_.checked = isLandscapeEnabled; | |
105 fadeInOption(this.getElement()); | |
106 } else { | |
107 fadeOutOption(this.getElement()); | |
108 } | |
109 }, | |
110 | |
111 onTicketChange_: function() { | |
112 if (this.printTicketStore_.hasLayoutCapability()) { | |
113 var isLandscapeEnabled = this.printTicketStore_.isLandscapeEnabled(); | |
114 this.portraitRadioButton_.checked = !isLandscapeEnabled; | |
115 this.landscapeRadioButton_.checked = isLandscapeEnabled; | |
116 } | |
117 } | |
118 }; | |
119 | |
120 // Export | |
121 return { | |
122 LayoutSettings: LayoutSettings | |
123 }; | |
124 }); | |
OLD | NEW |