Chromium Code Reviews| Index: remoting/webapp/crd/js/host_list.js |
| diff --git a/remoting/webapp/crd/js/host_list.js b/remoting/webapp/crd/js/host_list.js |
| index 4221115d3e33e8c1cb040800b29e43b435eddef6..b1ad9da312cd9a3c2d8c9222705b3bfa83e6b4f1 100644 |
| --- a/remoting/webapp/crd/js/host_list.js |
| +++ b/remoting/webapp/crd/js/host_list.js |
| @@ -72,15 +72,12 @@ remoting.HostList = function(table, noHosts, errorMsg, errorButton, |
| */ |
| this.lastError_ = ''; |
| /** |
| - * @type {remoting.Host?} |
| + * @type {remoting.LocalHostSection} |
| * @private |
| */ |
| - this.localHost_ = null; |
| - /** |
| - * @type {remoting.HostController.State} |
| - * @private |
| - */ |
| - this.localHostState_ = remoting.HostController.State.UNKNOWN; |
| + this.localHostSection_ = new remoting.LocalHostSection( |
| + document.getElementById('daemon-control'), |
| + new remoting.LocalHostSection.Controller(this)); |
| /** |
| * @type {number} |
| @@ -258,40 +255,21 @@ remoting.HostList.prototype.display = function() { |
| // not the local host (which is displayed separately). NB: if the host has |
| // never sent a heartbeat, then there will be no jabberId. |
| if (host.hostName && host.hostId && host.status && host.publicKey && |
| - (!this.localHost_ || host.hostId != this.localHost_.hostId)) { |
| + (host.hostId != this.localHostSection_.getHostId())) { |
| var hostTableEntry = new remoting.HostTableEntry( |
| - host, this.webappMajorVersion_, |
| - this.renameHost_.bind(this), this.deleteHost_.bind(this)); |
| - hostTableEntry.createDom(); |
| + this.webappMajorVersion_, |
| + this.renameHost.bind(this), |
| + this.deleteHost_.bind(this)); |
| + hostTableEntry.setHost(host); |
| this.hostTableEntries_[i] = hostTableEntry; |
| - this.table_.appendChild(hostTableEntry.tableRow); |
| + this.table_.appendChild(hostTableEntry.element()); |
| } |
| } |
| } |
| this.errorMsg_.parentNode.hidden = (this.lastError_ == ''); |
| - |
| - // The local host cannot be stopped or started if the host controller is not |
| - // implemented for this platform. Additionally, it cannot be started if there |
| - // is an error (in many error states, the start operation will fail anyway, |
| - // but even if it succeeds, the chance of a related but hard-to-diagnose |
| - // future error is high). |
| - var state = this.localHostState_; |
| - var enabled = (state == remoting.HostController.State.STARTING) || |
| - (state == remoting.HostController.State.STARTED); |
| - var canChangeLocalHostState = |
| - (state != remoting.HostController.State.NOT_IMPLEMENTED) && |
| - (state != remoting.HostController.State.UNKNOWN) && |
| - (state != remoting.HostController.State.NOT_INSTALLED || |
| - remoting.isMe2MeInstallable()) && |
| - (enabled || this.lastError_ == ''); |
| - |
| - remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state'); |
| - var element = document.getElementById('daemon-control'); |
| - element.hidden = !canChangeLocalHostState; |
| - |
| if (noHostsRegistered) { |
| - this.showHostListEmptyMessage_(canChangeLocalHostState); |
| + this.showHostListEmptyMessage_(this.localHostSection_.canChangeState()); |
| } |
| }; |
| @@ -337,7 +315,7 @@ remoting.HostList.prototype.showHostListEmptyMessage_ = function( |
| * @private |
| */ |
| remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) { |
| - this.table_.removeChild(hostTableEntry.tableRow); |
| + this.table_.removeChild(hostTableEntry.element()); |
| var index = this.hostTableEntries_.indexOf(hostTableEntry); |
| if (index != -1) { |
| this.hostTableEntries_.splice(index, 1); |
| @@ -349,9 +327,8 @@ remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) { |
| * Prepare a host for renaming by replacing its name with an edit box. |
| * @param {remoting.HostTableEntry} hostTableEntry The host to be renamed. |
| * @return {void} Nothing. |
| - * @private |
| */ |
| -remoting.HostList.prototype.renameHost_ = function(hostTableEntry) { |
| +remoting.HostList.prototype.renameHost = function(hostTableEntry) { |
| for (var i = 0; i < this.hosts_.length; ++i) { |
| if (this.hosts_[i].hostId == hostTableEntry.host.hostId) { |
| this.hosts_[i].hostName = hostTableEntry.host.hostName; |
| @@ -377,24 +354,6 @@ remoting.HostList.unregisterHostById = function(hostId) { |
| }; |
| /** |
| - * Set tool-tips for the 'connect' action. We can't just set this on the |
| - * parent element because the button has no tool-tip, and therefore would |
| - * inherit connectStr. |
| - * |
| - * @return {void} Nothing. |
| - * @private |
| - */ |
| -remoting.HostList.prototype.setTooltips_ = function() { |
| - var connectStr = ''; |
| - if (this.localHost_) { |
| - chrome.i18n.getMessage(/*i18n-content*/'TOOLTIP_CONNECT', |
| - this.localHost_.hostName); |
| - } |
| - document.getElementById('this-host-name').title = connectStr; |
| - document.getElementById('this-host-icon').title = connectStr; |
| -}; |
| - |
| -/** |
| * Set the state of the local host and localHostId if any. |
| * |
| * @param {remoting.HostController.State} state State of the local host. |
| @@ -402,48 +361,12 @@ remoting.HostList.prototype.setTooltips_ = function() { |
| * @return {void} Nothing. |
| */ |
| remoting.HostList.prototype.setLocalHostStateAndId = function(state, hostId) { |
| - this.localHostState_ = state; |
| - this.setLocalHost_(hostId ? this.getHostForId(hostId) : null); |
| -} |
| - |
| -/** |
| - * Set the host object that corresponds to the local computer, if any. |
| - * |
| - * @param {remoting.Host?} host The host, or null if not registered. |
| - * @return {void} Nothing. |
| - * @private |
| - */ |
| -remoting.HostList.prototype.setLocalHost_ = function(host) { |
| - this.localHost_ = host; |
| - this.setTooltips_(); |
| - /** @type {remoting.HostList} */ |
| - var that = this; |
| - if (host) { |
| - /** @param {remoting.HostTableEntry} host */ |
| - var renameHost = function(host) { |
| - that.renameHost_(host); |
| - that.setTooltips_(); |
| - }; |
| - if (!this.localHostTableEntry_) { |
| - /** @type {remoting.HostTableEntry} @private */ |
| - this.localHostTableEntry_ = new remoting.HostTableEntry( |
| - host, this.webappMajorVersion_, renameHost); |
| - this.localHostTableEntry_.init( |
| - document.getElementById('this-host-connect'), |
| - document.getElementById('this-host-warning'), |
| - document.getElementById('this-host-name'), |
| - document.getElementById('this-host-rename')); |
| - } else { |
| - // TODO(jamiewalch): This is hack to prevent multiple click handlers being |
| - // registered for the same DOM elements if this method is called more than |
| - // once. A better solution would be to let HostTable create the daemon row |
| - // like it creates the rows for non-local hosts. |
| - this.localHostTableEntry_.host = host; |
| - } |
| - } else { |
| - this.localHostTableEntry_ = null; |
| + var host = hostId ? this.getHostForId(hostId) : null; |
| + if (this.lastError_ !== '') { |
| + state = remoting.HostController.State.UNKNOWN; |
|
Jamie
2015/02/23 22:28:11
This appears to be a change in behaviour. Is it in
kelvinp
2015/02/24 22:04:44
Done.
|
| } |
| -} |
| + this.localHostSection_.setModel(host, state); |
| +}; |
| /** |
| * Called by the HostControlled after the local host has been started. |
| @@ -471,7 +394,8 @@ remoting.HostList.prototype.onLocalHostStarted = function( |
| localHost.status = 'ONLINE'; |
| this.hosts_.push(localHost); |
| this.save_(); |
| - this.setLocalHost_(localHost); |
| + this.localHostSection_.setModel(localHost, |
| + remoting.HostController.State.STARTED); |
| }; |
| /** |