OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Polymer element for displaying the network state for a specific | 6 * @fileoverview Polymer element for displaying the network state for a specific |
7 * type and a list of networks for that type. | 7 * type and a list of networks for that type. |
8 */ | 8 */ |
9 | 9 |
10 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */ | 10 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */ |
11 var DeviceStateProperties; | 11 var DeviceStateProperties; |
12 | 12 |
13 Polymer({ | 13 Polymer({ |
14 is: 'network-summary-item', | 14 is: 'network-summary-item', |
15 | 15 |
16 behaviors: [Polymer.IronA11yKeysBehavior], | |
17 | |
16 properties: { | 18 properties: { |
17 /** | 19 /** |
18 * Device state for the network type. | 20 * Device state for the network type. |
19 * @type {DeviceStateProperties|undefined} | 21 * @type {DeviceStateProperties|undefined} |
20 */ | 22 */ |
21 deviceState: { | 23 deviceState: { |
22 type: Object, | 24 type: Object, |
23 observer: 'deviceStateChanged_', | 25 observer: 'deviceStateChanged_', |
24 }, | 26 }, |
25 | 27 |
26 /** | 28 /** |
27 * Network state for the active network. | 29 * Network state for the active network. |
28 * @type {!CrOnc.NetworkStateProperties|undefined} | 30 * @type {!CrOnc.NetworkStateProperties|undefined} |
29 */ | 31 */ |
30 activeNetworkState: { | 32 activeNetworkState: Object, |
31 type: Object, | |
32 observer: 'activeNetworkStateChanged_', | |
33 }, | |
34 | 33 |
35 /** | 34 /** |
36 * List of all network state data for the network type. | 35 * List of all network state data for the network type. |
37 * @type {!Array<!CrOnc.NetworkStateProperties>} | 36 * @type {!Array<!CrOnc.NetworkStateProperties>} |
38 */ | 37 */ |
39 networkStateList: { | 38 networkStateList: { |
40 type: Array, | 39 type: Array, |
41 value: function() { | 40 value: function() { |
42 return []; | 41 return []; |
43 }, | 42 }, |
44 observer: 'networkStateListChanged_', | |
45 }, | 43 }, |
46 | 44 |
47 /** The maximum height in pixels for the list of networks. */ | 45 /** The maximum height in pixels for the list of networks. */ |
48 maxHeight: { | 46 maxHeight: { |
49 type: Number, | 47 type: Number, |
50 value: 200, | 48 value: 200, |
51 }, | 49 }, |
52 | 50 |
53 /** | 51 /** |
52 * Interface for networkingPrivate calls, passed from internet_page. | |
53 * @type {NetworkingPrivate} | |
michaelpg
2016/09/15 02:24:28
!NetworkingPrivate perhaps?
stevenjb
2016/09/15 17:42:17
Done. (I thought this would need to become !Networ
michaelpg
2016/09/15 21:35:16
Polymer properties are a weird case. It's possible
| |
54 */ | |
55 networkingPrivate: Object, | |
56 | |
57 /** | |
54 * The expanded state of the list of networks. | 58 * The expanded state of the list of networks. |
55 * @private | 59 * @private |
56 */ | 60 */ |
57 expanded_: { | 61 expanded_: { |
58 type: Boolean, | 62 type: Boolean, |
59 value: false, | 63 value: false, |
60 observer: 'expandedChanged_', | 64 observer: 'expandedChanged_', |
61 }, | 65 }, |
62 | 66 |
63 /** | 67 /** |
64 * Whether the list has been expanded. This is used to ensure the | 68 * Whether the list has been expanded. This is used to ensure the |
65 * iron-collapse section animates correctly. | 69 * iron-collapse section animates correctly. |
66 * @private | 70 * @private |
67 */ | 71 */ |
68 wasExpanded_: { | 72 wasExpanded_: { |
69 type: Boolean, | 73 type: Boolean, |
70 value: false, | 74 value: false, |
71 }, | 75 }, |
72 }, | 76 }, |
73 | 77 |
78 keyBindings: { | |
79 'enter': 'onDetailsTap_', | |
80 }, | |
81 | |
74 /** @private */ | 82 /** @private */ |
75 expandedChanged_: function() { | 83 expandedChanged_: function() { |
76 var type = this.deviceState ? this.deviceState.Type : ''; | 84 var type = this.deviceState ? this.deviceState.Type : ''; |
77 this.fire('expanded', {expanded: this.expanded_, type: type}); | 85 this.fire('expanded', {expanded: this.expanded_, type: type}); |
78 }, | 86 }, |
79 | 87 |
80 /** @private */ | 88 /** @private */ |
81 deviceStateChanged_: function() { | 89 deviceStateChanged_: function() { |
82 this.updateSelectable_(); | |
83 if (this.expanded_ && !this.deviceIsEnabled_()) | 90 if (this.expanded_ && !this.deviceIsEnabled_()) |
84 this.expanded_ = false; | 91 this.expanded_ = false; |
85 }, | 92 }, |
86 | 93 |
87 /** @private */ | 94 /** |
88 activeNetworkStateChanged_: function() { | 95 * @return {boolean} Whether or not the scanning spinner should be visible. |
89 this.updateSelectable_(); | 96 * @private |
90 }, | 97 */ |
91 | 98 scanningIsVisible_: function() { |
92 /** @private */ | 99 return this.deviceState.Type == CrOnc.Type.WI_FI; |
93 networkStateListChanged_: function() { | |
94 this.updateSelectable_(); | |
95 }, | 100 }, |
96 | 101 |
97 /** | 102 /** |
98 * @return {boolean} Whether or not the scanning spinner should be shown. | 103 * @return {boolean} Whether or not the scanning spinner should be active. |
99 * @private | 104 * @private |
100 */ | 105 */ |
101 showScanning_: function() { | 106 scanningIsActive_: function() { |
102 return !!this.expanded_ && !!this.deviceState.Scanning; | 107 return !!this.expanded_ && !!this.deviceState.Scanning; |
103 }, | 108 }, |
104 | 109 |
105 /** | 110 /** |
111 * Show the <network-siminfo> element if this is a disabled and locked | |
112 * cellular device. | |
113 * @return {boolean} | |
114 * @private | |
115 */ | |
116 showSimInfo_: function() { | |
117 let device = this.deviceState; | |
118 if (device.Type != CrOnc.Type.CELLULAR || this.deviceIsEnabled_()) | |
119 return false; | |
120 return device.SimPresent === false || | |
121 device.SimLockType == CrOnc.LockType.PIN || | |
122 device.SimLockType == CrOnc.LockType.PUK; | |
123 }, | |
124 | |
125 /** | |
126 * Returns a NetworkProperties object for <network-siminfo> built from | |
127 * the device properties (since there will be no active network). | |
128 * @return {!CrOnc.NetworkProperties} | |
129 * @private | |
130 */ | |
131 getCellularState_: function() { | |
132 let device = this.deviceState; | |
133 return { | |
134 GUID: '', | |
135 Type: CrOnc.Type.CELLULAR, | |
136 Cellular: { | |
137 SIMLockStatus: { | |
138 LockType: device.SimLockType || '', | |
139 LockEnabled: device.SimLockType != CrOnc.LockType.NONE | |
michaelpg
2016/09/15 02:24:28
nit: trailing comma for consistency
stevenjb
2016/09/15 17:42:17
Done.
| |
140 }, | |
141 SIMPresent: device.SimPresent, | |
142 }, | |
143 }; | |
144 }, | |
145 | |
146 /** | |
106 * @return {boolean} Whether or not the device state is enabled. | 147 * @return {boolean} Whether or not the device state is enabled. |
107 * @private | 148 * @private |
108 */ | 149 */ |
109 deviceIsEnabled_: function() { | 150 deviceIsEnabled_: function() { |
110 return !!this.deviceState && | 151 return !!this.deviceState && |
111 this.deviceState.State == | 152 this.deviceState.State == |
112 chrome.networkingPrivate.DeviceStateType.ENABLED; | 153 chrome.networkingPrivate.DeviceStateType.ENABLED; |
113 }, | 154 }, |
114 | 155 |
115 /** | 156 /** |
(...skipping 21 matching lines...) Expand all Loading... | |
137 */ | 178 */ |
138 networksIronCollapseIsOpened_() { | 179 networksIronCollapseIsOpened_() { |
139 return this.expanded_ && this.wasExpanded_; | 180 return this.expanded_ && this.wasExpanded_; |
140 }, | 181 }, |
141 | 182 |
142 /** | 183 /** |
143 * @return {boolean} | 184 * @return {boolean} |
144 * @private | 185 * @private |
145 */ | 186 */ |
146 enableIsVisible_: function() { | 187 enableIsVisible_: function() { |
147 return !!this.deviceState && this.deviceState.Type != CrOnc.Type.ETHERNET && | 188 return this.deviceState.Type != CrOnc.Type.ETHERNET && |
148 this.deviceState.Type != CrOnc.Type.VPN; | 189 this.deviceState.Type != CrOnc.Type.VPN; |
149 }, | 190 }, |
150 | 191 |
151 /** | 192 /** |
193 * @return {boolean} | |
194 * @private | |
195 */ | |
196 showDetailsIsVisible_: function() { | |
197 return this.deviceState.Type == CrOnc.Type.CELLULAR && | |
198 this.networkStateList.length == 1; | |
199 }, | |
200 | |
201 /** | |
152 * @return {boolean} Whether or not to show the UI to expand the list. | 202 * @return {boolean} Whether or not to show the UI to expand the list. |
153 * @private | 203 * @private |
154 */ | 204 */ |
155 expandIsVisible_: function() { | 205 expandIsVisible_: function() { |
156 if (!this.deviceIsEnabled_()) | 206 if (!this.deviceIsEnabled_()) |
157 return false; | 207 return false; |
158 var minLength = (this.deviceState.Type == CrOnc.Type.WI_FI) ? 1 : 2; | 208 let type = this.deviceState.Type; |
209 var minLength = | |
210 (type == CrOnc.Type.WI_FI || type == CrOnc.Type.VPN) ? 1 : 2; | |
159 return this.networkStateList.length >= minLength; | 211 return this.networkStateList.length >= minLength; |
160 }, | 212 }, |
161 | 213 |
162 /** | 214 /** |
163 * @return {boolean} True if the known networks button should be shown. | 215 * @return {boolean} True if the known networks button should be shown. |
164 * @private | 216 * @private |
165 */ | 217 */ |
166 knownNetworksIsVisible_: function() { | 218 knownNetworksIsVisible_: function() { |
167 return !!this.activeNetworkState && | 219 return !!this.activeNetworkState && |
168 this.activeNetworkState.Type == CrOnc.Type.WI_FI; | 220 this.activeNetworkState.Type == CrOnc.Type.WI_FI; |
169 }, | 221 }, |
170 | 222 |
171 /** | 223 /** |
172 * Event triggered when the details div is tapped. | 224 * Event triggered when the details div is tapped or Enter is pressed. |
173 * @param {Event} event The enable button event. | 225 * @param {!Event} event The enable button event. |
174 * @private | 226 * @private |
175 */ | 227 */ |
176 onDetailsTap_: function(event) { | 228 onDetailsTap_: function(event) { |
177 if ((event.target.id == 'expandListButton') || | 229 if ((event.target && event.target.id == 'expandListButton') || |
178 (this.deviceState && !this.deviceIsEnabled_())) { | 230 (this.deviceState && !this.deviceIsEnabled_())) { |
179 // Already handled or disabled, do nothing. | 231 // Already handled or disabled, do nothing. |
180 return; | 232 return; |
181 } | 233 } |
182 if (this.expandIsVisible_()) { | 234 if (this.expandIsVisible_()) { |
183 // Expandable, toggle expand. | 235 // Expandable, toggle expand. |
184 this.expanded_ = !this.expanded_; | 236 this.expanded_ = !this.expanded_; |
185 return; | 237 return; |
186 } | 238 } |
187 // Not expandable, fire 'selected' with |activeNetworkState|. | 239 // Not expandable, fire 'selected' with |activeNetworkState|. |
188 this.fire('selected', this.activeNetworkState); | 240 this.fire('selected', this.activeNetworkState); |
189 }, | 241 }, |
190 | 242 |
191 /** | 243 /** |
244 * @param {!Event} event The enable button event. | |
245 * @private | |
246 */ | |
247 onShowDetailsTap_: function(event) { | |
248 if (!this.activeNetworkState.GUID) | |
249 return; | |
250 this.fire('show-detail', this.activeNetworkState); | |
251 event.stopPropagation(); | |
252 }, | |
253 | |
254 /** | |
192 * Event triggered when the known networks button is tapped. | 255 * Event triggered when the known networks button is tapped. |
193 * @private | 256 * @private |
194 */ | 257 */ |
195 onKnownNetworksTap_: function() { | 258 onKnownNetworksTap_: function() { |
196 this.fire('show-known-networks', {type: CrOnc.Type.WI_FI}); | 259 this.fire('show-known-networks', {type: CrOnc.Type.WI_FI}); |
197 }, | 260 }, |
198 | 261 |
199 /** | 262 /** |
200 * Event triggered when the enable button is toggled. | 263 * Event triggered when the enable button is toggled. |
201 * @param {!Event} event | 264 * @param {!Event} event |
202 * @private | 265 * @private |
203 */ | 266 */ |
204 onDeviceEnabledTap_: function(event) { | 267 onDeviceEnabledTap_: function(event) { |
205 var deviceIsEnabled = this.deviceIsEnabled_(); | 268 var deviceIsEnabled = this.deviceIsEnabled_(); |
206 var type = this.deviceState ? this.deviceState.Type : ''; | 269 var type = this.deviceState ? this.deviceState.Type : ''; |
207 this.fire( | 270 this.fire( |
208 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); | 271 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); |
209 // Make sure this does not propagate to onDetailsTap_. | 272 // Make sure this does not propagate to onDetailsTap_. |
210 event.stopPropagation(); | 273 event.stopPropagation(); |
211 }, | 274 }, |
212 | 275 |
213 /** | 276 /** |
214 * Called whenever the 'selectable' state might change. | 277 * @return {string} |
215 * @private | 278 * @private |
216 */ | 279 */ |
217 updateSelectable_: function() { | 280 getTabIndex_: function() { |
218 var selectable = this.deviceIsEnabled_(); | 281 return this.deviceIsEnabled_() ? '0' : '-1'; |
219 this.$.details.classList.toggle('selectable', selectable); | |
220 }, | 282 }, |
221 }); | 283 }); |
OLD | NEW |