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