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

Side by Side 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: Address Jamie's feedback Created 5 years, 9 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
« no previous file with comments | « remoting/webapp/crd/js/host_table_entry.js ('k') | remoting/webapp/js_proto/qunit_proto.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 var remoting = remoting || {};
6
7 (function() {
8
9 'use strict';
10
11 /**
12 * @param {HTMLElement} rootElement
13 * @param {remoting.LocalHostSection.Controller} controller
14 *
15 * @constructor
16 * @implements {base.Disposable}
17 */
18 remoting.LocalHostSection = function(rootElement, controller) {
19 /** @private */
20 this.rootElement_ = rootElement;
21 /** @private */
22 this.controller_ = controller;
23 /** @private {remoting.Host} */
24 this.host_ = null;
25 /** @private {remoting.HostController.State} */
26 this.state_ = remoting.HostController.State.UNKNOWN;
27
28 var hostContainer = rootElement.querySelector('.host-entry');
29 /** @private */
30 this.hostTableEntry_ = new remoting.HostTableEntry(
31 parseInt(chrome.runtime.getManifest().version, 10),
32 remoting.connectMe2Me,
33 this.rename_.bind(this));
34 hostContainer.appendChild(this.hostTableEntry_.element());
35 this.hostTableEntry_.element().id = 'local-host-connect-button';
36
37 var startButton = rootElement.querySelector('.start-daemon');
38 var stopButton = rootElement.querySelector('.stop-daemon');
39 var changePINButton = rootElement.querySelector('.change-daemon-pin');
40
41 /** @private */
42 this.eventHooks_ = new base.Disposables(
43 new base.DomEventHook(startButton, 'click',
44 controller.start.bind(controller), false),
45 new base.DomEventHook(stopButton, 'click',
46 controller.stop.bind(controller), false),
47 new base.DomEventHook(changePINButton, 'click',
48 controller.changePIN.bind(controller), false));
49 /** @private */
50 this.hasError_ = false;
51 };
52
53 remoting.LocalHostSection.prototype.dispose = function() {
54 base.dispose(this.eventHooks_);
55 this.eventHooks_ = null;
56 };
57
58 /**
59 * @param {remoting.Host} host
60 * @param {remoting.HostController.State} state
61 * @param {boolean} hasError Whether the host list is in an error state.
62 */
63 remoting.LocalHostSection.prototype.setModel = function(host, state, hasError) {
64 this.host_ = host;
65 this.state_ = state;
66 this.hasError_ = hasError;
67 this.updateUI_();
68 };
69
70 /**
71 * @return {?string}
72 */
73 remoting.LocalHostSection.prototype.getHostId = function() {
74 return this.host_ ? this.host_.hostId : null;
75 };
76
77 /** @return {boolean} */
78 remoting.LocalHostSection.prototype.isEnabled_ = function() {
79 return (this.state_ == remoting.HostController.State.STARTING) ||
80 (this.state_ == remoting.HostController.State.STARTED);
81 };
82
83 /** @return {boolean} */
84 remoting.LocalHostSection.prototype.canChangeState = function() {
85 // The local host cannot be stopped or started if the host controller is not
86 // implemented for this platform.
87 var state = this.state_;
88 if (state === remoting.HostController.State.NOT_IMPLEMENTED ||
89 state === remoting.HostController.State.UNKNOWN) {
90 return false;
91 }
92
93 // Return false if the host is uninstallable. The NOT_INSTALLED check is
94 // required to handle the special case for Ubuntu, as we report the host as
95 // uninstallable on Linux.
96 if (!remoting.isMe2MeInstallable() &&
97 state === remoting.HostController.State.NOT_INSTALLED) {
98 return false;
99 }
100
101 // In addition, it cannot be started if there is an error (in many error
102 // states, the start operation will fail anyway, but even if it succeeds, the
103 // chance of a related but hard-to-diagnose future error is high).
104 return this.isEnabled_() || !this.hasError_;
105 };
106
107 /** @private */
108 remoting.LocalHostSection.prototype.updateUI_ = function() {
109 this.hostTableEntry_.setHost(this.host_);
110
111 // Disable elements.
112 var enabled = this.isEnabled_();
113 var canChangeLocalHostState = this.canChangeState();
114 remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state');
115 this.rootElement_.hidden = !canChangeLocalHostState;
116 };
117
118 remoting.LocalHostSection.prototype.rename_ = function() {
119 return this.controller_.rename(this.hostTableEntry_);
120 };
121
122 /**
123 * @constructor
124 * @param {remoting.HostList} hostList
125 * @param {remoting.HostSetupDialog} setupDialog
126 */
127 remoting.LocalHostSection.Controller = function(hostList, setupDialog) {
128 /** @private */
129 this.hostList_ = hostList;
130 this.setupDialog_ = setupDialog;
131 };
132
133 remoting.LocalHostSection.Controller.prototype.start = function() {
134 this.setupDialog_.showForStart();
135 };
136
137 remoting.LocalHostSection.Controller.prototype.stop = function() {
138 this.setupDialog_.showForStop();
139 };
140
141 remoting.LocalHostSection.Controller.prototype.changePIN = function() {
142 this.setupDialog_.showForPin();
143 };
144
145 /** @param {remoting.HostTableEntry} host */
146 remoting.LocalHostSection.Controller.prototype.rename = function(host) {
147 this.hostList_.renameHost(host);
148 };
149
150 }());
151
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/host_table_entry.js ('k') | remoting/webapp/js_proto/qunit_proto.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698