Chromium Code Reviews| Index: remoting/webapp/crd/js/local_host_section.js |
| diff --git a/remoting/webapp/crd/js/local_host_section.js b/remoting/webapp/crd/js/local_host_section.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ed7185c4018f019c6e1d09bf804e0040b3a65732 |
| --- /dev/null |
| +++ b/remoting/webapp/crd/js/local_host_section.js |
| @@ -0,0 +1,145 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +var remoting = remoting || {}; |
| + |
| +(function() { |
| + |
| +'use strict'; |
| + |
| +/** |
| + * @param {HTMLElement} rootElement |
| + * @param {remoting.LocalHostSection.Controller} controller |
| + * |
| + * @constructor |
| + * @implements {base.Disposable} |
| + */ |
| +remoting.LocalHostSection = function(rootElement, controller) { |
| + /** @private */ |
| + this.rootElement_ = rootElement; |
| + /** @private */ |
| + this.controller_ = controller; |
| + /** @private {remoting.Host} */ |
| + this.host_ = null; |
| + /** @private {remoting.HostController.State} */ |
| + this.state_ = remoting.HostController.State.UNKNOWN; |
| + |
| + var hostContainer = rootElement.querySelector('.host-entry'); |
| + /** @private */ |
| + this.hostTableEntry_ = new remoting.HostTableEntry( |
| + parseInt(chrome.runtime.getManifest().version, 10), |
| + remoting.connectMe2Me, |
| + this.rename_.bind(this)); |
| + hostContainer.appendChild(this.hostTableEntry_.element()); |
| + this.hostTableEntry_.element().id = 'local-host-connect-button'; |
| + |
| + var startButton = rootElement.querySelector('.start-daemon'); |
| + var stopButton = rootElement.querySelector('.stop-daemon'); |
| + var changePINButton = rootElement.querySelector('.change-daemon-pin'); |
| + |
| + /** @private */ |
| + this.eventHooks_ = new base.Disposables( |
| + new base.DomEventHook(startButton, 'click', |
| + controller.start.bind(controller), false), |
| + new base.DomEventHook(stopButton, 'click', |
| + controller.stop.bind(controller), false), |
| + new base.DomEventHook(changePINButton, 'click', |
| + controller.changePIN.bind(controller), false)); |
| + /** @private */ |
| + this.hasError_ = false; |
| +}; |
| + |
| +remoting.LocalHostSection.prototype.dispose = function() { |
| + base.dispose(this.eventHooks_); |
| + this.eventHooks_ = null; |
| +}; |
| + |
| +/** |
| + * @param {remoting.Host} host |
| + * @param {remoting.HostController.State} state |
| + * @param {boolean} hasError Whether the host list is in an error state. |
| + */ |
| +remoting.LocalHostSection.prototype.setModel = function(host, state, hasError) { |
| + this.host_ = host; |
| + this.state_ = state; |
| + this.hasError_ = hasError; |
| + this.updateUI_(); |
| +}; |
| + |
| +/** |
| + * @return {?string} |
| + */ |
| +remoting.LocalHostSection.prototype.getHostId = function() { |
| + return this.host_ ? this.host_.hostId : null; |
| +}; |
| + |
| +/** @return {boolean} */ |
| +remoting.LocalHostSection.prototype.isEnabled_ = function() { |
| + return (this.state_ == remoting.HostController.State.STARTING) || |
| + (this.state_ == remoting.HostController.State.STARTED); |
| +}; |
| + |
| +/** @return {boolean} */ |
| +remoting.LocalHostSection.prototype.canChangeState = function() { |
| + // 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.state_; |
| + if (state === remoting.HostController.State.NOT_IMPLEMENTED || |
| + state === remoting.HostController.State.UNKNOWN || |
| + this.hasError_) { |
| + return false; |
| + } |
| + var isInstallable = (state != remoting.HostController.State.NOT_INSTALLED || |
| + remoting.isMe2MeInstallable()); |
|
Jamie
2015/03/04 00:09:25
Shouldn't this be isMe2MeInstallable() && state ==
kelvinp
2015/03/04 02:02:28
Done.
|
| + return (this.isEnabled_() || isInstallable); |
| +}; |
| + |
| +/** @private */ |
| +remoting.LocalHostSection.prototype.updateUI_ = function() { |
| + this.hostTableEntry_.setHost(this.host_); |
| + |
| + // Disable elements. |
| + var enabled = this.isEnabled_(); |
| + var canChangeLocalHostState = this.canChangeState(); |
| + remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state'); |
| + this.rootElement_.hidden = !canChangeLocalHostState; |
| +}; |
| + |
| +remoting.LocalHostSection.prototype.rename_ = function() { |
| + return this.controller_.rename(this.hostTableEntry_); |
| +}; |
| + |
| +/** |
| + * @constructor |
| + * @param {remoting.HostList} hostList |
| + * @param {remoting.HostSetupDialog} setupDialog |
| + */ |
| +remoting.LocalHostSection.Controller = function(hostList, setupDialog) { |
| + /** @private */ |
| + this.hostList_ = hostList; |
| + this.setupDialog_ = setupDialog; |
| +}; |
| + |
| +remoting.LocalHostSection.Controller.prototype.start = function() { |
| + this.setupDialog_.showForStart(); |
| +}; |
| + |
| +remoting.LocalHostSection.Controller.prototype.stop = function() { |
| + this.setupDialog_.showForStop(); |
| +}; |
| + |
| +remoting.LocalHostSection.Controller.prototype.changePIN = function() { |
| + this.setupDialog_.showForPin(); |
| +}; |
| + |
| +/** @param {remoting.HostTableEntry} host */ |
| +remoting.LocalHostSection.Controller.prototype.rename = function(host) { |
| + this.hostList_.renameHost(host); |
| +}; |
| + |
| +}()); |
| + |