Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: chrome/browser/resources/help/help.js

Issue 17437004: Implemented new channel switcher UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix, sync. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 <include src="../uber/uber_utils.js"> 5 <include src="../uber/uber_utils.js">
6 6
7 cr.define('help', function() { 7 cr.define('help', function() {
8 /** 8 /**
9 * Encapsulated handling of the help page. 9 * Encapsulated handling of the help page.
10 */ 10 */
11 function HelpPage() {} 11 function HelpPage() {}
12 12
13 cr.addSingletonGetter(HelpPage); 13 cr.addSingletonGetter(HelpPage);
14 14
15 HelpPage.prototype = { 15 HelpPage.prototype = {
16 __proto__: HTMLDivElement.prototype, 16 __proto__: HTMLDivElement.prototype,
17 17
18 /** 18 /**
19 * True if after update powerwash button should be displayed.
20 * @private
21 */
22 powerwashAfterUpdate_: false,
23
24 /**
25 * List of the channels names.
26 * @private
27 */
28 channelList_: ['dev-channel', 'beta-channel', 'stable-channel'],
29
30 /**
31 * Bubble for error messages and notifications.
32 * @private
33 */
34 bubble_: null,
35
36 /**
37 * Name of the channel the device is currently on.
38 * @private
39 */
40 currentChannel_: null,
41
42 /**
43 * Name of the channel the device is supposed to be.
44 * @private
45 */
46 targetChannel_: null,
47
48 /**
19 * Perform initial setup. 49 * Perform initial setup.
20 */ 50 */
21 initialize: function() { 51 initialize: function() {
52 var self = this;
53
22 uber.onContentFrameLoaded(); 54 uber.onContentFrameLoaded();
23 55
24 // Set the title. 56 // Set the title.
25 var title = loadTimeData.getString('helpTitle'); 57 var title = loadTimeData.getString('helpTitle');
26 uber.invokeMethodOnParent('setTitle', {title: title}); 58 uber.invokeMethodOnParent('setTitle', {title: title});
27 59
28 $('product-license').innerHTML = loadTimeData.getString('productLicense'); 60 $('product-license').innerHTML = loadTimeData.getString('productLicense');
29 if (cr.isChromeOS) { 61 if (cr.isChromeOS) {
30 $('product-os-license').innerHTML = 62 $('product-os-license').innerHTML =
31 loadTimeData.getString('productOsLicense'); 63 loadTimeData.getString('productOsLicense');
(...skipping 12 matching lines...) Expand all
44 76
45 this.maybeSetOnClick_($('more-info-expander'), 77 this.maybeSetOnClick_($('more-info-expander'),
46 this.toggleMoreInfo_.bind(this)); 78 this.toggleMoreInfo_.bind(this));
47 79
48 this.maybeSetOnClick_($('promote'), function() { 80 this.maybeSetOnClick_($('promote'), function() {
49 chrome.send('promoteUpdater'); 81 chrome.send('promoteUpdater');
50 }); 82 });
51 this.maybeSetOnClick_($('relaunch'), function() { 83 this.maybeSetOnClick_($('relaunch'), function() {
52 chrome.send('relaunchNow'); 84 chrome.send('relaunchNow');
53 }); 85 });
86 this.maybeSetOnClick_($('relaunch-and-powerwash'), function() {
87 chrome.send('relaunchAndPowerwash');
88 });
89
90 this.channelTable_ = {
91 'stable-channel': {
92 'name': loadTimeData.getString('stable'),
93 'label': loadTimeData.getString('currentChannelStable'),
94 },
95 'beta-channel': {
96 'name': loadTimeData.getString('beta'),
97 'label': loadTimeData.getString('currentChannelBeta')
98 },
99 'dev-channel': {
100 'name': loadTimeData.getString('dev'),
101 'label': loadTimeData.getString('currentChannelDev')
102 }
103 };
54 104
55 var channelChanger = $('channel-changer'); 105 var channelChanger = $('channel-changer');
56 if (channelChanger) { 106 if (channelChanger) {
57 this.channelName_ = { 107 channelChanger.onchange = function(event) {
58 'stable-channel': loadTimeData.getString('stable'), 108 self.setChannel_(event.target.value, false);
59 'beta-channel': loadTimeData.getString('beta'),
60 'dev-channel': loadTimeData.getString('dev')
61 }; 109 };
62 var self = this;
63 channelChanger.onchange = function(event) {
64 self.setReleaseChannel_(event.target.value);
65 }
66 } 110 }
67 111
112 cr.ui.overlay.globalInitialization();
113 cr.ui.overlay.setupOverlay($('overlay-container'));
114 $('overlay-container').addEventListener('cancelOverlay', function() {
115 self.showOverlay_(null);
116 });
117
118 $('change-channel').onclick = function() {
119 self.showOverlay_($('channel-change-page'));
120 };
121
122 var channelChangeDisallowedError = document.createElement('div');
123 channelChangeDisallowedError.className = 'channel-change-error-bubble';
124
125 var channelChangeDisallowedIcon = document.createElement('div');
126 channelChangeDisallowedIcon.classList.add('help-page-icon-large');
127 channelChangeDisallowedIcon.classList.add('channel-change-error-icon');
128 channelChangeDisallowedError.appendChild(channelChangeDisallowedIcon);
129
130 var channelChangeDisallowedText = document.createElement('div');
131 channelChangeDisallowedText.className = 'channel-change-error-text';
132 channelChangeDisallowedText.textContent =
133 loadTimeData.getString('channelChangeDisallowedMessage');
134 channelChangeDisallowedError.appendChild(channelChangeDisallowedText);
135
136 $('channel-change-disallowed-icon').onclick = function() {
137 self.showBubble_(channelChangeDisallowedError,
138 $('help-container'),
139 $('channel-change-disallowed-icon'),
140 cr.ui.ArrowLocation.TOP_END);
141 };
142
68 // Attempt to update. 143 // Attempt to update.
69 chrome.send('onPageLoaded'); 144 chrome.send('onPageLoaded');
70 }, 145 },
71 146
72 /** 147 /**
148 * Shows the bubble.
149 * @param {HTMLDivElement} content The content of the bubble.
150 * @param {HTMLElement} target The element at which the bubble points.
151 * @param {HTMLElement} domSibling The element after which the bubble is
152 * added to the DOM.
153 * @param {cr.ui.ArrowLocation} location The arrow location.
154 * @private
155 */
156 showBubble_: function(content, domSibling, target, location) {
157 if (!cr.isChromeOS)
158 return;
159 this.hideBubble_();
160 var bubble = new cr.ui.AutoCloseBubble;
161 bubble.anchorNode = target;
162 bubble.domSibling = domSibling;
163 bubble.arrowLocation = location;
164 bubble.content = content;
165 bubble.show();
166 this.bubble_ = bubble;
167 },
168
169 /**
170 * Hides the bubble.
171 * @private
172 */
173 hideBubble_: function() {
174 if (!cr.isChromeOS)
175 return;
176 if (this.bubble_)
177 this.bubble_.hide();
178 },
179
180 /**
73 * Toggles the visible state of the 'More Info' section. 181 * Toggles the visible state of the 'More Info' section.
74 * @private 182 * @private
75 */ 183 */
76 toggleMoreInfo_: function() { 184 toggleMoreInfo_: function() {
77 var moreInfo = $('more-info-container'); 185 var moreInfo = $('more-info-container');
78 var visible = moreInfo.className == 'visible'; 186 var visible = moreInfo.className == 'visible';
79 moreInfo.className = visible ? '' : 'visible'; 187 moreInfo.className = visible ? '' : 'visible';
80 moreInfo.style.height = visible ? '' : moreInfo.scrollHeight + 'px'; 188 moreInfo.style.height = visible ? '' : moreInfo.scrollHeight + 'px';
81 moreInfo.addEventListener('webkitTransitionEnd', function(event) { 189 moreInfo.addEventListener('webkitTransitionEnd', function(event) {
82 $('more-info-expander').textContent = visible ? 190 $('more-info-expander').textContent = visible ?
83 loadTimeData.getString('showMoreInfo') : 191 loadTimeData.getString('showMoreInfo') :
84 loadTimeData.getString('hideMoreInfo'); 192 loadTimeData.getString('hideMoreInfo');
85 }); 193 });
86 }, 194 },
87 195
88 /** 196 /**
89 * Assigns |method| to the onclick property of |el| if |el| exists. 197 * Assigns |method| to the onclick property of |el| if |el| exists.
90 * @private 198 * @private
91 */ 199 */
92 maybeSetOnClick_: function(el, method) { 200 maybeSetOnClick_: function(el, method) {
93 if (el) 201 if (el)
94 el.onclick = method; 202 el.onclick = method;
95 }, 203 },
96 204
97 /** 205 /**
98 * @private 206 * @private
99 */ 207 */
100 setUpdateImage_: function(state) { 208 setUpdateImage_: function(state) {
101 $('update-status-icon').className = 'update-icon ' + state; 209 $('update-status-icon').className = 'help-page-icon ' + state;
102 }, 210 },
103 211
104 /** 212 /**
213 * Returns current overlay.
214 * @return {HTMLElement} Current overlay
215 * @private
216 */
217 getCurrentOverlay_: function() {
218 return document.querySelector('#overlay .page.showing');
219 },
220
221 /**
222 * @return {boolean} True, if new channel switcher UI is used,
223 * false otherwise.
224 * @private
225 */
226 isNewChannelSwitcherUI_: function() {
227 return !loadTimeData.valueExists('disableNewChannelSwitcherUI');
228 },
229
230 /**
231 * @return {boolean} True if target and current channels are not
232 * null and not equals
233 * @private
234 */
235 channelsDiffer_: function() {
236 var current = this.currentChannel_;
237 var target = this.targetChannel_;
238 return (current != null && target != null && current != target);
239 },
240
241 /**
105 * @private 242 * @private
106 */ 243 */
107 setUpdateStatus_: function(status, message) { 244 setUpdateStatus_: function(status, message) {
108 if (status == 'checking') { 245 if (status == 'checking') {
109 this.setUpdateImage_('working'); 246 this.setUpdateImage_('working');
110 $('update-status-message').innerHTML = 247 $('update-status-message').innerHTML =
111 loadTimeData.getString('updateCheckStarted'); 248 loadTimeData.getString('updateCheckStarted');
112 } else if (status == 'updating') { 249 } else if (status == 'updating') {
113 this.setUpdateImage_('working'); 250 this.setUpdateImage_('working');
114 $('update-status-message').innerHTML = 251 if (this.channelsDiffer_()) {
115 loadTimeData.getString('updating'); 252 $('update-status-message').innerHTML =
253 loadTimeData.getStringF('updatingChannelSwitch',
254 this.channelTable_[channel].label);
255 } else {
256 $('update-status-message').innerHTML =
257 loadTimeData.getStringF('updating');
258 }
116 } else if (status == 'nearly_updated') { 259 } else if (status == 'nearly_updated') {
117 this.setUpdateImage_('up-to-date'); 260 this.setUpdateImage_('up-to-date');
118 $('update-status-message').innerHTML = 261 if (this.channelsDiffer_()) {
119 loadTimeData.getString('updateAlmostDone'); 262 $('update-status-message').innerHTML =
263 loadTimeData.getString('successfulChannelSwitch');
264 } else {
265 $('update-status-message').innerHTML =
266 loadTimeData.getString('updateAlmostDone');
267 }
120 } else if (status == 'updated') { 268 } else if (status == 'updated') {
121 this.setUpdateImage_('up-to-date'); 269 this.setUpdateImage_('up-to-date');
122 $('update-status-message').innerHTML = 270 $('update-status-message').innerHTML =
123 loadTimeData.getString('upToDate'); 271 loadTimeData.getString('upToDate');
124 } else if (status == 'failed') { 272 } else if (status == 'failed') {
125 this.setUpdateImage_('failed'); 273 this.setUpdateImage_('failed');
126 $('update-status-message').innerHTML = message; 274 $('update-status-message').innerHTML = message;
127 } 275 }
128 276
129 var container = $('update-status-container'); 277 var container = $('update-status-container');
130 if (container) { 278 if (container) {
131 container.hidden = status == 'disabled'; 279 container.hidden = status == 'disabled';
132 $('relaunch').hidden = status != 'nearly_updated'; 280 $('relaunch').hidden = status != 'nearly_updated';
133 281
282 // It's allowed to do powerwash only for customer devices,
283 // when user explicitly decides to update to a more stable
284 // channel.
285 $('relaunch-and-powerwash').hidden =
286 !this.powerwashAfterUpdate_ || status != 'nearly_updated';
287
134 if (!cr.isMac) 288 if (!cr.isMac)
135 $('update-percentage').hidden = status != 'updating'; 289 $('update-percentage').hidden = status != 'updating';
136 } 290 }
137 }, 291 },
138 292
139 /** 293 /**
140 * @private 294 * @private
141 */ 295 */
142 setProgress_: function(progress) { 296 setProgress_: function(progress) {
143 $('update-percentage').innerHTML = progress + '%'; 297 $('update-percentage').innerHTML = progress + '%';
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 $('firmware').textContent = firmware; 348 $('firmware').textContent = firmware;
195 }, 349 },
196 350
197 /** 351 /**
198 * Sets the given overlay to show. This hides whatever overlay is currently 352 * Sets the given overlay to show. This hides whatever overlay is currently
199 * showing, if any. 353 * showing, if any.
200 * @param {HTMLElement} node The overlay page to show. If null, all 354 * @param {HTMLElement} node The overlay page to show. If null, all
201 * overlays are hidden. 355 * overlays are hidden.
202 */ 356 */
203 showOverlay_: function(node) { 357 showOverlay_: function(node) {
204 var currentlyShowingOverlay = 358 var currentlyShowingOverlay = this.getCurrentOverlay_();
205 document.querySelector('#overlay .page.showing');
206 if (currentlyShowingOverlay) 359 if (currentlyShowingOverlay)
207 currentlyShowingOverlay.classList.remove('showing'); 360 currentlyShowingOverlay.classList.remove('showing');
208
209 if (node) 361 if (node)
210 node.classList.add('showing'); 362 node.classList.add('showing');
211 $('overlay').hidden = !node; 363 $('overlay-container').hidden = !node;
364 },
365
366 /**
367 * Updates name of the current channel, i.e. the name of the
368 * channel the device is currently on.
369 * @param {string} channel The name of the current channel
370 * @private
371 */
372 updateCurrentChannel_: function(channel) {
373 if (this.channelList_.indexOf(channel) < 0)
374 return;
375 $('current-channel').textContent = loadTimeData.getStringF(
376 'currentChannel', this.channelTable_[channel].label);
377 this.currentChannel_ = channel;
378 help.ChannelChangePage.updateCurrentChannel(channel);
212 }, 379 },
213 380
214 /** 381 /**
215 * |enabled| is true if the release channel can be enabled. 382 * |enabled| is true if the release channel can be enabled.
216 * @private 383 * @private
217 */ 384 */
218 updateEnableReleaseChannel_: function(enabled) { 385 updateEnableReleaseChannel_: function(enabled) {
219 $('channel-changer-container').hidden = !enabled; 386 this.updateChannelChangerContainerVisibility_(enabled);
387 $('change-channel').disabled = !enabled;
388 $('channel-change-disallowed-icon').hidden = enabled;
220 }, 389 },
221 390
222 /** 391 /**
392 * Sets the device target channel.
393 * @param {string} channel The name of the target channel
394 * @param {boolean} isPowerwashAllowed True iff powerwash is allowed
223 * @private 395 * @private
224 */ 396 */
225 updateSelectedChannel_: function(value) { 397 setChannel_: function(channel, isPowerwashAllowed) {
226 var options = $('channel-changer').querySelectorAll('option'); 398 this.powerwashAfterUpdate_ = isPowerwashAllowed;
227 for (var i = 0; i < options.length; i++) { 399 this.targetChannel_ = channel;
228 var option = options[i]; 400 chrome.send('setChannel', [channel, isPowerwashAllowed]);
229 if (option.value == value) 401 $('channel-change-confirmation').hidden = false;
230 option.selected = true; 402 $('channel-change-confirmation').textContent = loadTimeData.getStringF(
231 } 403 'channel-changed', this.channelTable_[channel].name);
232 }, 404 },
233 405
234 /** 406 /**
235 * @private
236 */
237 setReleaseChannel_: function(channel) {
238 chrome.send('setReleaseTrack', [channel]);
239 $('channel-change-confirmation').hidden = false;
240 $('channel-change-confirmation').textContent = loadTimeData.getStringF(
241 'channel-changed', this.channelName_[channel]);
242 },
243
244 /**
245 * Sets the value of the "Build Date" field of the "More Info" section. 407 * Sets the value of the "Build Date" field of the "More Info" section.
246 * @param {string} buildDate The date of the build. 408 * @param {string} buildDate The date of the build.
247 * @private 409 * @private
248 */ 410 */
249 setBuildDate_: function(buildDate) { 411 setBuildDate_: function(buildDate) {
250 $('build-date-container').classList.remove('empty'); 412 $('build-date-container').classList.remove('empty');
251 $('build-date').textContent = buildDate; 413 $('build-date').textContent = buildDate;
252 }, 414 },
415
416 /**
417 * Updates channel-change-page-container visibility according to
418 * internal state.
419 * @private
420 */
421 updateChannelChangePageContainerVisibility_: function() {
422 if (!this.isNewChannelSwitcherUI_()) {
423 $('channel-change-page-container').hidden = true;
424 return;
425 }
426 $('channel-change-page-container').hidden =
427 !help.ChannelChangePage.isPageReady();
428 },
429
430 /**
431 * Updates channel-changer dropdown visibility if |visible| is
432 * true and new channel switcher UI is disallowed.
433 * @param {boolean} visible True if channel-changer should be
434 * displayed, false otherwise.
435 * @private
436 */
437 updateChannelChangerContainerVisibility_: function(visible) {
438 if (this.isNewChannelSwitcherUI_()) {
439 $('channel-changer').hidden = true;
440 return;
441 }
442 $('channel-changer').hidden = !visible;
443 },
253 }; 444 };
254 445
255 HelpPage.setUpdateStatus = function(status, message) { 446 HelpPage.setUpdateStatus = function(status, message) {
256 HelpPage.getInstance().setUpdateStatus_(status, message); 447 HelpPage.getInstance().setUpdateStatus_(status, message);
257 }; 448 };
258 449
259 HelpPage.setProgress = function(progress) { 450 HelpPage.setProgress = function(progress) {
260 HelpPage.getInstance().setProgress_(progress); 451 HelpPage.getInstance().setProgress_(progress);
261 }; 452 };
262 453
(...skipping 19 matching lines...) Expand all
282 }; 473 };
283 474
284 HelpPage.setOSFirmware = function(firmware) { 475 HelpPage.setOSFirmware = function(firmware) {
285 HelpPage.getInstance().setOSFirmware_(firmware); 476 HelpPage.getInstance().setOSFirmware_(firmware);
286 }; 477 };
287 478
288 HelpPage.showOverlay = function(node) { 479 HelpPage.showOverlay = function(node) {
289 HelpPage.getInstance().showOverlay_(node); 480 HelpPage.getInstance().showOverlay_(node);
290 }; 481 };
291 482
292 HelpPage.updateSelectedChannel = function(channel) { 483 HelpPage.cancelOverlay = function() {
293 HelpPage.getInstance().updateSelectedChannel_(channel); 484 HelpPage.getInstance().showOverlay_(null);
485 };
486
487 HelpPage.updateIsEnterpriseManaged = function(isEnterpriseManaged) {
488 if (!cr.isChromeOS)
489 return;
490 help.ChannelChangePage.updateIsEnterpriseManaged(isEnterpriseManaged);
491 };
492
493 HelpPage.updateCurrentChannel = function(channel) {
494 if (!cr.isChromeOS)
495 return;
496 HelpPage.getInstance().updateCurrentChannel_(channel);
497 };
498
499 HelpPage.updateTargetChannel = function(channel) {
500 if (!cr.isChromeOS)
501 return;
502 help.ChannelChangePage.updateTargetChannel(channel);
294 }; 503 };
295 504
296 HelpPage.updateEnableReleaseChannel = function(enabled) { 505 HelpPage.updateEnableReleaseChannel = function(enabled) {
297 HelpPage.getInstance().updateEnableReleaseChannel_(enabled); 506 HelpPage.getInstance().updateEnableReleaseChannel_(enabled);
298 }; 507 };
299 508
300 HelpPage.setReleaseChannel = function(channel) { 509 HelpPage.setChannel = function(channel, isPowerwashAllowed) {
301 HelpPage.getInstance().setReleaseChannel_(channel); 510 HelpPage.getInstance().setChannel_(channel, isPowerwashAllowed);
302 }; 511 };
303 512
304 HelpPage.setBuildDate = function(buildDate) { 513 HelpPage.setBuildDate = function(buildDate) {
305 HelpPage.getInstance().setBuildDate_(buildDate); 514 HelpPage.getInstance().setBuildDate_(buildDate);
306 } 515 };
516
517 HelpPage.updateChannelChangePageContainerVisibility = function() {
518 HelpPage.getInstance().updateChannelChangePageContainerVisibility_();
519 };
307 520
308 // Export 521 // Export
309 return { 522 return {
310 HelpPage: HelpPage 523 HelpPage: HelpPage
311 }; 524 };
312 }); 525 });
313 526
314 /** 527 /**
315 * onload listener to initialize the HelpPage. 528 * onload listener to initialize the HelpPage.
316 */ 529 */
317 window.onload = function() { 530 window.onload = function() {
318 help.HelpPage.getInstance().initialize(); 531 help.HelpPage.getInstance().initialize();
532 help.ChannelChangePage.getInstance().initialize();
319 }; 533 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698