Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / chrome / browser / resources / help / channel_change_page.js
blobd7c776066c2b42647edb981ca4830568176b71d8
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;
9 /**
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,
21 /**
22 * Name of the channel the device is currently on.
23 * @private
25 currentChannel_: null,
27 /**
28 * Name of the channel the device is supposed to be on.
29 * @private
31 targetChannel_: null,
33 /**
34 * True iff the device is enterprise-managed.
35 * @private
37 isEnterpriseManaged_: undefined,
39 /**
40 * List of the channels names, from the least stable to the most stable.
41 * @private
43 channelList_: ['dev-channel', 'beta-channel', 'stable-channel'],
45 /**
46 * List of the possible ui states.
47 * @private
49 uiClassTable_: ['selected-channel-requires-powerwash',
50 'selected-channel-requires-delayed-update',
51 'selected-channel-good',
52 'selected-channel-unstable'],
54 /** override */
55 initializePage: function() {
56 Page.prototype.initializePage.call(this);
58 $('channel-change-page-cancel-button').onclick =
59 PageManager.closeOverlay.bind(PageManager);
61 var self = this;
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();
81 /** @override */
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];
90 if (option.checked)
91 option.focus();
95 /**
96 * Returns the list of all radio buttons responsible for channel selection.
97 * @return {Array.<HTMLInputElement>} Array of radio buttons
98 * @private
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.
108 * @private
110 getSelectedOption_: function() {
111 var options = this.getAllChannelOptions_();
112 for (var i = 0; i < options.length; i++) {
113 var option = options[i];
114 if (option.checked)
115 return option.value;
117 return null;
121 * Selects option for a given channel.
122 * @param {string} channel Name of channel option that should be selected.
123 * @private
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
139 * @private
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';
159 else
160 newOverlayClass = 'selected-channel-requires-powerwash';
161 } else if (selectedChannel == 'dev-channel') {
162 // Warn user about unstable channel.
163 newOverlayClass = 'selected-channel-unstable';
164 } else {
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]);
174 if (newOverlayClass)
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
182 * @private
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
193 * enterprise managed
194 * @private
196 updateIsEnterpriseManaged_: function(isEnterpriseManaged) {
197 this.isEnterpriseManaged_ = isEnterpriseManaged;
198 help.HelpPage.updateChannelChangePageContainerVisibility();
202 * Updates name of the current channel, i.e. the name of the
203 * channel the device is currently on.
204 * @param {string} channel The name of the current channel
205 * @private
207 updateCurrentChannel_: function(channel) {
208 if (this.channelList_.indexOf(channel) < 0)
209 return;
210 this.currentChannel_ = channel;
211 this.selectOption_(channel);
212 help.HelpPage.updateChannelChangePageContainerVisibility();
216 * Updates name of the target channel, i.e. the name of the
217 * channel the device is supposed to be in case of a pending
218 * channel change.
219 * @param {string} channel The name of the target channel
220 * @private
222 updateTargetChannel_: function(channel) {
223 if (this.channelList_.indexOf(channel) < 0)
224 return;
225 this.targetChannel_ = channel;
226 help.HelpPage.updateChannelChangePageContainerVisibility();
230 * @return {boolean} True if the page is ready and can be
231 * displayed, false otherwise
232 * @private
234 isPageReady_: function() {
235 if (typeof this.isEnterpriseManaged_ == 'undefined')
236 return false;
237 if (!this.currentChannel_ || !this.targetChannel_)
238 return false;
239 return true;
243 ChannelChangePage.updateIsEnterpriseManaged = function(isEnterpriseManaged) {
244 ChannelChangePage.getInstance().updateIsEnterpriseManaged_(
245 isEnterpriseManaged);
248 ChannelChangePage.updateCurrentChannel = function(channel) {
249 ChannelChangePage.getInstance().updateCurrentChannel_(channel);
252 ChannelChangePage.updateTargetChannel = function(channel) {
253 ChannelChangePage.getInstance().updateTargetChannel_(channel);
256 ChannelChangePage.isPageReady = function() {
257 return ChannelChangePage.getInstance().isPageReady_();
260 // Export
261 return {
262 ChannelChangePage: ChannelChangePage