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

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

Powered by Google App Engine
This is Rietveld 408576698