Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * Class representing an entry in the host-list portion of the home screen. | 7 * Class representing an entry in the host-list portion of the home screen. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 this.tableRow.title = ''; | 196 this.tableRow.title = ''; |
| 197 } | 197 } |
| 198 var showOffline = this.host.status != 'ONLINE'; | 198 var showOffline = this.host.status != 'ONLINE'; |
| 199 if (showOffline) { | 199 if (showOffline) { |
| 200 this.tableRow.classList.remove('host-online'); | 200 this.tableRow.classList.remove('host-online'); |
| 201 this.tableRow.classList.add('host-offline'); | 201 this.tableRow.classList.add('host-offline'); |
| 202 } else { | 202 } else { |
| 203 this.tableRow.classList.add('host-online'); | 203 this.tableRow.classList.add('host-online'); |
| 204 this.tableRow.classList.remove('host-offline'); | 204 this.tableRow.classList.remove('host-offline'); |
| 205 } | 205 } |
| 206 this.warningOverlay_.hidden = !remoting.Host.needsUpdate( | 206 var hostReportedError = this.host.hostOfflineReason != ""; |
| 207 var hostNeedsUpdate = remoting.Host.needsUpdate( | |
| 207 this.host, this.webappMajorVersion_); | 208 this.host, this.webappMajorVersion_); |
| 209 this.warningOverlay_.hidden = !hostNeedsUpdate && !hostReportedError; | |
| 208 }; | 210 }; |
| 209 | 211 |
| 210 /** | 212 /** |
| 211 * Prepare the host for renaming by replacing its name with an edit box. | 213 * Prepare the host for renaming by replacing its name with an edit box. |
| 212 * @return {void} Nothing. | 214 * @return {void} Nothing. |
| 213 * @private | 215 * @private |
| 214 */ | 216 */ |
| 215 remoting.HostTableEntry.prototype.beginRename_ = function() { | 217 remoting.HostTableEntry.prototype.beginRename_ = function() { |
| 216 var editBox = | 218 var editBox = |
| 217 /** @type {HTMLInputElement} */ (document.createElement('input')); | 219 /** @type {HTMLInputElement} */ (document.createElement('input')); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 if (editBox) { | 309 if (editBox) { |
| 308 // onblur will fire when the edit box is removed, so remove the hook. | 310 // onblur will fire when the edit box is removed, so remove the hook. |
| 309 editBox.removeEventListener('blur', this.onBlurReference_, false); | 311 editBox.removeEventListener('blur', this.onBlurReference_, false); |
| 310 } | 312 } |
| 311 // Update the tool-top and event handler. | 313 // Update the tool-top and event handler. |
| 312 this.updateStatus(); | 314 this.updateStatus(); |
| 313 this.setHostName_(); | 315 this.setHostName_(); |
| 314 }; | 316 }; |
| 315 | 317 |
| 316 /** | 318 /** |
| 319 * Formats host's updateTime value relative to current time (i.e. only | |
| 320 * displaying hours and minutes if updateTime is less than a day in the past). | |
| 321 * @param {string} updateTime RFC 3339 formatted date-time value. | |
| 322 * @return {string} Formatted value (i.e. 11/11/2014) | |
| 323 */ | |
| 324 function formatUpdateTime(updateTime) { | |
| 325 var lastOnline = new Date(updateTime); | |
| 326 var now = new Date(); | |
| 327 var displayString = ''; | |
| 328 if (now.getFullYear() == lastOnline.getFullYear() && | |
| 329 now.getMonth() == lastOnline.getMonth() && | |
| 330 now.getDate() == lastOnline.getDate()) { | |
| 331 return lastOnline.toLocaleTimeString(); | |
| 332 } else { | |
| 333 return lastOnline.toLocaleDateString(); | |
| 334 } | |
| 335 } | |
| 336 | |
| 337 /** | |
| 338 * Formats host's host-offline-reason value (i.e. "INVALID_HOST_CONFIGURATION_") | |
|
Jamie
2015/02/09 19:57:15
Nit: trailing underscore.
Łukasz Anforowicz
2015/02/09 20:19:13
Ooops. Fixed. Thanks.
| |
| 339 * to a human-readable description of the error. | |
| 340 * @param {string} hostOfflineReason | |
| 341 * @return {string} | |
| 342 */ | |
| 343 function formatHostOfflineReason(hostOfflineReason) { | |
| 344 var knownReasonTags = [ | |
| 345 /*i18n-content*/ "OFFLINE_REASON_INITIALIZATION_FAILED", | |
|
Jamie
2015/02/09 19:57:15
Single-quotes for JS strings, please.
Łukasz Anforowicz
2015/02/09 20:19:13
Done.
| |
| 346 /*i18n-content*/ "OFFLINE_REASON_INVALID_HOST_CONFIGURATION", | |
| 347 /*i18n-content*/ "OFFLINE_REASON_INVALID_HOST_ID", | |
| 348 /*i18n-content*/ "OFFLINE_REASON_INVALID_OAUTH_CREDENTIALS", | |
| 349 /*i18n-content*/ "OFFLINE_REASON_INVALID_HOST_DOMAIN", | |
| 350 /*i18n-content*/ "OFFLINE_REASON_LOGIN_SCREEN_NOT_SUPPORTED", | |
| 351 /*i18n-content*/ "OFFLINE_REASON_USERNAME_MISMATCH" | |
| 352 ]; | |
| 353 var offlineReasonTag = "OFFLINE_REASON_" + hostOfflineReason; | |
| 354 if (knownReasonTags.indexOf(offlineReasonTag) != (-1)) { | |
|
Jamie
2015/02/09 19:57:15
No need for parentheses around -1.
Łukasz Anforowicz
2015/02/09 20:19:13
Acknowledged.
| |
| 355 return chrome.i18n.getMessage(offlineReasonTag); | |
| 356 } else { | |
| 357 return chrome.i18n.getMessage( | |
| 358 /*i18n-content*/ "OFFLINE_REASON_UNKNOWN", | |
| 359 hostOfflineReason); | |
| 360 } | |
| 361 } | |
| 362 | |
| 363 /** | |
| 317 * Create the DOM nodes and event handlers for the hostname cell. | 364 * Create the DOM nodes and event handlers for the hostname cell. |
| 318 * @return {void} Nothing. | 365 * @return {void} Nothing. |
| 319 * @private | 366 * @private |
| 320 */ | 367 */ |
| 321 remoting.HostTableEntry.prototype.setHostName_ = function() { | 368 remoting.HostTableEntry.prototype.setHostName_ = function() { |
| 322 var hostNameNode = /** @type {HTMLElement} */ (document.createElement('a')); | 369 var hostNameNode = /** @type {HTMLElement} */ (document.createElement('a')); |
| 323 if (this.host.status == 'ONLINE') { | 370 if (this.host.status == 'ONLINE') { |
| 324 if (remoting.Host.needsUpdate(this.host, this.webappMajorVersion_)) { | 371 if (remoting.Host.needsUpdate(this.host, this.webappMajorVersion_)) { |
| 325 hostNameNode.innerText = chrome.i18n.getMessage( | 372 hostNameNode.innerText = chrome.i18n.getMessage( |
| 326 /*i18n-content*/'UPDATE_REQUIRED', this.host.hostName); | 373 /*i18n-content*/'UPDATE_REQUIRED', this.host.hostName); |
| 327 } else { | 374 } else { |
| 328 hostNameNode.innerText = this.host.hostName; | 375 hostNameNode.innerText = this.host.hostName; |
| 329 } | 376 } |
| 330 hostNameNode.href = '#'; | 377 hostNameNode.href = '#'; |
| 331 this.registerFocusHandlers_(hostNameNode); | 378 this.registerFocusHandlers_(hostNameNode); |
| 332 /** @type {remoting.HostTableEntry} */ | 379 /** @type {remoting.HostTableEntry} */ |
| 333 var that = this; | 380 var that = this; |
| 334 /** @param {Event} event */ | 381 /** @param {Event} event */ |
| 335 var onKeyDown = function(event) { | 382 var onKeyDown = function(event) { |
| 336 if (that.onConnectReference_ && | 383 if (that.onConnectReference_ && |
| 337 (event.which == 13 || event.which == 32)) { | 384 (event.which == 13 || event.which == 32)) { |
| 338 that.onConnectReference_(); | 385 that.onConnectReference_(); |
| 339 } | 386 } |
| 340 }; | 387 }; |
| 341 hostNameNode.addEventListener('keydown', onKeyDown, false); | 388 hostNameNode.addEventListener('keydown', onKeyDown, false); |
| 342 } else { | 389 } else { |
| 343 if (this.host.updatedTime) { | 390 if (this.host.updatedTime) { |
| 344 var lastOnline = new Date(this.host.updatedTime); | 391 var formattedTime = formatUpdateTime(this.host.updatedTime); |
| 345 var now = new Date(); | 392 hostNameNode.innerText = chrome.i18n.getMessage( |
| 346 var displayString = ''; | 393 /*i18n-content*/'LAST_ONLINE', [this.host.hostName, formattedTime]); |
| 347 if (now.getFullYear() == lastOnline.getFullYear() && | 394 if (this.host.hostOfflineReason) { |
| 348 now.getMonth() == lastOnline.getMonth() && | 395 var detailsText = formatHostOfflineReason(this.host.hostOfflineReason); |
| 349 now.getDate() == lastOnline.getDate()) { | 396 // TODO(lukasza): Put detailsText into a hideable div (title/tooltip |
| 350 displayString = lastOnline.toLocaleTimeString(); | 397 // is not as discoverable + doesn't work well for touchscreens). |
| 351 } else { | 398 hostNameNode.title = detailsText; |
| 352 displayString = lastOnline.toLocaleDateString(); | |
| 353 } | 399 } |
| 354 hostNameNode.innerText = chrome.i18n.getMessage( | |
| 355 /*i18n-content*/'LAST_ONLINE', [this.host.hostName, displayString]); | |
| 356 } else { | 400 } else { |
| 357 hostNameNode.innerText = chrome.i18n.getMessage( | 401 hostNameNode.innerText = chrome.i18n.getMessage( |
| 358 /*i18n-content*/'OFFLINE', this.host.hostName); | 402 /*i18n-content*/'OFFLINE', this.host.hostName); |
| 359 } | 403 } |
| 360 } | 404 } |
| 361 hostNameNode.classList.add('host-list-label'); | 405 hostNameNode.classList.add('host-list-label'); |
| 362 this.hostNameCell_.innerText = ''; // Remove previous contents (if any). | 406 this.hostNameCell_.innerText = ''; // Remove previous contents (if any). |
| 363 this.hostNameCell_.appendChild(hostNameNode); | 407 this.hostNameCell_.appendChild(hostNameNode); |
| 364 }; | 408 }; |
| 365 | 409 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 var element = document.activeElement; | 446 var element = document.activeElement; |
| 403 while (element) { | 447 while (element) { |
| 404 if (element == this.tableRow) { | 448 if (element == this.tableRow) { |
| 405 this.tableRow.classList.add('child-focused'); | 449 this.tableRow.classList.add('child-focused'); |
| 406 return; | 450 return; |
| 407 } | 451 } |
| 408 element = element.parentNode; | 452 element = element.parentNode; |
| 409 } | 453 } |
| 410 this.tableRow.classList.remove('child-focused'); | 454 this.tableRow.classList.remove('child-focused'); |
| 411 }; | 455 }; |
| OLD | NEW |