1 // Copyright 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.
5 cr
.define('help', function() {
6 var Page
= cr
.ui
.pageManager
.Page
;
7 var PageManager
= cr
.ui
.pageManager
.PageManager
;
10 * Encapsulated handling of the channel change overlay.
12 function ChannelChangePage() {
13 Page
.call(this, 'channel-change-page', '', 'channel-change-page');
16 cr
.addSingletonGetter(ChannelChangePage
);
18 ChannelChangePage
.prototype = {
19 __proto__
: Page
.prototype,
22 * Name of the channel the device is currently on.
25 currentChannel_
: null,
28 * Name of the channel the device is supposed to be on.
34 * True iff the device is enterprise-managed.
37 isEnterpriseManaged_
: undefined,
40 * List of the channels names, from the least stable to the most stable.
43 channelList_
: ['dev-channel', 'beta-channel', 'stable-channel'],
46 * List of the possible ui states.
49 uiClassTable_
: ['selected-channel-requires-powerwash',
50 'selected-channel-requires-delayed-update',
51 'selected-channel-good',
52 'selected-channel-unstable'],
55 initializePage: function() {
56 Page
.prototype.initializePage
.call(this);
58 $('channel-change-page-cancel-button').onclick
=
59 PageManager
.closeOverlay
.bind(PageManager
);
62 var options
= this.getAllChannelOptions_();
63 for (var i
= 0; i
< options
.length
; i
++) {
64 var option
= options
[i
];
65 option
.onclick = function() {
66 self
.updateUI_(this.value
);
70 $('channel-change-page-powerwash-button').onclick = function() {
71 self
.setChannel_(self
.getSelectedOption_(), true);
72 PageManager
.closeOverlay();
75 $('channel-change-page-change-button').onclick = function() {
76 self
.setChannel_(self
.getSelectedOption_(), false);
77 PageManager
.closeOverlay();
82 didShowPage: function() {
83 if (this.targetChannel_
!= null)
84 this.selectOption_(this.targetChannel_
);
85 else if (this.currentChannel_
!= null)
86 this.selectOption_(this.currentChannel_
);
87 var options
= this.getAllChannelOptions_();
88 for (var i
= 0; i
< options
.length
; i
++) {
89 var option
= options
[i
];
96 * Returns the list of all radio buttons responsible for channel selection.
97 * @return {NodeList} Array of radio buttons
100 getAllChannelOptions_: function() {
101 return this.pageDiv
.querySelectorAll('input[type="radio"]');
105 * Returns value of the selected option.
106 * @return {?string} Selected channel name or null, if neither
107 * option is selected.
110 getSelectedOption_: function() {
111 var options
= this.getAllChannelOptions_();
112 for (var i
= 0; i
< options
.length
; i
++) {
113 var option
= options
[i
];
121 * Selects option for a given channel.
122 * @param {string} channel Name of channel option that should be selected.
125 selectOption_: function(channel
) {
126 var options
= this.getAllChannelOptions_();
127 for (var i
= 0; i
< options
.length
; i
++) {
128 var option
= options
[i
];
129 if (option
.value
== channel
) {
130 option
.checked
= true;
133 this.updateUI_(channel
);
137 * Updates UI according to selected channel.
138 * @param {string} selectedChannel Selected channel
141 updateUI_: function(selectedChannel
) {
142 var currentStability
= this.channelList_
.indexOf(this.currentChannel_
);
143 var newStability
= this.channelList_
.indexOf(selectedChannel
);
145 var newOverlayClass
= null;
147 if (selectedChannel
== this.currentChannel_
) {
148 if (this.currentChannel_
!= this.targetChannel_
) {
149 // Allow user to switch back to the current channel.
150 newOverlayClass
= 'selected-channel-good';
152 } else if (selectedChannel
!= this.targetChannel_
) {
153 // Selected channel isn't equal to the current and target channel.
154 if (newStability
> currentStability
) {
155 // More stable channel is selected. For customer devices
156 // notify user about powerwash.
157 if (this.isEnterpriseManaged_
)
158 newOverlayClass
= 'selected-channel-requires-delayed-update';
160 newOverlayClass
= 'selected-channel-requires-powerwash';
161 } else if (selectedChannel
== 'dev-channel') {
162 // Warn user about unstable channel.
163 newOverlayClass
= 'selected-channel-unstable';
165 // Switching to the less stable channel.
166 newOverlayClass
= 'selected-channel-good';
170 // Switch to the new UI state.
171 for (var i
= 0; i
< this.uiClassTable_
.length
; i
++)
172 this.pageDiv
.classList
.remove(this.uiClassTable_
[i
]);
175 this.pageDiv
.classList
.add(newOverlayClass
);
179 * Sets the device target channel.
180 * @param {string} channel The name of the target channel
181 * @param {boolean} isPowerwashAllowed True iff powerwash is allowed
184 setChannel_: function(channel
, isPowerwashAllowed
) {
185 this.targetChannel_
= channel
;
186 this.updateUI_(channel
);
187 help
.HelpPage
.setChannel(channel
, isPowerwashAllowed
);
191 * Updates page UI according to device owhership policy.
192 * @param {boolean} isEnterpriseManaged True if the device is
196 updateIsEnterpriseManaged_: function(isEnterpriseManaged
) {
197 this.isEnterpriseManaged_
= isEnterpriseManaged
;
201 * Updates name of the current channel, i.e. the name of the
202 * channel the device is currently on.
203 * @param {string} channel The name of the current channel
206 updateCurrentChannel_: function(channel
) {
207 if (this.channelList_
.indexOf(channel
) < 0)
209 this.currentChannel_
= channel
;
210 this.selectOption_(channel
);
214 * Updates name of the target channel, i.e. the name of the
215 * channel the device is supposed to be in case of a pending
217 * @param {string} channel The name of the target channel
220 updateTargetChannel_: function(channel
) {
221 if (this.channelList_
.indexOf(channel
) < 0)
223 this.targetChannel_
= channel
;
227 * @return {boolean} True if the page is ready and can be
228 * displayed, false otherwise
231 isPageReady_: function() {
232 if (typeof this.isEnterpriseManaged_
== 'undefined')
234 if (!this.currentChannel_
|| !this.targetChannel_
)
240 ChannelChangePage
.updateIsEnterpriseManaged = function(isEnterpriseManaged
) {
241 ChannelChangePage
.getInstance().updateIsEnterpriseManaged_(
242 isEnterpriseManaged
);
245 ChannelChangePage
.updateCurrentChannel = function(channel
) {
246 ChannelChangePage
.getInstance().updateCurrentChannel_(channel
);
249 ChannelChangePage
.updateTargetChannel = function(channel
) {
250 ChannelChangePage
.getInstance().updateTargetChannel_(channel
);
253 ChannelChangePage
.isPageReady = function() {
254 return ChannelChangePage
.getInstance().isPageReady_();
259 ChannelChangePage
: ChannelChangePage