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

Side by Side Diff: chrome/browser/resources/settings/internet_page/network_summary_item.js

Issue 2720503006: MD Settings: Internet: Move network lists to a subpage (Closed)
Patch Set: Rebase Created 3 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
OLDNEW
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, I18nBehavior], 16 behaviors: [Polymer.IronA11yKeysBehavior, I18nBehavior],
17 17
18 properties: { 18 properties: {
19 /** 19 /**
20 * Device state for the network type. 20 * Device state for the network type.
21 * @type {!DeviceStateProperties|undefined} 21 * @type {!DeviceStateProperties|undefined}
22 */ 22 */
23 deviceState: { 23 deviceState: Object,
24 type: Object,
25 observer: 'deviceStateChanged_',
26 },
27 24
28 /** 25 /**
29 * Network state for the active network. 26 * Network state for the active network.
30 * @type {!CrOnc.NetworkStateProperties|undefined} 27 * @type {!CrOnc.NetworkStateProperties|undefined}
31 */ 28 */
32 activeNetworkState: Object, 29 activeNetworkState: Object,
33 30
34 /** 31 /**
35 * List of all network state data for the network type. 32 * List of all network state data for the network type.
36 * @type {!Array<!CrOnc.NetworkStateProperties>} 33 * @type {!Array<!CrOnc.NetworkStateProperties>}
37 */ 34 */
38 networkStateList: { 35 networkStateList: {
39 type: Array, 36 type: Array,
40 value: function() { 37 value: function() {
41 return []; 38 return [];
42 }, 39 },
43 }, 40 },
44 41
45 /** 42 /**
46 * Type of networks in networkStateList. Used to initialte scanning.
47 * @type {CrOnc.Type}
48 */
49 networkType: String,
50
51 /**
52 * Interface for networkingPrivate calls, passed from internet_page. 43 * Interface for networkingPrivate calls, passed from internet_page.
53 * @type {!NetworkingPrivate} 44 * @type {!NetworkingPrivate}
54 */ 45 */
55 networkingPrivate: Object, 46 networkingPrivate: Object,
56
57 /**
58 * The expanded state of the list of networks.
59 * @private
60 */
61 expanded_: {
62 type: Boolean,
63 value: false,
64 observer: 'expandedChanged_',
65 },
66
67 /**
68 * Whether the list has been expanded. This is used to ensure the
69 * iron-collapse section animates correctly.
70 * @private
71 */
72 wasExpanded_: {
73 type: Boolean,
74 value: false,
75 },
76 },
77
78 observers: ['updateScanning_(networkingPrivate, networkType, expanded_)'],
79
80 /** @private {number|null} */
81 scanIntervalId_: null,
82
83 /** override */
84 detached: function() {
85 if (this.scanIntervalId_ !== null) {
86 window.clearInterval(this.scanIntervalId_);
87 this.scanIntervalId_ = null;
88 }
89 },
90
91 /** @private */
92 expandedChanged_: function() {
93 var type = this.deviceState ? this.deviceState.Type : '';
94 this.fire('expanded', {expanded: this.expanded_, type: type});
95 },
96
97 /** @private */
98 deviceStateChanged_: function() {
99 if (this.expanded_ && !this.deviceIsEnabled_(this.deviceState))
100 this.expanded_ = false;
101 },
102
103 /** @private */
104 updateScanning_: function() {
105 if (this.scanIntervalId_ != null) {
106 if (!this.expanded_) {
107 window.clearInterval(this.scanIntervalId_);
108 this.scanIntervalId_ = null;
109 }
110 return;
111 }
112 if (!this.expanded_ ||
113 (this.networkType != CrOnc.Type.ALL &&
114 this.networkType != CrOnc.Type.WI_FI)) {
115 return;
116 }
117 /** @const */ var INTERVAL_MS = 10 * 1000;
118 this.networkingPrivate.requestNetworkScan();
119 this.scanIntervalId_ = window.setInterval(function() {
120 this.networkingPrivate.requestNetworkScan();
121 }.bind(this), INTERVAL_MS);
122 }, 47 },
123 48
124 /** 49 /**
125 * @return {boolean} Whether or not the scanning spinner should be visible.
126 * @private
127 */
128 scanningIsVisible_: function() {
129 return this.deviceState.Type == CrOnc.Type.WI_FI;
130 },
131
132 /**
133 * @return {boolean} Whether or not the scanning spinner should be active.
134 * @private
135 */
136 scanningIsActive_: function() {
137 return !!this.expanded_ && !!this.deviceState.Scanning;
138 },
139
140 /**
141 * Show the <network-siminfo> element if this is a disabled and locked 50 * Show the <network-siminfo> element if this is a disabled and locked
142 * cellular device. 51 * cellular device.
143 * @return {boolean} 52 * @return {boolean}
144 * @private 53 * @private
145 */ 54 */
146 showSimInfo_: function() { 55 showSimInfo_: function() {
147 var device = this.deviceState; 56 var device = this.deviceState;
148 if (device.Type != CrOnc.Type.CELLULAR || 57 if (device.Type != CrOnc.Type.CELLULAR ||
149 this.deviceIsEnabled_(this.deviceState)) { 58 this.deviceIsEnabled_(this.deviceState)) {
150 return false; 59 return false;
(...skipping 28 matching lines...) Expand all
179 * @param {!DeviceStateProperties|undefined} deviceState 88 * @param {!DeviceStateProperties|undefined} deviceState
180 * @return {boolean} Whether or not the device state is enabled. 89 * @return {boolean} Whether or not the device state is enabled.
181 * @private 90 * @private
182 */ 91 */
183 deviceIsEnabled_: function(deviceState) { 92 deviceIsEnabled_: function(deviceState) {
184 return !!deviceState && 93 return !!deviceState &&
185 deviceState.State == chrome.networkingPrivate.DeviceStateType.ENABLED; 94 deviceState.State == chrome.networkingPrivate.DeviceStateType.ENABLED;
186 }, 95 },
187 96
188 /** 97 /**
189 * @return {boolean} Whether the dom-if for the network list should be true.
190 * The logic here is designed to allow the enclosed content to be stamped
191 * before it is expanded.
192 * @private
193 */
194 networksDomIfIsTrue_: function() {
195 if (this.expanded_ == this.wasExpanded_)
196 return this.expanded_;
197 if (this.expanded_) {
198 Polymer.RenderStatus.afterNextRender(this, function() {
199 this.wasExpanded_ = true;
200 }.bind(this));
201 return true;
202 }
203 return this.wasExpanded_;
204 },
205
206 /**
207 * @param {boolean} expanded
208 * @param {boolean} wasExpanded
209 * @return {boolean} Whether the iron-collapse for the network list should
210 * be opened.
211 * @private
212 */
213 networksIronCollapseIsOpened_: function(expanded, wasExpanded) {
214 return expanded && wasExpanded;
215 },
216
217 /**
218 * @param {!DeviceStateProperties} deviceState 98 * @param {!DeviceStateProperties} deviceState
219 * @return {boolean} 99 * @return {boolean}
220 * @private 100 * @private
221 */ 101 */
222 enableToggleIsVisible_: function(deviceState) { 102 enableToggleIsVisible_: function(deviceState) {
223 return deviceState.Type != CrOnc.Type.ETHERNET && 103 return deviceState.Type != CrOnc.Type.ETHERNET &&
224 deviceState.Type != CrOnc.Type.VPN; 104 deviceState.Type != CrOnc.Type.VPN;
225 }, 105 },
226 106
227 /** 107 /**
(...skipping 20 matching lines...) Expand all
248 case CrOnc.Type.WI_FI: 128 case CrOnc.Type.WI_FI:
249 return this.i18n('internetToggleWiFiA11yLabel'); 129 return this.i18n('internetToggleWiFiA11yLabel');
250 case CrOnc.Type.WI_MAX: 130 case CrOnc.Type.WI_MAX:
251 return this.i18n('internetToggleWiMAXA11yLabel'); 131 return this.i18n('internetToggleWiMAXA11yLabel');
252 } 132 }
253 assertNotReached(); 133 assertNotReached();
254 return ''; 134 return '';
255 }, 135 },
256 136
257 /** 137 /**
258 * @return {boolean} Whether or not to show the UI to expand the list. 138 * @return {boolean}
259 * @private
260 */
261 expandIsVisible_: function() {
262 if (!this.deviceIsEnabled_(this.deviceState))
263 return false;
264 var type = this.deviceState.Type;
265 var minLength =
266 (type == CrOnc.Type.WI_FI || type == CrOnc.Type.VPN) ? 1 : 2;
267 return this.networkStateList.length >= minLength;
268 },
269
270 /**
271 * @return {boolean} Whether or not to show the UI to show details.
272 * @private 139 * @private
273 */ 140 */
274 showDetailsIsVisible_: function() { 141 showDetailsIsVisible_: function() {
275 if (this.expandIsVisible_())
276 return false;
277 return this.deviceIsEnabled_(this.deviceState); 142 return this.deviceIsEnabled_(this.deviceState);
278 }, 143 },
279 144
280 /** 145 /**
281 * @param {!CrOnc.NetworkStateProperties} activeNetworkState 146 * @return {boolean}
282 * @return {boolean} True if the known networks button should be shown.
283 * @private 147 * @private
284 */ 148 */
285 knownNetworksIsVisible_: function(activeNetworkState) { 149 shouldShowList_: function() {
286 return !!activeNetworkState && activeNetworkState.Type == CrOnc.Type.WI_FI; 150 var minlen = (this.deviceState.Type == CrOnc.Type.WI_FI ||
151 this.deviceState.Type == CrOnc.Type.VPN) ?
152 1 :
153 2;
154 return this.networkStateList.length >= minlen;
287 }, 155 },
288 156
289 /** 157 /**
290 * Event triggered when the details div is tapped or Enter is pressed.
291 * @param {!Event} event The enable button event.
292 * @private
293 */
294 onDetailsTap_: function(event) {
295 if ((event.target && event.target.id == 'expandListButton') ||
296 (this.deviceState && !this.deviceIsEnabled_(this.deviceState))) {
297 // Already handled or disabled, do nothing.
298 return;
299 }
300 if (this.expandIsVisible_()) {
301 // Expandable, toggle expand.
302 this.expanded_ = !this.expanded_;
303 return;
304 }
305 // Not expandable, fire 'selected' with |activeNetworkState|.
306 this.fire('selected', this.activeNetworkState);
307 },
308
309 /**
310 * @param {!Event} event The enable button event. 158 * @param {!Event} event The enable button event.
311 * @private 159 * @private
312 */ 160 */
313 onShowDetailsTap_: function(event) { 161 onShowDetailsTap_: function(event) {
314 if (!this.activeNetworkState.GUID) 162 if (this.shouldShowList_())
315 return; 163 this.fire('show-networks', this.deviceState);
316 this.fire('show-detail', this.activeNetworkState); 164 else if (this.activeNetworkState.GUID)
165 this.fire('show-detail', this.activeNetworkState);
166 else if (this.networkStateList.length > 0)
167 this.fire('show-detail', this.networkStateList[0]);
317 event.stopPropagation(); 168 event.stopPropagation();
318 }, 169 },
319 170
320 /** 171 /**
321 * Event triggered when the known networks button is tapped. 172 * @return {string}
322 * @private 173 * @private
323 */ 174 */
324 onKnownNetworksTap_: function() { 175 getDetailsA11yString_: function() {
325 this.fire('show-known-networks', {type: CrOnc.Type.WI_FI}); 176 if (!this.shouldShowList_()) {
177 if (this.activeNetworkState.GUID) {
178 return CrOnc.getNetworkName(this.activeNetworkState);
179 } else if (this.networkStateList.length > 0) {
180 return CrOnc.getNetworkName(this.networkStateList[0]);
181 }
182 }
183 return this.i18n('OncType' + this.deviceState.Type);
326 }, 184 },
327 185
328 /** 186 /**
329 * Event triggered when the enable button is toggled. 187 * Event triggered when the enable button is toggled.
330 * @param {!Event} event 188 * @param {!Event} event
331 * @private 189 * @private
332 */ 190 */
333 onDeviceEnabledTap_: function(event) { 191 onDeviceEnabledTap_: function(event) {
334 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); 192 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState);
335 var type = this.deviceState ? this.deviceState.Type : ''; 193 var type = this.deviceState ? this.deviceState.Type : '';
336 this.fire( 194 this.fire(
337 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); 195 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type});
338 // Make sure this does not propagate to onDetailsTap_. 196 // Make sure this does not propagate to onDetailsTap_.
339 event.stopPropagation(); 197 event.stopPropagation();
340 }, 198 },
341 }); 199 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/internet_page/network_summary_item.html ('k') | chrome/browser/resources/settings/route.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698