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 properties: { | 16 properties: { |
17 /** | 17 /** |
18 * True if the list is expanded. | 18 * True if the list is expanded. |
19 */ | 19 */ |
20 expanded: { | 20 expanded: { |
21 type: Boolean, | 21 type: Boolean, |
22 value: false, | 22 value: false, |
23 observer: 'expandedChanged_' | 23 observer: 'expandedChanged_', |
24 }, | 24 }, |
25 | 25 |
26 /** | 26 /** |
27 * The maximum height in pixels for the list of networks. | 27 * The maximum height in pixels for the list of networks. |
28 */ | 28 */ |
29 maxHeight: { | 29 maxHeight: { |
30 type: Number, | 30 type: Number, |
31 value: 200 | 31 value: 200, |
32 }, | 32 }, |
33 | 33 |
34 /** | 34 /** |
35 * True if this item should be hidden. We need this computed property so | |
36 * that it can default to true, hiding this element, since no changed event | |
37 * will be fired for deviceState if it is undefined (in NetworkSummary). | |
38 */ | |
39 isHidden: { | |
40 type: Boolean, | |
41 value: true, | |
42 computed: 'noDeviceState_(deviceState)' | |
43 }, | |
44 | |
45 /** | |
46 * Device state for the network type. | 35 * Device state for the network type. |
47 * @type {DeviceStateProperties|undefined} | 36 * @type {DeviceStateProperties|undefined} |
48 */ | 37 */ |
49 deviceState: { | 38 deviceState: { |
50 type: Object, | 39 type: Object, |
51 observer: 'deviceStateChanged_' | 40 observer: 'deviceStateChanged_', |
52 }, | 41 }, |
53 | 42 |
54 /** | 43 /** |
55 * Network state for the active network. | 44 * Network state for the active network. |
56 * @type {!CrOnc.NetworkStateProperties|undefined} | 45 * @type {!CrOnc.NetworkStateProperties|undefined} |
57 */ | 46 */ |
58 networkState: { | 47 activeNetworkState: { |
59 type: Object, | 48 type: Object, |
49 observer: 'activeNetworkStateChanged_', | |
60 }, | 50 }, |
61 | 51 |
62 /** | 52 /** |
63 * List of all network state data for the network type. | 53 * List of all network state data for the network type. |
64 * @type {!Array<!CrOnc.NetworkStateProperties>} | 54 * @type {!Array<!CrOnc.NetworkStateProperties>} |
65 */ | 55 */ |
66 networkStateList: { | 56 networkStateList: { |
67 type: Array, | 57 type: Array, |
68 value: function() { return []; }, | 58 value: function() { return []; }, |
69 observer: 'networkStateListChanged_' | 59 observer: 'networkStateListChanged_', |
70 } | 60 } |
71 }, | 61 }, |
72 | 62 |
73 /** | 63 /** @private */ |
74 * Polymer expanded changed method. | |
75 */ | |
76 expandedChanged_: function() { | 64 expandedChanged_: function() { |
77 var type = this.deviceState ? this.deviceState.Type : ''; | 65 var type = this.deviceState ? this.deviceState.Type : ''; |
78 this.fire('expanded', {expanded: this.expanded, type: type}); | 66 this.fire('expanded', {expanded: this.expanded, type: type}); |
79 }, | 67 }, |
80 | 68 |
81 /** | 69 /** @private */ |
82 * Polymer deviceState changed method. | |
83 */ | |
84 deviceStateChanged_: function() { | 70 deviceStateChanged_: function() { |
85 this.updateSelectable_(); | 71 this.updateSelectable_(); |
86 if (this.expanded && !this.deviceIsEnabled_(this.deviceState)) | 72 if (this.expanded && !this.deviceIsEnabled_(this.deviceState)) |
87 this.expanded = false; | 73 this.expanded = false; |
88 }, | 74 }, |
89 | 75 |
90 /** | 76 /** @private */ |
91 * Polymer networkStateList changed method. | 77 activeNetworkStateChanged_: function() { |
92 */ | 78 console.log('activeNetwork: ' + JSON.stringify(this.activeNetworkState)); |
michaelpg
2016/07/20 19:36:37
remove
stevenjb
2016/07/20 20:29:16
Doh. Done.
michaelpg
2016/07/20 23:52:37
(i'm assuming you do want to keep the new console.
| |
93 networkStateListChanged_: function() { | |
94 this.updateSelectable_(); | 79 this.updateSelectable_(); |
95 }, | 80 }, |
96 | 81 |
97 /** | 82 /** @private */ |
98 * @param {DeviceStateProperties} deviceState | 83 networkStateListChanged_: function() { this.updateSelectable_(); }, |
99 * @return {boolean} True if the device state is not set. | |
100 * @private | |
101 */ | |
102 noDeviceState_: function(deviceState) { | |
103 return !deviceState; | |
104 }, | |
105 | 84 |
106 /** | 85 /** |
107 * @param {DeviceStateProperties} deviceState | 86 * @param {DeviceStateProperties} deviceState |
108 * @param {boolean} expanded The expanded state. | 87 * @param {boolean} expanded The expanded state. |
109 * @return {boolean} Whether or not the scanning spinner should be shown. | 88 * @return {boolean} Whether or not the scanning spinner should be shown. |
110 * @private | 89 * @private |
111 */ | 90 */ |
112 showScanning_: function(deviceState, expanded) { | 91 showScanning_: function(deviceState, expanded) { |
113 return !!expanded && !!deviceState.Scanning; | 92 return !!expanded && !!deviceState.Scanning; |
114 }, | 93 }, |
115 | 94 |
116 /** | 95 /** |
117 * @param {DeviceStateProperties|undefined} deviceState | 96 * @param {DeviceStateProperties|undefined} deviceState |
118 * @return {boolean} Whether or not the device state is enabled. | 97 * @return {boolean} Whether or not the device state is enabled. |
119 * @private | 98 * @private |
120 */ | 99 */ |
121 deviceIsEnabled_: function(deviceState) { | 100 deviceIsEnabled_: function(deviceState) { |
122 return !!deviceState && deviceState.State == 'Enabled'; | 101 return !!deviceState && deviceState.State == 'Enabled'; |
123 }, | 102 }, |
124 | 103 |
125 /** | 104 /** |
126 * @param {DeviceStateProperties} deviceState | 105 * @param {DeviceStateProperties} deviceState |
127 * @return {string} The class value for the device enabled button. | 106 * @return {boolean} |
128 * @private | 107 * @private |
129 */ | 108 */ |
130 getDeviceEnabledButtonClass_: function(deviceState) { | 109 enableIsVisible_: function(deviceState) { |
131 var visible = deviceState && deviceState.Type != CrOnc.Type.ETHERNET && | 110 return !!deviceState && deviceState.Type != CrOnc.Type.ETHERNET && |
132 deviceState.Type != CrOnc.Type.VPN; | 111 deviceState.Type != CrOnc.Type.VPN; |
133 return visible ? '' : 'invisible'; | |
134 }, | |
135 | |
136 /** | |
137 * @param {DeviceStateProperties} deviceState | |
138 * @param {!Array<!CrOnc.NetworkStateProperties>} networkList | |
139 * @return {string} The class value for the expand button. | |
140 * @private | |
141 */ | |
142 getExpandButtonClass_: function(deviceState, networkList) { | |
143 var visible = this.expandIsVisible_(deviceState, networkList); | |
144 return visible ? '' : 'invisible'; | |
145 }, | 112 }, |
146 | 113 |
147 /** | 114 /** |
148 * @param {DeviceStateProperties|undefined} deviceState | 115 * @param {DeviceStateProperties|undefined} deviceState |
149 * @param {!Array<!CrOnc.NetworkStateProperties>} networkList | 116 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStateList |
150 * @return {boolean} Whether or not to show the UI to expand the list. | 117 * @return {boolean} Whether or not to show the UI to expand the list. |
151 * @private | 118 * @private |
152 */ | 119 */ |
153 expandIsVisible_: function(deviceState, networkList) { | 120 expandIsVisible_: function(deviceState, networkStateList) { |
154 if (!this.deviceIsEnabled_(deviceState)) | 121 if (!this.deviceIsEnabled_(deviceState)) |
155 return false; | 122 return false; |
156 var minLength = (this.deviceState.Type == CrOnc.Type.WI_FI) ? 1 : 2; | 123 var minLength = (this.deviceState.Type == CrOnc.Type.WI_FI) ? 1 : 2; |
157 return networkList.length >= minLength; | 124 return networkStateList.length >= minLength; |
158 }, | 125 }, |
159 | 126 |
160 /** | 127 /** |
161 * @param {!CrOnc.NetworkStateProperties} state | 128 * @param {!CrOnc.NetworkStateProperties} state |
162 * @param {boolean} expanded The expanded state. | 129 * @return {boolean} True if the known networks button should be shown. |
163 * @return {boolean} True if the 'Known networks' button should be shown. | |
164 * @private | 130 * @private |
165 */ | 131 */ |
166 showKnownNetworks_: function(state, expanded) { | 132 knownNetworksIsVisible_: function(state) { |
167 return !!expanded && !!state && state.Type == CrOnc.Type.WI_FI; | 133 return !!state && state.Type == CrOnc.Type.WI_FI; |
168 }, | 134 }, |
169 | 135 |
170 /** | 136 /** |
171 * Event triggered when the details div is tapped. | 137 * Event triggered when the details div is tapped. |
172 * @param {Event} event The enable button event. | 138 * @param {Event} event The enable button event. |
173 * @private | 139 * @private |
174 */ | 140 */ |
175 onDetailsTap_: function(event) { | 141 onDetailsTap_: function(event) { |
176 if ((event.target.id == 'expandListButton') || | 142 if ((event.target.id == 'expandListButton') || |
177 (this.deviceState && !this.deviceIsEnabled_(this.deviceState))) { | 143 (this.deviceState && !this.deviceIsEnabled_(this.deviceState))) { |
178 // Already handled or disabled, do nothing. | 144 // Already handled or disabled, do nothing. |
179 return; | 145 return; |
180 } | 146 } |
181 if (this.expandIsVisible_(this.deviceState, this.networkStateList)) { | 147 if (this.expandIsVisible_(this.deviceState, this.networkStateList)) { |
182 // Expandable, toggle expand. | 148 // Expandable, toggle expand. |
183 this.expanded = !this.expanded; | 149 this.expanded = !this.expanded; |
184 return; | 150 return; |
185 } | 151 } |
186 // Not expandable, fire 'selected' with |networkState|. | 152 // Not expandable, fire 'selected' with |activeNetworkState|. |
187 this.fire('selected', this.networkState); | 153 this.fire('selected', this.activeNetworkState); |
188 }, | 154 }, |
189 | 155 |
190 /** | 156 /** |
191 * Event triggered when the known networks button is tapped. | 157 * Event triggered when the known networks button is tapped. |
192 * @private | 158 * @private |
193 */ | 159 */ |
194 onKnownNetworksTap_: function() { | 160 onKnownNetworksTap_: function() { |
195 this.fire('show-known-networks', {type: CrOnc.Type.WI_FI}); | 161 this.fire('show-known-networks', {type: CrOnc.Type.WI_FI}); |
196 }, | 162 }, |
197 | 163 |
198 /** | 164 /** |
199 * Event triggered when the enable button is toggled. | 165 * Event triggered when the enable button is toggled. |
200 * @param {!Event} event | 166 * @param {!Event} event |
201 * @private | 167 * @private |
202 */ | 168 */ |
203 onDeviceEnabledTap_: function(event) { | 169 onDeviceEnabledTap_: function(event) { |
204 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); | 170 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); |
205 var type = this.deviceState ? this.deviceState.Type : ''; | 171 var type = this.deviceState ? this.deviceState.Type : ''; |
206 this.fire('device-enabled-toggled', | 172 this.fire( |
207 {enabled: !deviceIsEnabled, type: type}); | 173 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); |
208 // Make sure this does not propagate to onDetailsTap_. | 174 // Make sure this does not propagate to onDetailsTap_. |
209 event.stopPropagation(); | 175 event.stopPropagation(); |
210 }, | 176 }, |
211 | 177 |
212 /** | 178 /** |
213 * Called whenever the 'selectable' state might change. | 179 * Called whenever the 'selectable' state might change. |
214 * @private | 180 * @private |
215 */ | 181 */ |
216 updateSelectable_: function() { | 182 updateSelectable_: function() { |
217 var selectable = this.deviceIsEnabled_(this.deviceState); | 183 var selectable = this.deviceIsEnabled_(this.deviceState); |
218 this.$.details.classList.toggle('selectable', selectable); | 184 this.$.details.classList.toggle('selectable', selectable); |
219 }, | 185 }, |
220 }); | 186 }); |
OLD | NEW |