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

Side by Side Diff: chrome/browser/resources/help/channel_change_page.js

Issue 17437004: Implemented new channel switcher UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 7 years, 6 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) 2013 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('help', function() {
6 /**
7 * Encapsulated handling of the channel change overlay.
8 */
9 function ChannelChangePage() {}
10
11 cr.addSingletonGetter(ChannelChangePage);
12
13 ChannelChangePage.prototype = {
14 __proto__: HTMLDivElement.prototype,
15
16 /**
17 * Name of the channel the device is currently on.
18 * @private
19 */
20 currentChannel_: null,
21
22 /**
23 * Name of the channel the device is supposed to be.
James Hawkins 2013/06/24 18:13:12 "be on."?
ygorshenin1 2013/06/24 18:35:31 Done.
24 * @private
25 */
26 targetChannel_: null,
27
28 /**
29 * True if the device is enterprise-managed, false otherwise.
James Hawkins 2013/06/24 18:13:12 Optional nit: ", false otherwise" is superfluous.
ygorshenin1 2013/06/24 18:35:31 Done.
30 * @private
31 */
32 isEnterpriseManaged_: undefined,
33
34 /**
35 * List of the channels names, from the least stable to the most stable.
36 * @private
37 */
38 channelList_: ['dev-channel', 'beta-channel', 'stable-channel'],
39
40 /**
41 * List of the possible ui states.
42 * @private
43 */
44 uiClassTable_: ['selected-channel-requires-powerwash',
45 'selected-channel-requires-delayed-update',
46 'selected-channel-good',
47 'selected-channel-unstable'],
48
49 /**
50 * Perform initial setup.
51 */
52 initialize: function() {
53 var self = this;
54
55 $('channel-change-page-cancel-button').onclick = function() {
56 help.HelpPage.cancelOverlay();
57 };
58
59 var options = this.getAllChannelOptions_();
60 for (var i = 0; i < options.length; i++) {
61 var option = options[i];
62 option.onclick = function() {
63 self.updateUI_(this.value);
64 };
65 }
66
67 $('channel-change-page-powerwash-button').onclick = function() {
68 self.setChannel_(self.getSelectedOption_(), true);
69 help.HelpPage.cancelOverlay();
70 };
71
72 $('channel-change-page-change-button').onclick = function() {
73 self.setChannel_(self.getSelectedOption_(), false);
74 help.HelpPage.cancelOverlay();
75 };
76 },
77
78 /**
79 * Returns the list of all radio buttons responsible for channel selection.
80 * @return {Array.<HTMLInputElement>} Array of radio buttons
81 * @private
82 */
83 getAllChannelOptions_: function() {
84 return $('channel-change-page').querySelectorAll('input[type="radio"]');
85 },
86
87 /**
88 * Returns value of the selected option.
89 * @return {string} Selected channel name or null, if neither
90 * option is selected.
91 * @private
92 */
93 getSelectedOption_: function() {
94 var options = this.getAllChannelOptions_();
95 for (var i = 0; i < options.length; i++) {
96 var option = options[i];
97 if (option.checked)
98 return option.value;
99 }
100 return null;
101 },
102
103 /**
104 * Updates UI according to selected channel.
105 * @param {string} selectedChannel Selected channel
106 * @private
107 */
108 updateUI_: function(selectedChannel) {
109 var currentStability = this.channelList_.indexOf(this.currentChannel_);
110 var newStability = this.channelList_.indexOf(selectedChannel);
111
112 var newOverlayClass = null;
113
114 if (selectedChannel == this.currentChannel_) {
115 if (this.currentChannel_ != this.targetChannel_) {
116 // Allow user to switch back to the current channel.
117 newOverlayClass = 'selected-channel-good';
118 }
119 } else if (selectedChannel == this.targetChannel_) {
120 // Do nothing in this case.
James Hawkins 2013/06/24 18:13:12 Why have the case listed if nothing is to be done?
ygorshenin1 2013/06/24 18:35:31 Done.
121 } else {
122 // Selected channel isn't equal to the current and target channel.
123 if (newStability > currentStability) {
124 // More stable channel is selected. For customer devices
125 // notify user about powerwash.
126 if (this.isEnterpriseManaged_)
127 newOverlayClass = 'selected-channel-requires-delayed-update';
128 else
129 newOverlayClass = 'selected-channel-requires-powerwash';
130 } else if (selectedChannel == 'dev-channel') {
131 // Warn user about unstable channel.
132 newOverlayClass = 'selected-channel-unstable';
133 } else {
134 // Switching to the less stable channel.
135 newOverlayClass = 'selected-channel-good';
136 }
137 }
138
139 // Switch to the new UI state.
140 for (var i = 0; i < this.uiClassTable_.length; i++)
141 $('channel-change-page').classList.remove(this.uiClassTable_[i]);
142 if (newOverlayClass)
James Hawkins 2013/06/24 18:13:12 Optional nit: Blank lines between blocks to increa
ygorshenin1 2013/06/24 18:35:31 Done.
143 $('channel-change-page').classList.add(newOverlayClass);
144 },
145
146 /**
147 * Sets the device target channel.
148 * @param {string} channel The name of the target channel
149 * @param {boolean} isPowerwashAllowed True iff powerwash is allowed
150 * @private
151 */
152 setChannel_: function(channel, isPowerwashAllowed) {
153 this.targetChannel_ = channel;
154 this.updateUI_(channel);
155 help.HelpPage.setChannel(channel, isPowerwashAllowed);
156 },
157
158 /**
159 * Updates page UI according to device owhership policy.
160 * @param {boolean} isEnterpriseManaged True if the device is
161 * enterprise managed
162 * @private
163 */
164 updateIsEnterpriseManaged_: function(isEnterpriseManaged) {
165 this.isEnterpriseManaged_ = isEnterpriseManaged;
166 help.HelpPage.updateChannelChangePageContainerVisibility();
167 },
168
169 /**
170 * Updates name of the current channel, i.e. the name of the
171 * channel the device is currently on.
172 * @param {string} channel The name of the current channel
173 * @private
174 */
175 updateCurrentChannel_: function(channel) {
176 if (this.channelList_.indexOf(channel) < 0)
177 return;
178 this.currentChannel_ = channel;
179
180 var options = this.getAllChannelOptions_();
181 for (var i = 0; i < options.length; i++) {
182 var option = options[i];
183 if (option.value == channel)
184 option.checked = true;
185 }
186 help.HelpPage.updateChannelChangePageContainerVisibility();
187 },
188
189 /**
190 * Updates name of the target channel, i.e. the name of the
191 * channel the device is supposed to be in case of a pending
192 * channel change.
193 * @param {string} channel The name of the target channel
194 * @private
195 */
196 updateTargetChannel_: function(channel) {
197 if (this.channelList_.indexOf(channel) < 0)
198 return;
199 this.targetChannel_ = channel;
200 help.HelpPage.updateChannelChangePageContainerVisibility();
201 },
202
203 /**
204 * @return {boolean} True if the page is ready and can be
205 * displayed, false otherwise
206 * @private
207 */
208 isPageReady_: function() {
209 if (typeof this.isEnterpriseManaged_ == 'undefined')
210 return false;
211 if (!this.currentChannel_ || !this.targetChannel_)
212 return false;
213 return true;
214 },
215 };
216
217 ChannelChangePage.updateIsEnterpriseManaged = function(isEnterpriseManaged) {
218 ChannelChangePage.getInstance().updateIsEnterpriseManaged_(
219 isEnterpriseManaged);
220 };
221
222 ChannelChangePage.updateCurrentChannel = function(channel) {
223 ChannelChangePage.getInstance().updateCurrentChannel_(channel);
224 };
225
226 ChannelChangePage.updateTargetChannel = function(channel) {
227 ChannelChangePage.getInstance().updateTargetChannel_(channel);
228 };
229
230 ChannelChangePage.isPageReady = function() {
231 return ChannelChangePage.getInstance().isPageReady_();
232 };
233
234 // Export
235 return {
236 ChannelChangePage: ChannelChangePage
237 };
238 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698