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

Side by Side Diff: remoting/webapp/crd/js/host_table_entry.js

Issue 882463003: Basic webapp UI for host-offline-reason. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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 /** 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 if (editBox) { 307 if (editBox) {
308 // onblur will fire when the edit box is removed, so remove the hook. 308 // onblur will fire when the edit box is removed, so remove the hook.
309 editBox.removeEventListener('blur', this.onBlurReference_, false); 309 editBox.removeEventListener('blur', this.onBlurReference_, false);
310 } 310 }
311 // Update the tool-top and event handler. 311 // Update the tool-top and event handler.
312 this.updateStatus(); 312 this.updateStatus();
313 this.setHostName_(); 313 this.setHostName_();
314 }; 314 };
315 315
316 /** 316 /**
317 * Formats host's updateTime value relative to current time (i.e. only
318 * displaying hours and minutes if updateTime is less than a day in the past).
319 * @param {string} updateTime RFC 3339 formatted date-time value.
320 * @return {string} Formatted value (i.e. 11/11/2014)
321 */
322 function formatUpdateTime(/** number */ updateTime) {
323 var lastOnline = new Date(updateTime);
324 var now = new Date();
325 var displayString = '';
326 if (now.getFullYear() == lastOnline.getFullYear() &&
327 now.getMonth() == lastOnline.getMonth() &&
328 now.getDate() == lastOnline.getDate()) {
329 return lastOnline.toLocaleTimeString();
330 } else {
331 return lastOnline.toLocaleDateString();
332 }
333 }
334
335 /**
317 * Create the DOM nodes and event handlers for the hostname cell. 336 * Create the DOM nodes and event handlers for the hostname cell.
318 * @return {void} Nothing. 337 * @return {void} Nothing.
319 * @private 338 * @private
320 */ 339 */
321 remoting.HostTableEntry.prototype.setHostName_ = function() { 340 remoting.HostTableEntry.prototype.setHostName_ = function() {
322 var hostNameNode = /** @type {HTMLElement} */ (document.createElement('a')); 341 var hostNameNode = /** @type {HTMLElement} */ (document.createElement('a'));
323 if (this.host.status == 'ONLINE') { 342 if (this.host.status == 'ONLINE') {
324 if (remoting.Host.needsUpdate(this.host, this.webappMajorVersion_)) { 343 if (remoting.Host.needsUpdate(this.host, this.webappMajorVersion_)) {
325 hostNameNode.innerText = chrome.i18n.getMessage( 344 hostNameNode.innerText = chrome.i18n.getMessage(
326 /*i18n-content*/'UPDATE_REQUIRED', this.host.hostName); 345 /*i18n-content*/'UPDATE_REQUIRED', this.host.hostName);
327 } else { 346 } else {
328 hostNameNode.innerText = this.host.hostName; 347 hostNameNode.innerText = this.host.hostName;
329 } 348 }
330 hostNameNode.href = '#'; 349 hostNameNode.href = '#';
331 this.registerFocusHandlers_(hostNameNode); 350 this.registerFocusHandlers_(hostNameNode);
332 /** @type {remoting.HostTableEntry} */ 351 /** @type {remoting.HostTableEntry} */
333 var that = this; 352 var that = this;
334 /** @param {Event} event */ 353 /** @param {Event} event */
335 var onKeyDown = function(event) { 354 var onKeyDown = function(event) {
336 if (that.onConnectReference_ && 355 if (that.onConnectReference_ &&
337 (event.which == 13 || event.which == 32)) { 356 (event.which == 13 || event.which == 32)) {
338 that.onConnectReference_(); 357 that.onConnectReference_();
339 } 358 }
340 }; 359 };
341 hostNameNode.addEventListener('keydown', onKeyDown, false); 360 hostNameNode.addEventListener('keydown', onKeyDown, false);
342 } else { 361 } else {
343 if (this.host.updatedTime) { 362 if (this.host.hostOfflineReason) {
344 var lastOnline = new Date(this.host.updatedTime); 363 var formattedTime = formatUpdateTime(this.host.updatedTime);
345 var now = new Date(); 364 hostNameNode.innerText = chrome.i18n.getMessage(
346 var displayString = ''; 365 /*i18n-content*/'LAST_OFFLINE_REASON',
347 if (now.getFullYear() == lastOnline.getFullYear() && 366 [this.host.hostName, formattedTime]);
348 now.getMonth() == lastOnline.getMonth() && 367 var detailsText = chrome.i18n.getMessage(
349 now.getDate() == lastOnline.getDate()) { 368 'OFFLINE_REASON_' +
350 displayString = lastOnline.toLocaleTimeString(); 369 this.host.hostOfflineReason + '_GENERATED_AT_RUNTIME',
Jamie 2015/02/07 00:46:46 Rather than constructing this tag programmatically
Łukasz Anforowicz 2015/02/09 19:21:58 Good idea. Done.
351 } else { 370 [this.host.hostName, formattedTime]);
352 displayString = lastOnline.toLocaleDateString(); 371 if (!detailsText) {
372 detailsText = chrome.i18n.getMessage(
373 /*i18n-content*/'OFFLINE_REASON_UNKNOWN',
374 [this.host.hostOfflineReason, formattedTime]);
Jamie 2015/02/07 00:46:46 The time is already included in the status string.
Łukasz Anforowicz 2015/02/09 19:21:58 Ok - removed.
353 } 375 }
376 // TODO(lukasza): Put detailsText into a hideable div (title/tooltip
377 // is not as discoverable + doesn't work well for touchscreens).
378 hostNameNode.title = detailsText;
379 }
380 else if (this.host.updatedTime) {
381 var formattedTime = formatUpdateTime(this.host.updatedTime);
354 hostNameNode.innerText = chrome.i18n.getMessage( 382 hostNameNode.innerText = chrome.i18n.getMessage(
355 /*i18n-content*/'LAST_ONLINE', [this.host.hostName, displayString]); 383 /*i18n-content*/'LAST_ONLINE', [this.host.hostName, formattedTime]);
356 } else { 384 } else {
357 hostNameNode.innerText = chrome.i18n.getMessage( 385 hostNameNode.innerText = chrome.i18n.getMessage(
358 /*i18n-content*/'OFFLINE', this.host.hostName); 386 /*i18n-content*/'OFFLINE', this.host.hostName);
359 } 387 }
360 } 388 }
361 hostNameNode.classList.add('host-list-label'); 389 hostNameNode.classList.add('host-list-label');
362 this.hostNameCell_.innerText = ''; // Remove previous contents (if any). 390 this.hostNameCell_.innerText = ''; // Remove previous contents (if any).
363 this.hostNameCell_.appendChild(hostNameNode); 391 this.hostNameCell_.appendChild(hostNameNode);
364 }; 392 };
365 393
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 var element = document.activeElement; 430 var element = document.activeElement;
403 while (element) { 431 while (element) {
404 if (element == this.tableRow) { 432 if (element == this.tableRow) {
405 this.tableRow.classList.add('child-focused'); 433 this.tableRow.classList.add('child-focused');
406 return; 434 return;
407 } 435 }
408 element = element.parentNode; 436 element = element.parentNode;
409 } 437 }
410 this.tableRow.classList.remove('child-focused'); 438 this.tableRow.classList.remove('child-focused');
411 }; 439 };
OLDNEW
« remoting/resources/remoting_strings.grd ('K') | « remoting/webapp/crd/js/host.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698