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

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 /**
19 * Perform initial setup. 37 * Perform initial setup.
20 */ 38 */
21 initialize: function() { 39 initialize: function() {
40 var self = this;
41
22 uber.onContentFrameLoaded(); 42 uber.onContentFrameLoaded();
23 43
24 // Set the title. 44 // Set the title.
25 var title = loadTimeData.getString('helpTitle'); 45 var title = loadTimeData.getString('helpTitle');
26 uber.invokeMethodOnParent('setTitle', {title: title}); 46 uber.invokeMethodOnParent('setTitle', {title: title});
27 47
28 $('product-license').innerHTML = loadTimeData.getString('productLicense'); 48 $('product-license').innerHTML = loadTimeData.getString('productLicense');
29 if (cr.isChromeOS) { 49 if (cr.isChromeOS) {
30 $('product-os-license').innerHTML = 50 $('product-os-license').innerHTML =
31 loadTimeData.getString('productOsLicense'); 51 loadTimeData.getString('productOsLicense');
(...skipping 12 matching lines...) Expand all
44 64
45 this.maybeSetOnClick_($('more-info-expander'), 65 this.maybeSetOnClick_($('more-info-expander'),
46 this.toggleMoreInfo_.bind(this)); 66 this.toggleMoreInfo_.bind(this));
47 67
48 this.maybeSetOnClick_($('promote'), function() { 68 this.maybeSetOnClick_($('promote'), function() {
49 chrome.send('promoteUpdater'); 69 chrome.send('promoteUpdater');
50 }); 70 });
51 this.maybeSetOnClick_($('relaunch'), function() { 71 this.maybeSetOnClick_($('relaunch'), function() {
52 chrome.send('relaunchNow'); 72 chrome.send('relaunchNow');
53 }); 73 });
74 this.maybeSetOnClick_($('relaunch-and-powerwash'), function() {
75 chrome.send('performFactoryResetRestart');
76 });
77
78 this.channelTable_ = {
79 'stable-channel': {
80 'name': loadTimeData.getString('stable'),
81 'label': loadTimeData.getString('currentChannelStable')
82 },
83 'beta-channel': {
84 'name': loadTimeData.getString('beta'),
85 'label': loadTimeData.getString('currentChannelBeta')
86 },
87 'dev-channel': {
88 'name': loadTimeData.getString('dev'),
89 'label': loadTimeData.getString('currentChannelDev')
90 }
91 };
54 92
55 var channelChanger = $('channel-changer'); 93 var channelChanger = $('channel-changer');
56 if (channelChanger) { 94 if (channelChanger) {
57 this.channelName_ = { 95 channelChanger.onchange = function(event) {
58 'stable-channel': loadTimeData.getString('stable'), 96 self.setChannnel_(event.target.value, false);
59 'beta-channel': loadTimeData.getString('beta'),
60 'dev-channel': loadTimeData.getString('dev')
61 }; 97 };
62 var self = this;
63 channelChanger.onchange = function(event) {
64 self.setReleaseChannel_(event.target.value);
65 }
66 } 98 }
67 99
100 cr.ui.overlay.globalInitialization();
101 cr.ui.overlay.setupOverlay($('overlay-container'));
102 $('overlay-container').addEventListener('cancelOverlay', function() {
103 self.showOverlay_(null);
104 });
105
106 $('change-channel').onclick = function() {
107 self.showOverlay_($('channel-change-page'));
108 };
109
110 // Create the DOM tree
Nikita (slow) 2013/06/21 12:58:04 nit: drop comment
ygorshenin1 2013/06/21 17:24:58 Done.
111 var channelChangeDisallowedError = document.createElement('div');
112 channelChangeDisallowedError.className = 'channel-change-error-bubble';
113
114 var channelChangeDisallowedIcon = document.createElement('div');
115 channelChangeDisallowedIcon.classList.add('help-page-icon-large');
116 channelChangeDisallowedIcon.classList.add('channel-change-error-icon');
117 channelChangeDisallowedError.appendChild(channelChangeDisallowedIcon);
118
119 var channelChangeDisallowedText = document.createElement('div');
120 channelChangeDisallowedText.className = 'channel-change-error-text';
121 channelChangeDisallowedText.textContent =
122 loadTimeData.getString('channelChangeDisallowedMessage');
123 channelChangeDisallowedError.appendChild(channelChangeDisallowedText);
124
125 $('channel-change-disallowed-icon').onclick = function() {
126 self.showBubble_(channelChangeDisallowedError,
127 $('help-container'),
128 $('channel-change-disallowed-icon'),
129 cr.ui.ArrowLocation.TOP_END);
130 };
131
68 // Attempt to update. 132 // Attempt to update.
69 chrome.send('onPageLoaded'); 133 chrome.send('onPageLoaded');
70 }, 134 },
71 135
72 /** 136 /**
137 * Shows the bubble.
138 * @param {HTMLDivElement} content The content of the bubble.
139 * @param {HTMLElement} target The element at which the bubble points.
140 * @param {HTMLElement} domSibling The element after which the bubble is
141 * added to the DOM.
142 * @param {cr.ui.ArrowLocation} location The arrow location.
143 * @private
144 */
145 showBubble_: function(content, domSibling, target, location) {
146 this.hideBubble_();
147 var bubble = new cr.ui.AutoCloseBubble;
148 bubble.anchorNode = target;
149 bubble.domSibling = domSibling;
150 bubble.arrowLocation = location;
151 bubble.content = content;
152 bubble.show();
153 this.bubble_ = bubble;
154 },
155
156 /**
157 * Hides the bubble.
158 * @private
159 */
160 hideBubble_: function() {
161 if (this.bubble_)
162 this.bubble_.hide();
163 },
164
165 /**
73 * Toggles the visible state of the 'More Info' section. 166 * Toggles the visible state of the 'More Info' section.
74 * @private 167 * @private
75 */ 168 */
76 toggleMoreInfo_: function() { 169 toggleMoreInfo_: function() {
77 var moreInfo = $('more-info-container'); 170 var moreInfo = $('more-info-container');
78 var visible = moreInfo.className == 'visible'; 171 var visible = moreInfo.className == 'visible';
79 moreInfo.className = visible ? '' : 'visible'; 172 moreInfo.className = visible ? '' : 'visible';
80 moreInfo.style.height = visible ? '' : moreInfo.scrollHeight + 'px'; 173 moreInfo.style.height = visible ? '' : moreInfo.scrollHeight + 'px';
81 moreInfo.addEventListener('webkitTransitionEnd', function(event) { 174 moreInfo.addEventListener('webkitTransitionEnd', function(event) {
82 $('more-info-expander').textContent = visible ? 175 $('more-info-expander').textContent = visible ?
83 loadTimeData.getString('showMoreInfo') : 176 loadTimeData.getString('showMoreInfo') :
84 loadTimeData.getString('hideMoreInfo'); 177 loadTimeData.getString('hideMoreInfo');
85 }); 178 });
86 }, 179 },
87 180
88 /** 181 /**
89 * Assigns |method| to the onclick property of |el| if |el| exists. 182 * Assigns |method| to the onclick property of |el| if |el| exists.
90 * @private 183 * @private
91 */ 184 */
92 maybeSetOnClick_: function(el, method) { 185 maybeSetOnClick_: function(el, method) {
93 if (el) 186 if (el)
94 el.onclick = method; 187 el.onclick = method;
95 }, 188 },
96 189
97 /** 190 /**
98 * @private 191 * @private
99 */ 192 */
100 setUpdateImage_: function(state) { 193 setUpdateImage_: function(state) {
101 $('update-status-icon').className = 'update-icon ' + state; 194 $('update-status-icon').className = 'help-page-icon ' + state;
102 }, 195 },
103 196
104 /** 197 /**
198 * Returns current overlay.
199 * @return {HTMLElement} Current overlay
200 * @private
201 */
202 getCurrentOverlay_: function() {
203 return document.querySelector('#overlay .page.showing');
204 },
205
206 /**
207 * @return {boolean} True, if new channel switcher UI is used,
208 * false otherwise.
209 * @private
210 */
211 isNewChannelSwitcherUI_: function() {
212 return !loadTimeData.valueExists('disableNewChannelSwitcherUI');
Nikita (slow) 2013/06/21 12:58:04 Where is this flag defined, passed?
ygorshenin1 2013/06/21 17:24:58 The flag isn't defined. This code is needed becaus
213 },
214
215 /**
105 * @private 216 * @private
106 */ 217 */
107 setUpdateStatus_: function(status, message) { 218 setUpdateStatus_: function(status, message) {
108 if (status == 'checking') { 219 if (status == 'checking') {
109 this.setUpdateImage_('working'); 220 this.setUpdateImage_('working');
110 $('update-status-message').innerHTML = 221 $('update-status-message').innerHTML =
111 loadTimeData.getString('updateCheckStarted'); 222 loadTimeData.getString('updateCheckStarted');
112 } else if (status == 'updating') { 223 } else if (status == 'updating') {
113 this.setUpdateImage_('working'); 224 this.setUpdateImage_('working');
114 $('update-status-message').innerHTML = 225 $('update-status-message').innerHTML =
115 loadTimeData.getString('updating'); 226 loadTimeData.getString('updating');
116 } else if (status == 'nearly_updated') { 227 } else if (status == 'nearly_updated') {
117 this.setUpdateImage_('up-to-date'); 228 this.setUpdateImage_('up-to-date');
118 $('update-status-message').innerHTML = 229 $('update-status-message').innerHTML =
119 loadTimeData.getString('updateAlmostDone'); 230 loadTimeData.getString('updateAlmostDone');
120 } else if (status == 'updated') { 231 } else if (status == 'updated') {
121 this.setUpdateImage_('up-to-date'); 232 this.setUpdateImage_('up-to-date');
122 $('update-status-message').innerHTML = 233 $('update-status-message').innerHTML =
123 loadTimeData.getString('upToDate'); 234 loadTimeData.getString('upToDate');
124 } else if (status == 'failed') { 235 } else if (status == 'failed') {
125 this.setUpdateImage_('failed'); 236 this.setUpdateImage_('failed');
126 $('update-status-message').innerHTML = message; 237 $('update-status-message').innerHTML = message;
127 } 238 }
128 239
129 var container = $('update-status-container'); 240 var container = $('update-status-container');
130 if (container) { 241 if (container) {
131 container.hidden = status == 'disabled'; 242 container.hidden = status == 'disabled';
132 $('relaunch').hidden = status != 'nearly_updated'; 243 $('relaunch').hidden = status != 'nearly_updated';
244 $('relaunch-and-powerwash').hidden =
Nikita (slow) 2013/06/21 12:58:04 nit: Please add comment to clarify login when we a
ygorshenin1 2013/06/21 17:24:58 Done.
245 !this.powerwashAfterUpdate_ || status != 'updated';
133 246
134 if (!cr.isMac) 247 if (!cr.isMac)
135 $('update-percentage').hidden = status != 'updating'; 248 $('update-percentage').hidden = status != 'updating';
136 } 249 }
137 }, 250 },
138 251
139 /** 252 /**
140 * @private 253 * @private
141 */ 254 */
142 setProgress_: function(progress) { 255 setProgress_: function(progress) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 $('firmware').textContent = firmware; 307 $('firmware').textContent = firmware;
195 }, 308 },
196 309
197 /** 310 /**
198 * Sets the given overlay to show. This hides whatever overlay is currently 311 * Sets the given overlay to show. This hides whatever overlay is currently
199 * showing, if any. 312 * showing, if any.
200 * @param {HTMLElement} node The overlay page to show. If null, all 313 * @param {HTMLElement} node The overlay page to show. If null, all
201 * overlays are hidden. 314 * overlays are hidden.
202 */ 315 */
203 showOverlay_: function(node) { 316 showOverlay_: function(node) {
204 var currentlyShowingOverlay = 317 var currentlyShowingOverlay = this.getCurrentOverlay_();
205 document.querySelector('#overlay .page.showing');
206 if (currentlyShowingOverlay) 318 if (currentlyShowingOverlay)
207 currentlyShowingOverlay.classList.remove('showing'); 319 currentlyShowingOverlay.classList.remove('showing');
208
209 if (node) 320 if (node)
210 node.classList.add('showing'); 321 node.classList.add('showing');
211 $('overlay').hidden = !node; 322 $('overlay-container').hidden = !node;
323 },
324
325 /**
326 * Updates name of the current channel, i.e. the name of the
327 * channel the device is currently on.
328 * @param {string} channel The name of the current channel
329 * @private
330 */
331 updateCurrentChannel_: function(channel) {
332 if (this.channelList_.indexOf(channel) < 0)
333 return;
334 $('current-channel').textContent = loadTimeData.getStringF(
335 'currentChannel', this.channelTable_[channel].label);
336 help.ChannelChangePage.updateCurrentChannel(channel);
212 }, 337 },
213 338
214 /** 339 /**
215 * |enabled| is true if the release channel can be enabled. 340 * |enabled| is true if the release channel can be enabled.
216 * @private 341 * @private
217 */ 342 */
218 updateEnableReleaseChannel_: function(enabled) { 343 updateEnableReleaseChannel_: function(enabled) {
219 $('channel-changer-container').hidden = !enabled; 344 this.updateChannelChangePageContainerVisibility_(enabled);
345 $('change-channel').disabled = !enabled;
346 $('channel-change-disallowed-icon').hidden = enabled;
220 }, 347 },
221 348
222 /** 349 /**
350 * Sets the device target channel.
351 * @param {string} channel The name of the target channel
352 * @param {boolean} isPowerwashAllowed True iff powerwash is allowed
223 * @private 353 * @private
224 */ 354 */
225 updateSelectedChannel_: function(value) { 355 setChannel_: function(channel, isPowerwashAllowed) {
226 var options = $('channel-changer').querySelectorAll('option'); 356 this.powerwashAfterUpdate_ = isPowerwashAllowed;
227 for (var i = 0; i < options.length; i++) { 357 chrome.send('setChannel', [channel, isPowerwashAllowed]);
228 var option = options[i]; 358 $('channel-change-confirmation').hidden = false;
229 if (option.value == value) 359 $('channel-change-confirmation').textContent = loadTimeData.getStringF(
230 option.selected = true; 360 'channel-changed', this.channelTable_[channel].name);
231 }
232 }, 361 },
233 362
234 /** 363 /**
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. 364 * Sets the value of the "Build Date" field of the "More Info" section.
246 * @param {string} buildDate The date of the build. 365 * @param {string} buildDate The date of the build.
247 * @private 366 * @private
248 */ 367 */
249 setBuildDate_: function(buildDate) { 368 setBuildDate_: function(buildDate) {
250 $('build-date-container').classList.remove('empty'); 369 $('build-date-container').classList.remove('empty');
251 $('build-date').textContent = buildDate; 370 $('build-date').textContent = buildDate;
252 }, 371 },
372
373 /**
374 * Updates channel-change-page-container visibility according to
375 * internal state.
376 * @private
377 */
378 updateChannelChangePageContainerVisibility_: function() {
379 if (!this.isNewChannelSwitcherUI_()) {
380 $('channel-change-page-container').hidden = true;
Nikita (slow) 2013/06/21 12:58:04 Not clear what exactly is left for old UI.
ygorshenin1 2013/06/21 17:24:58 channel-changer div contains old channel switcher
381 return;
382 }
383 $('channel-change-page-container').hidden =
384 help.ChannelChangePage.isPageReady();
385 },
386
387 /**
388 * Updates channel-changer dropdown visibility if |visible| is
389 * true and new channel switcher UI is disallowed.
390 * @param {boolean} visible True if channel-changer should be
391 * displayed, false otherwise.
392 * @private
393 */
394 updateChannelChangerContainerVisibility_: function(visible) {
395 if (this.isNewChannelSwitcherUI_()) {
396 $('channel-changer').hidden = true;
397 return;
398 }
399 $('channel-changer').hidden = !visible;
400 },
253 }; 401 };
254 402
255 HelpPage.setUpdateStatus = function(status, message) { 403 HelpPage.setUpdateStatus = function(status, message) {
256 HelpPage.getInstance().setUpdateStatus_(status, message); 404 HelpPage.getInstance().setUpdateStatus_(status, message);
257 }; 405 };
258 406
259 HelpPage.setProgress = function(progress) { 407 HelpPage.setProgress = function(progress) {
260 HelpPage.getInstance().setProgress_(progress); 408 HelpPage.getInstance().setProgress_(progress);
261 }; 409 };
262 410
(...skipping 19 matching lines...) Expand all
282 }; 430 };
283 431
284 HelpPage.setOSFirmware = function(firmware) { 432 HelpPage.setOSFirmware = function(firmware) {
285 HelpPage.getInstance().setOSFirmware_(firmware); 433 HelpPage.getInstance().setOSFirmware_(firmware);
286 }; 434 };
287 435
288 HelpPage.showOverlay = function(node) { 436 HelpPage.showOverlay = function(node) {
289 HelpPage.getInstance().showOverlay_(node); 437 HelpPage.getInstance().showOverlay_(node);
290 }; 438 };
291 439
292 HelpPage.updateSelectedChannel = function(channel) { 440 HelpPage.cancelOverlay = function() {
293 HelpPage.getInstance().updateSelectedChannel_(channel); 441 HelpPage.getInstance().showOverlay_(null);
442 };
443
444 HelpPage.updateIsEnterpriseManaged = function(isEnterpriseManaged) {
445 help.ChannelChangePage.updateIsEnterpriseManaged(isEnterpriseManaged);
446 };
447
448 HelpPage.updateCurrentChannel = function(channel) {
449 HelpPage.getInstance().updateCurrentChannel_(channel);
450 };
451
452 HelpPage.updateTargetChannel = function(channel) {
453 help.ChannelChangePage.updateTargetChannel(channel);
294 }; 454 };
295 455
296 HelpPage.updateEnableReleaseChannel = function(enabled) { 456 HelpPage.updateEnableReleaseChannel = function(enabled) {
297 HelpPage.getInstance().updateEnableReleaseChannel_(enabled); 457 HelpPage.getInstance().updateEnableReleaseChannel_(enabled);
298 }; 458 };
299 459
300 HelpPage.setReleaseChannel = function(channel) { 460 HelpPage.setChannel = function(channel, isPowerwashAllowed) {
301 HelpPage.getInstance().setReleaseChannel_(channel); 461 HelpPage.getInstance().setChannel_(channel, isPowerwashAllowed);
302 }; 462 };
303 463
304 HelpPage.setBuildDate = function(buildDate) { 464 HelpPage.setBuildDate = function(buildDate) {
305 HelpPage.getInstance().setBuildDate_(buildDate); 465 HelpPage.getInstance().setBuildDate_(buildDate);
306 } 466 };
467
468 HelpPage.updateChannelChangePageContainerVisibility = function() {
469 HelpPage.getInstance().updateChannelChangePageContainerVisibility_();
470 };
307 471
308 // Export 472 // Export
309 return { 473 return {
310 HelpPage: HelpPage 474 HelpPage: HelpPage
311 }; 475 };
312 }); 476 });
313 477
314 /** 478 /**
315 * onload listener to initialize the HelpPage. 479 * onload listener to initialize the HelpPage.
316 */ 480 */
317 window.onload = function() { 481 window.onload = function() {
318 help.HelpPage.getInstance().initialize(); 482 help.HelpPage.getInstance().initialize();
483 help.ChannelChangePage.getInstance().initialize();
319 }; 484 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698