OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview |
| 7 * Class representing the host-list portion of the home screen UI. |
| 8 */ |
| 9 |
| 10 'use strict'; |
| 11 |
| 12 /** @suppress {duplicate} */ |
| 13 var remoting = remoting || {}; |
| 14 |
| 15 /** |
| 16 * @constructor |
| 17 */ |
| 18 remoting.Host = function() { |
| 19 /** @type {string} */ |
| 20 this.hostName = ''; |
| 21 /** @type {string} */ |
| 22 this.hostId = ''; |
| 23 /** @type {string} */ |
| 24 this.status = ''; |
| 25 /** @type {string} */ |
| 26 this.jabberId = ''; |
| 27 /** @type {string} */ |
| 28 this.publicKey = ''; |
| 29 } |
| 30 |
| 31 |
| 32 /** |
| 33 * @constructor |
| 34 * @param {Element} table The HTML <table> to contain host-list. |
| 35 * @param {Element} errorDiv The HTML <div> to display error messages. |
| 36 */ |
| 37 remoting.HostList = function(table, errorDiv) { |
| 38 this.table = table; |
| 39 this.errorDiv = errorDiv; |
| 40 /** @type {Array.<remoting.Host>} */ |
| 41 this.hosts = null; |
| 42 } |
| 43 |
| 44 /** |
| 45 * Refresh the host list with up-to-date details. |
| 46 * @param {Array.<remoting.Host>} hosts The new host list. |
| 47 * @return {void} Nothing. |
| 48 */ |
| 49 remoting.HostList.prototype.update = function(hosts) { |
| 50 this.table.innerHTML = ''; |
| 51 this.showError(null); |
| 52 this.hosts = hosts; |
| 53 |
| 54 for (var i = 0; i < hosts.length; ++i) { |
| 55 var host = hosts[i]; |
| 56 if (!host.hostName || !host.hostId || !host.status || !host.jabberId || |
| 57 !host.publicKey) |
| 58 continue; |
| 59 |
| 60 var hostEntry = document.createElement('tr'); |
| 61 addClass(hostEntry, 'host-list-row'); |
| 62 |
| 63 var hostIcon = document.createElement('td'); |
| 64 var hostIconImage = document.createElement('img'); |
| 65 hostIconImage.src = 'icon_host.png'; |
| 66 hostIcon.className = 'host-list-row-start'; |
| 67 hostIcon.appendChild(hostIconImage); |
| 68 hostEntry.appendChild(hostIcon); |
| 69 |
| 70 var hostName = document.createElement('td'); |
| 71 hostName.setAttribute('class', 'mode-select-label'); |
| 72 hostName.appendChild(document.createTextNode(host.hostName)); |
| 73 hostEntry.appendChild(hostName); |
| 74 |
| 75 var hostStatus = document.createElement('td'); |
| 76 if (host.status == 'ONLINE') { |
| 77 var connectButton = document.createElement('button'); |
| 78 connectButton.setAttribute('class', 'mode-select-button'); |
| 79 connectButton.setAttribute('type', 'button'); |
| 80 connectButton.setAttribute('onclick', |
| 81 'remoting.connectHost("'+host.hostId+'")'); |
| 82 connectButton.innerHTML = |
| 83 chrome.i18n.getMessage(/*i18n-content*/'CONNECT_BUTTON'); |
| 84 hostStatus.appendChild(connectButton); |
| 85 } else { |
| 86 addClass(hostEntry, 'host-offline'); |
| 87 hostStatus.innerHTML = chrome.i18n.getMessage(/*i18n-content*/'OFFLINE'); |
| 88 } |
| 89 hostStatus.className = 'host-list-row-end'; |
| 90 hostEntry.appendChild(hostStatus); |
| 91 |
| 92 this.table.appendChild(hostEntry); |
| 93 } |
| 94 |
| 95 this.showOrHide_(this.hosts.length != 0); |
| 96 } |
| 97 |
| 98 /** |
| 99 * Display a localized error message. |
| 100 * @param {remoting.Error?} errorTag The error to display, or NULL to clear any |
| 101 * previous error. |
| 102 * @return {void} Nothing. |
| 103 */ |
| 104 remoting.HostList.prototype.showError = function(errorTag) { |
| 105 this.table.innerHTML = ''; |
| 106 if (errorTag) { |
| 107 l10n.localizeElementFromTag(this.errorDiv, |
| 108 /** @type {string} */ (errorTag)); |
| 109 this.showOrHide_(true); |
| 110 } else { |
| 111 this.errorDiv.innerText = ''; |
| 112 } |
| 113 } |
| 114 |
| 115 /** |
| 116 * Show or hide the host-list UI. |
| 117 * @param {boolean} show True to show the UI, or false to hide it. |
| 118 * @return {void} Nothing. |
| 119 * @private |
| 120 */ |
| 121 remoting.HostList.prototype.showOrHide_ = function(show) { |
| 122 var parent = /** @type {Element} */ (this.table.parentNode); |
| 123 parent.hidden = !show; |
| 124 if (show) { |
| 125 parent.style.height = parent.scrollHeight + 'px'; |
| 126 removeClass(parent, remoting.HostList.COLLAPSED_); |
| 127 } else { |
| 128 addClass(parent, remoting.HostList.COLLAPSED_); |
| 129 } |
| 130 } |
| 131 |
| 132 /** |
| 133 * Class name for the host list when it is collapsed. |
| 134 * @private |
| 135 */ |
| 136 remoting.HostList.COLLAPSED_ = 'collapsed'; |
| 137 |
| 138 /** @type {remoting.HostList} */ |
| 139 remoting.hostList = null; |
OLD | NEW |