1 // Copyright (c) 2012 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 <include src="../uber/uber_utils.js">
7 cr.define('help', function() {
9 * Encapsulated handling of the help page.
11 function HelpPage() {}
13 cr.addSingletonGetter(HelpPage);
15 HelpPage.prototype = {
16 __proto__: help.HelpBasePage.prototype,
19 * True if after update powerwash button should be displayed.
22 powerwashAfterUpdate_: false,
25 * List of the channels names.
28 channelList_: ['dev-channel', 'beta-channel', 'stable-channel'],
31 * Bubble for error messages and notifications.
37 * Name of the channel the device is currently on.
40 currentChannel_: null,
43 * Name of the channel the device is supposed to be on.
49 * Perform initial setup.
51 initialize: function() {
52 help.HelpBasePage.prototype.initialize.call(this, 'help-page');
56 uber.onContentFrameLoaded();
59 var title = loadTimeData.getString('helpTitle');
60 uber.invokeMethodOnParent('setTitle', {title: title});
62 $('product-license').innerHTML = loadTimeData.getString('productLicense');
64 $('product-os-license').innerHTML =
65 loadTimeData.getString('productOsLicense');
68 var productTOS = $('product-tos');
70 productTOS.innerHTML = loadTimeData.getString('productTOS');
72 $('get-help').onclick = function() {
73 chrome.send('openHelpPage');
75 <if expr="pp_ifdef('_google_chrome')">
76 $('report-issue').onclick = function() {
77 chrome.send('openFeedbackDialog');
81 this.maybeSetOnClick_($('more-info-expander'),
82 this.toggleMoreInfo_.bind(this));
84 this.maybeSetOnClick_($('promote'), function() {
85 chrome.send('promoteUpdater');
87 this.maybeSetOnClick_($('relaunch'), function() {
88 chrome.send('relaunchNow');
91 this.maybeSetOnClick_($('relaunch-and-powerwash'), function() {
92 chrome.send('relaunchAndPowerwash');
95 this.channelTable_ = {
97 'name': loadTimeData.getString('stable'),
98 'label': loadTimeData.getString('currentChannelStable'),
101 'name': loadTimeData.getString('beta'),
102 'label': loadTimeData.getString('currentChannelBeta')
105 'name': loadTimeData.getString('dev'),
106 'label': loadTimeData.getString('currentChannelDev')
111 var channelChanger = $('channel-changer');
112 if (channelChanger) {
113 channelChanger.onchange = function(event) {
114 self.setChannel_(event.target.value, false);
119 help.ChannelChangePage.getInstance().initialize();
120 this.registerOverlay(help.ChannelChangePage.getInstance());
122 cr.ui.overlay.setupOverlay($('overlay-container'));
123 cr.ui.overlay.globalInitialization();
124 $('overlay-container').addEventListener('cancelOverlay', function() {
127 $('change-channel').onclick = function() {
128 self.showOverlay('channel-change-page');
131 var channelChangeDisallowedError = document.createElement('div');
132 channelChangeDisallowedError.className = 'channel-change-error-bubble';
134 var channelChangeDisallowedIcon = document.createElement('div');
135 channelChangeDisallowedIcon.classList.add('help-page-icon-large');
136 channelChangeDisallowedIcon.classList.add('channel-change-error-icon');
137 channelChangeDisallowedError.appendChild(channelChangeDisallowedIcon);
139 var channelChangeDisallowedText = document.createElement('div');
140 channelChangeDisallowedText.className = 'channel-change-error-text';
141 channelChangeDisallowedText.textContent =
142 loadTimeData.getString('channelChangeDisallowedMessage');
143 channelChangeDisallowedError.appendChild(channelChangeDisallowedText);
145 $('channel-change-disallowed-icon').onclick = function() {
146 self.showBubble_(channelChangeDisallowedError,
148 $('channel-change-disallowed-icon'),
149 cr.ui.ArrowLocation.TOP_END);
153 cr.ui.FocusManager.disableMouseFocusOnButtons();
154 help.HelpFocusManager.getInstance().initialize();
156 // Attempt to update.
157 chrome.send('onPageLoaded');
162 * @param {HTMLDivElement} content The content of the bubble.
163 * @param {HTMLElement} target The element at which the bubble points.
164 * @param {HTMLElement} domSibling The element after which the bubble is
166 * @param {cr.ui.ArrowLocation} location The arrow location.
169 showBubble_: function(content, domSibling, target, location) {
173 var bubble = new cr.ui.AutoCloseBubble;
174 bubble.anchorNode = target;
175 bubble.domSibling = domSibling;
176 bubble.arrowLocation = location;
177 bubble.content = content;
179 this.bubble_ = bubble;
186 hideBubble_: function() {
194 * Toggles the visible state of the 'More Info' section.
197 toggleMoreInfo_: function() {
198 var moreInfo = $('more-info-container');
199 var visible = moreInfo.className == 'visible';
200 moreInfo.className = visible ? '' : 'visible';
201 moreInfo.style.height = visible ? '' : moreInfo.scrollHeight + 'px';
202 moreInfo.addEventListener('webkitTransitionEnd', function(event) {
203 $('more-info-expander').textContent = visible ?
204 loadTimeData.getString('showMoreInfo') :
205 loadTimeData.getString('hideMoreInfo');
210 * Assigns |method| to the onclick property of |el| if |el| exists.
213 maybeSetOnClick_: function(el, method) {
221 setUpdateImage_: function(state) {
222 $('update-status-icon').className = 'help-page-icon ' + state;
226 * @return {boolean} True, if new channel switcher UI is used,
230 isNewChannelSwitcherUI_: function() {
231 return !loadTimeData.valueExists('disableNewChannelSwitcherUI');
235 * @return {boolean} True if target and current channels are not
236 * null and not equals
239 channelsDiffer_: function() {
240 var current = this.currentChannel_;
241 var target = this.targetChannel_;
242 return (current != null && target != null && current != target);
248 setUpdateStatus_: function(status, message) {
249 var channel = this.targetChannel_;
250 if (status == 'checking') {
251 this.setUpdateImage_('working');
252 $('update-status-message').innerHTML =
253 loadTimeData.getString('updateCheckStarted');
254 } else if (status == 'updating') {
255 this.setUpdateImage_('working');
256 if (this.channelsDiffer_()) {
257 $('update-status-message').innerHTML =
258 loadTimeData.getStringF('updatingChannelSwitch',
259 this.channelTable_[channel].label);
261 $('update-status-message').innerHTML =
262 loadTimeData.getStringF('updating');
264 } else if (status == 'nearly_updated') {
265 this.setUpdateImage_('up-to-date');
266 if (this.channelsDiffer_()) {
267 $('update-status-message').innerHTML =
268 loadTimeData.getString('successfulChannelSwitch');
270 $('update-status-message').innerHTML =
271 loadTimeData.getString('updateAlmostDone');
273 } else if (status == 'updated') {
274 this.setUpdateImage_('up-to-date');
275 $('update-status-message').innerHTML =
276 loadTimeData.getString('upToDate');
277 } else if (status == 'failed') {
278 this.setUpdateImage_('failed');
279 $('update-status-message').innerHTML = message;
282 // Following invariant must be established at the end of this function:
283 // { ~$('relaunch_and_powerwash').hidden -> $('relaunch').hidden }
284 var relaunchAndPowerwashHidden = true;
285 if ($('relaunch-and-powerwash')) {
286 // It's allowed to do powerwash only for customer devices,
287 // when user explicitly decides to update to a more stable
289 relaunchAndPowerwashHidden =
290 !this.powerwashAfterUpdate_ || status != 'nearly_updated';
291 $('relaunch-and-powerwash').hidden = relaunchAndPowerwashHidden;
294 var container = $('update-status-container');
296 container.hidden = status == 'disabled';
297 $('relaunch').hidden =
298 (status != 'nearly_updated') || !relaunchAndPowerwashHidden;
301 $('update-percentage').hidden = status != 'updating';
308 setProgress_: function(progress) {
309 $('update-percentage').innerHTML = progress + '%';
315 setAllowedConnectionTypesMsg_: function(message) {
316 $('allowed-connection-types-message').innerText = message;
322 showAllowedConnectionTypesMsg_: function(visible) {
323 $('allowed-connection-types-message').hidden = !visible;
329 setPromotionState_: function(state) {
330 if (state == 'hidden') {
331 $('promote').hidden = true;
332 } else if (state == 'enabled') {
333 $('promote').disabled = false;
334 $('promote').hidden = false;
335 } else if (state == 'disabled') {
336 $('promote').disabled = true;
337 $('promote').hidden = false;
344 setOSVersion_: function(version) {
346 console.error('OS version unsupported on non-CrOS');
348 $('os-version').parentNode.hidden = (version == '');
349 $('os-version').textContent = version;
355 setOSFirmware_: function(firmware) {
357 console.error('OS firmware unsupported on non-CrOS');
359 $('firmware').parentNode.hidden = (firmware == '');
360 $('firmware').textContent = firmware;
364 * Updates name of the current channel, i.e. the name of the
365 * channel the device is currently on.
366 * @param {string} channel The name of the current channel
369 updateCurrentChannel_: function(channel) {
370 if (this.channelList_.indexOf(channel) < 0)
372 $('current-channel').textContent = loadTimeData.getStringF(
373 'currentChannel', this.channelTable_[channel].label);
374 this.currentChannel_ = channel;
375 help.ChannelChangePage.updateCurrentChannel(channel);
379 * |enabled| is true if the release channel can be enabled.
382 updateEnableReleaseChannel_: function(enabled) {
383 this.updateChannelChangerContainerVisibility_(enabled);
384 $('change-channel').disabled = !enabled;
385 $('channel-change-disallowed-icon').hidden = enabled;
389 * Sets the device target channel.
390 * @param {string} channel The name of the target channel
391 * @param {boolean} isPowerwashAllowed True iff powerwash is allowed
394 setChannel_: function(channel, isPowerwashAllowed) {
395 this.powerwashAfterUpdate_ = isPowerwashAllowed;
396 this.targetChannel_ = channel;
397 chrome.send('setChannel', [channel, isPowerwashAllowed]);
398 $('channel-change-confirmation').hidden = false;
399 $('channel-change-confirmation').textContent = loadTimeData.getStringF(
400 'channel-changed', this.channelTable_[channel].name);
404 * Sets the value of the "Build Date" field of the "More Info" section.
405 * @param {string} buildDate The date of the build.
408 setBuildDate_: function(buildDate) {
409 $('build-date-container').classList.remove('empty');
410 $('build-date').textContent = buildDate;
414 * Updates channel-change-page-container visibility according to
418 updateChannelChangePageContainerVisibility_: function() {
419 if (!this.isNewChannelSwitcherUI_()) {
420 $('channel-change-page-container').hidden = true;
423 $('channel-change-page-container').hidden =
424 !help.ChannelChangePage.isPageReady();
428 * Updates channel-changer dropdown visibility if |visible| is
429 * true and new channel switcher UI is disallowed.
430 * @param {boolean} visible True if channel-changer should be
431 * displayed, false otherwise.
434 updateChannelChangerContainerVisibility_: function(visible) {
435 if (this.isNewChannelSwitcherUI_()) {
436 $('channel-changer').hidden = true;
439 $('channel-changer').hidden = !visible;
443 HelpPage.setUpdateStatus = function(status, message) {
444 HelpPage.getInstance().setUpdateStatus_(status, message);
447 HelpPage.setProgress = function(progress) {
448 HelpPage.getInstance().setProgress_(progress);
451 HelpPage.setAndShowAllowedConnectionTypesMsg = function(message) {
452 HelpPage.getInstance().setAllowedConnectionTypesMsg_(message);
453 HelpPage.getInstance().showAllowedConnectionTypesMsg_(true);
456 HelpPage.showAllowedConnectionTypesMsg = function(visible) {
457 HelpPage.getInstance().showAllowedConnectionTypesMsg_(visible);
460 HelpPage.setPromotionState = function(state) {
461 HelpPage.getInstance().setPromotionState_(state);
464 HelpPage.setObsoleteOS = function(obsolete) {
465 HelpPage.getInstance().setObsoleteOS_(obsolete);
468 HelpPage.setOSVersion = function(version) {
469 HelpPage.getInstance().setOSVersion_(version);
472 HelpPage.setOSFirmware = function(firmware) {
473 HelpPage.getInstance().setOSFirmware_(firmware);
476 HelpPage.showOverlay = function(name) {
477 HelpPage.getInstance().showOverlay(name);
480 HelpPage.cancelOverlay = function() {
481 HelpPage.getInstance().closeOverlay();
484 HelpPage.getTopmostVisiblePage = function() {
485 return HelpPage.getInstance().getTopmostVisiblePage();
488 HelpPage.updateIsEnterpriseManaged = function(isEnterpriseManaged) {
491 help.ChannelChangePage.updateIsEnterpriseManaged(isEnterpriseManaged);
494 HelpPage.updateCurrentChannel = function(channel) {
497 HelpPage.getInstance().updateCurrentChannel_(channel);
500 HelpPage.updateTargetChannel = function(channel) {
503 help.ChannelChangePage.updateTargetChannel(channel);
506 HelpPage.updateEnableReleaseChannel = function(enabled) {
507 HelpPage.getInstance().updateEnableReleaseChannel_(enabled);
510 HelpPage.setChannel = function(channel, isPowerwashAllowed) {
511 HelpPage.getInstance().setChannel_(channel, isPowerwashAllowed);
514 HelpPage.setBuildDate = function(buildDate) {
515 HelpPage.getInstance().setBuildDate_(buildDate);
518 HelpPage.updateChannelChangePageContainerVisibility = function() {
519 HelpPage.getInstance().updateChannelChangePageContainerVisibility_();
529 * onload listener to initialize the HelpPage.
531 window.onload = function() {
532 help.HelpPage.getInstance().initialize();