OLD | NEW |
---|---|
(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 * @constructor | |
15 */ | |
16 remoting.LocalHostSection = function(rootElement, controller) { | |
17 /** @private */ | |
18 this.rootElement_ = rootElement; | |
19 /** @private */ | |
20 this.controller_ = controller; | |
21 /** @private {remoting.Host} */ | |
22 this.host_ = null; | |
23 /** @private {remoting.HostController.State} */ | |
24 this.state_ = remoting.HostController.State.UNKNOWN; | |
25 | |
26 var hostContainer = rootElement.querySelector('.host-entry'); | |
27 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
| |
28 /** @private */ | |
29 this.hostTableEntry_ = | |
30 new remoting.HostTableEntry(webappVersion, this.rename_.bind(this)); | |
31 hostContainer.appendChild(this.hostTableEntry_.element()); | |
32 | |
33 var startButton = rootElement.querySelector('#start-daemon'); | |
34 var stopButton = rootElement.querySelector('#stop-daemon'); | |
35 var changePINButton = rootElement.querySelector('#change-daemon-pin'); | |
36 /** @private */ | |
37 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.
| |
38 new base.DomEventHook(startButton, 'click', controller.start, false), | |
39 new base.DomEventHook(stopButton, 'click', controller.stop, false), | |
40 new base.DomEventHook(changePINButton, 'click', controller.changePIN, false) | |
41 ); | |
42 }; | |
43 | |
44 /** | |
45 * @param {remoting.Host} host | |
46 * @param {remoting.HostController.State} state | |
47 */ | |
48 remoting.LocalHostSection.prototype.setModel = function(host, state) { | |
49 this.host_ = host; | |
50 this.state_ = state; | |
51 this.updateUI_(); | |
52 }; | |
53 | |
54 /** | |
55 * @return {?string} | |
56 */ | |
57 remoting.LocalHostSection.prototype.getHostId = function() { | |
58 return this.host_ ? this.host_.hostId : null; | |
59 }; | |
60 | |
61 /** @return {boolean} */ | |
62 remoting.LocalHostSection.prototype.canChangeState = function() { | |
63 // The local host cannot be stopped or started if the host controller is not | |
64 // implemented for this platform. Additionally, it cannot be started if there | |
65 // is an error (in many error states, the start operation will fail anyway, | |
66 // but even if it succeeds, the chance of a related but hard-to-diagnose | |
67 // future error is high). | |
68 var state = this.state_; | |
69 return (state != remoting.HostController.State.NOT_IMPLEMENTED) && | |
70 (state != remoting.HostController.State.UNKNOWN) && | |
71 (state != remoting.HostController.State.NOT_INSTALLED || | |
72 remoting.isMe2MeInstallable()); | |
73 }; | |
74 | |
75 /** @private */ | |
76 remoting.LocalHostSection.prototype.updateUI_ = function() { | |
77 this.hostTableEntry_.setHost(this.host_); | |
78 | |
79 // Disable elements. | |
80 var enabled = (this.state_ == remoting.HostController.State.STARTING) || | |
81 (this.state_ == remoting.HostController.State.STARTED); | |
82 var canChangeLocalHostState = this.canChangeState(); | |
83 remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state'); | |
84 this.rootElement_.hidden = !canChangeLocalHostState; | |
85 }; | |
86 | |
87 remoting.LocalHostSection.prototype.rename_ = function() { | |
88 return this.controller_.rename(this.hostTableEntry_); | |
89 }; | |
90 | |
91 /** | |
92 * @constructor | |
93 * @param {remoting.HostList} hostList | |
94 */ | |
95 remoting.LocalHostSection.Controller = function(hostList) { | |
96 /** @private */ | |
97 this.hostList_ = hostList; | |
98 }; | |
99 | |
100 remoting.LocalHostSection.Controller.prototype.start = function() { | |
101 remoting.hostSetupDialog.showForStart(); | |
102 }; | |
103 | |
104 remoting.LocalHostSection.Controller.prototype.stop = function() { | |
105 remoting.hostSetupDialog.showForStop(); | |
106 }; | |
107 | |
108 remoting.LocalHostSection.Controller.prototype.changePIN = function() { | |
109 remoting.hostSetupDialog.showForPin(); | |
110 }; | |
111 | |
112 /** @param {remoting.HostTableEntry} host */ | |
113 remoting.LocalHostSection.Controller.prototype.rename = function(host) { | |
114 this.hostList_.renameHost(host); | |
115 }; | |
116 | |
117 }()); | |
118 | |
OLD | NEW |