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() {
7 * Encapsulated handling of the channel change overlay.
9 function ChannelChangePage() {}
11 cr.addSingletonGetter(ChannelChangePage);
13 ChannelChangePage.prototype = {
14 __proto__: help.HelpBasePage.prototype,
17 * Name of the channel the device is currently on.
20 currentChannel_: null,
23 * Name of the channel the device is supposed to be on.
29 * True iff the device is enterprise-managed.
32 isEnterpriseManaged_: undefined,
35 * List of the channels names, from the least stable to the most stable.
38 channelList_: ['dev-channel', 'beta-channel', 'stable-channel'],
41 * List of the possible ui states.
44 uiClassTable_: ['selected-channel-requires-powerwash',
45 'selected-channel-requires-delayed-update',
46 'selected-channel-good',
47 'selected-channel-unstable'],
50 * Perform initial setup.
52 initialize: function() {
53 help.HelpBasePage.prototype.initialize.call(this, 'channel-change-page');
57 $('channel-change-page-cancel-button').onclick = function() {
58 help.HelpPage.cancelOverlay();
61 var options = this.getAllChannelOptions_();
62 for (var i = 0; i < options.length; i++) {
63 var option = options[i];
64 option.onclick = function() {
65 self.updateUI_(this.value);
69 $('channel-change-page-powerwash-button').onclick = function() {
70 self.setChannel_(self.getSelectedOption_(), true);
71 help.HelpPage.cancelOverlay();
74 $('channel-change-page-change-button').onclick = function() {
75 self.setChannel_(self.getSelectedOption_(), false);
76 help.HelpPage.cancelOverlay();
81 * Returns the list of all radio buttons responsible for channel selection.
82 * @return {Array.<HTMLInputElement>} Array of radio buttons
85 getAllChannelOptions_: function() {
86 return $('channel-change-page').querySelectorAll('input[type="radio"]');
90 * Returns value of the selected option.
91 * @return {string} Selected channel name or null, if neither
95 getSelectedOption_: function() {
96 var options = this.getAllChannelOptions_();
97 for (var i = 0; i < options.length; i++) {
98 var option = options[i];
106 * Updates UI according to selected channel.
107 * @param {string} selectedChannel Selected channel
110 updateUI_: function(selectedChannel) {
111 var currentStability = this.channelList_.indexOf(this.currentChannel_);
112 var newStability = this.channelList_.indexOf(selectedChannel);
114 var newOverlayClass = null;
116 if (selectedChannel == this.currentChannel_) {
117 if (this.currentChannel_ != this.targetChannel_) {
118 // Allow user to switch back to the current channel.
119 newOverlayClass = 'selected-channel-good';
121 } else if (selectedChannel != this.targetChannel_) {
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';
129 newOverlayClass = 'selected-channel-requires-powerwash';
130 } else if (selectedChannel == 'dev-channel') {
131 // Warn user about unstable channel.
132 newOverlayClass = 'selected-channel-unstable';
134 // Switching to the less stable channel.
135 newOverlayClass = 'selected-channel-good';
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]);
144 $('channel-change-page').classList.add(newOverlayClass);
148 * Sets the device target channel.
149 * @param {string} channel The name of the target channel
150 * @param {boolean} isPowerwashAllowed True iff powerwash is allowed
153 setChannel_: function(channel, isPowerwashAllowed) {
154 this.targetChannel_ = channel;
155 this.updateUI_(channel);
156 help.HelpPage.setChannel(channel, isPowerwashAllowed);
160 * Updates page UI according to device owhership policy.
161 * @param {boolean} isEnterpriseManaged True if the device is
165 updateIsEnterpriseManaged_: function(isEnterpriseManaged) {
166 this.isEnterpriseManaged_ = isEnterpriseManaged;
167 help.HelpPage.updateChannelChangePageContainerVisibility();
171 * Updates name of the current channel, i.e. the name of the
172 * channel the device is currently on.
173 * @param {string} channel The name of the current channel
176 updateCurrentChannel_: function(channel) {
177 if (this.channelList_.indexOf(channel) < 0)
179 this.currentChannel_ = channel;
181 var options = this.getAllChannelOptions_();
182 for (var i = 0; i < options.length; i++) {
183 var option = options[i];
184 if (option.value == channel)
185 option.checked = true;
187 help.HelpPage.updateChannelChangePageContainerVisibility();
191 * Updates name of the target channel, i.e. the name of the
192 * channel the device is supposed to be in case of a pending
194 * @param {string} channel The name of the target channel
197 updateTargetChannel_: function(channel) {
198 if (this.channelList_.indexOf(channel) < 0)
200 this.targetChannel_ = channel;
201 help.HelpPage.updateChannelChangePageContainerVisibility();
205 * @return {boolean} True if the page is ready and can be
206 * displayed, false otherwise
209 isPageReady_: function() {
210 if (typeof this.isEnterpriseManaged_ == 'undefined')
212 if (!this.currentChannel_ || !this.targetChannel_)
218 ChannelChangePage.updateIsEnterpriseManaged = function(isEnterpriseManaged) {
219 ChannelChangePage.getInstance().updateIsEnterpriseManaged_(
220 isEnterpriseManaged);
223 ChannelChangePage.updateCurrentChannel = function(channel) {
224 ChannelChangePage.getInstance().updateCurrentChannel_(channel);
227 ChannelChangePage.updateTargetChannel = function(channel) {
228 ChannelChangePage.getInstance().updateTargetChannel_(channel);
231 ChannelChangePage.isPageReady = function() {
232 return ChannelChangePage.getInstance().isPageReady_();
237 ChannelChangePage: ChannelChangePage