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

Unified Diff: remoting/webapp/crd/js/local_host_section.js

Issue 944183002: HostTableEntry refactor (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 side-by-side diff with in-line comments
Download patch
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..bbbc33c2c4d3da38160ce4117eadbf8f18150b09
--- /dev/null
+++ b/remoting/webapp/crd/js/local_host_section.js
@@ -0,0 +1,118 @@
+// 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
+ */
+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');
+ var webappVersion = parseInt(chrome.runtime.getManifest().version, 10);
Jamie 2015/02/23 22:28:11 I don't think you need to store this. Just query i
kelvinp 2015/02/24 22:04:45 Done.
Jamie 2015/02/27 18:19:40 I don't think you've changed this. To clarify my o
+ /** @private */
+ this.hostTableEntry_ =
+ new remoting.HostTableEntry(webappVersion, this.rename_.bind(this));
+ hostContainer.appendChild(this.hostTableEntry_.element());
+
+ 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(
Jamie 2015/02/23 22:28:11 Do you need a dispose() method to delete these?
kelvinp 2015/02/24 22:04:45 Done.
+ new base.DomEventHook(startButton, 'click', controller.start, false),
+ new base.DomEventHook(stopButton, 'click', controller.stop, false),
+ new base.DomEventHook(changePINButton, 'click', controller.changePIN, false)
+ );
+};
+
+/**
+ * @param {remoting.Host} host
+ * @param {remoting.HostController.State} state
+ */
+remoting.LocalHostSection.prototype.setModel = function(host, state) {
+ this.host_ = host;
+ this.state_ = state;
+ this.updateUI_();
+};
+
+/**
+ * @return {?string}
+ */
+remoting.LocalHostSection.prototype.getHostId = function() {
+ return this.host_ ? this.host_.hostId : null;
+};
+
+/** @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_;
+ return (state != remoting.HostController.State.NOT_IMPLEMENTED) &&
+ (state != remoting.HostController.State.UNKNOWN) &&
+ (state != remoting.HostController.State.NOT_INSTALLED ||
+ remoting.isMe2MeInstallable());
+};
+
+/** @private */
+remoting.LocalHostSection.prototype.updateUI_ = function() {
+ this.hostTableEntry_.setHost(this.host_);
+
+ // Disable elements.
+ var enabled = (this.state_ == remoting.HostController.State.STARTING) ||
+ (this.state_ == remoting.HostController.State.STARTED);
+ 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
+ */
+remoting.LocalHostSection.Controller = function(hostList) {
+ /** @private */
+ this.hostList_ = hostList;
+};
+
+remoting.LocalHostSection.Controller.prototype.start = function() {
+ remoting.hostSetupDialog.showForStart();
+};
+
+remoting.LocalHostSection.Controller.prototype.stop = function() {
+ remoting.hostSetupDialog.showForStop();
+};
+
+remoting.LocalHostSection.Controller.prototype.changePIN = function() {
+ remoting.hostSetupDialog.showForPin();
+};
+
+/** @param {remoting.HostTableEntry} host */
+remoting.LocalHostSection.Controller.prototype.rename = function(host) {
+ this.hostList_.renameHost(host);
+};
+
+}());
+

Powered by Google App Engine
This is Rietveld 408576698