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 and modifying a list of cellular | 6 * @fileoverview Polymer element for displaying and modifying a list of cellular |
7 * access points. | 7 * access points. |
8 */ | 8 */ |
9 (function() { | |
10 'use strict'; | |
11 | |
12 Polymer({ | 9 Polymer({ |
13 is: 'network-apnlist', | 10 is: 'network-apnlist', |
14 | 11 |
15 properties: { | 12 properties: { |
16 /** | 13 /** |
17 * The current set of properties for the network matching |guid|. | 14 * The current set of properties for the network matching |guid|. |
18 * @type {!CrOnc.NetworkProperties|undefined} | 15 * @type {!CrOnc.NetworkProperties|undefined} |
19 */ | 16 */ |
20 networkProperties: { | 17 networkProperties: { |
21 type: Object, | 18 type: Object, |
22 observer: 'networkPropertiesChanged_' | 19 observer: 'networkPropertiesChanged_', |
23 }, | 20 }, |
24 | 21 |
25 /** | 22 /** |
26 * The CrOnc.APNProperties.AccessPointName value of the selected APN. | 23 * The CrOnc.APNProperties.AccessPointName value of the selected APN. |
27 */ | 24 */ |
28 selectedApn: { | 25 selectedApn: { |
29 type: String, | 26 type: String, |
30 value: '' | 27 value: '', |
31 }, | 28 }, |
32 | 29 |
33 /** | 30 /** |
34 * Selectable list of APN dictionaries for the UI. Includes an entry | 31 * Selectable list of APN dictionaries for the UI. Includes an entry |
35 * corresponding to |otherApn| (see below). | 32 * corresponding to |otherApn| (see below). |
36 * @type {!Array<!CrOnc.APNProperties>} | 33 * @type {!Array<!CrOnc.APNProperties>} |
37 */ | 34 */ |
38 apnSelectList: { | 35 apnSelectList: { |
39 type: Array, | 36 type: Array, |
40 value: function() { return []; } | 37 value: function() { |
| 38 return []; |
| 39 } |
41 }, | 40 }, |
42 | 41 |
43 /** | 42 /** |
44 * The user settable properties for a new ('other') APN. The values for | 43 * The user settable properties for a new ('other') APN. The values for |
45 * AccessPointName, Username, and Password will be set to the currently | 44 * AccessPointName, Username, and Password will be set to the currently |
46 * active APN if it does not match an existing list entry. | 45 * active APN if it does not match an existing list entry. |
47 * @type {CrOnc.APNProperties|undefined} | 46 * @type {CrOnc.APNProperties|undefined} |
48 */ | 47 */ |
49 otherApn: { | 48 otherApn: { |
50 type: Object, | 49 type: Object, |
(...skipping 20 matching lines...) Expand all Loading... |
71 return { | 70 return { |
72 'AccessPointName': 'String', | 71 'AccessPointName': 'String', |
73 'Username': 'String', | 72 'Username': 'String', |
74 'Password': 'String' | 73 'Password': 'String' |
75 }; | 74 }; |
76 }, | 75 }, |
77 readOnly: true | 76 readOnly: true |
78 }, | 77 }, |
79 }, | 78 }, |
80 | 79 |
81 /** @const */ DefaultAccessPointName: 'none', | 80 /** @const */ |
| 81 DefaultAccessPointName: 'none', |
82 | 82 |
83 /** | 83 /** |
84 * Polymer networkProperties changed method. | 84 * Polymer networkProperties changed method. |
85 */ | 85 */ |
86 networkPropertiesChanged_: function() { | 86 networkPropertiesChanged_: function() { |
87 if (!this.networkProperties || !this.networkProperties.Cellular) | 87 if (!this.networkProperties || !this.networkProperties.Cellular) |
88 return; | 88 return; |
89 | 89 |
90 /** @type {!CrOnc.APNProperties|undefined} */ var activeApn; | 90 /** @type {!CrOnc.APNProperties|undefined} */ var activeApn; |
91 var cellular = this.networkProperties.Cellular; | 91 var cellular = this.networkProperties.Cellular; |
92 /** @type {!chrome.networkingPrivate.ManagedAPNProperties|undefined} */ var | 92 /** @type {!chrome.networkingPrivate.ManagedAPNProperties|undefined} */ var |
93 apn = cellular.APN; | 93 apn = cellular.APN; |
94 if (apn && apn.AccessPointName) { | 94 if (apn && apn.AccessPointName) { |
95 activeApn = /** @type {!CrOnc.APNProperties|undefined} */( | 95 activeApn = /** @type {!CrOnc.APNProperties|undefined} */ ( |
96 CrOnc.getSimpleActiveProperties(apn)); | 96 CrOnc.getSimpleActiveProperties(apn)); |
97 } else if (cellular.LastGoodAPN && cellular.LastGoodAPN.AccessPointName) { | 97 } else if (cellular.LastGoodAPN && cellular.LastGoodAPN.AccessPointName) { |
98 activeApn = cellular.LastGoodAPN; | 98 activeApn = cellular.LastGoodAPN; |
99 } | 99 } |
100 this.setApnSelectList_(activeApn); | 100 this.setApnSelectList_(activeApn); |
101 }, | 101 }, |
102 | 102 |
103 /** | 103 /** |
104 * Sets the list of selectable APNs for the UI. Appends an 'Other' entry | 104 * Sets the list of selectable APNs for the UI. Appends an 'Other' entry |
105 * (see comments for |otherApn| above). | 105 * (see comments for |otherApn| above). |
106 * @param {CrOnc.APNProperties|undefined} activeApn The currently active APN | 106 * @param {CrOnc.APNProperties|undefined} activeApn The currently active APN |
107 * properties. | 107 * properties. |
108 * @private | 108 * @private |
109 */ | 109 */ |
110 setApnSelectList_: function(activeApn) { | 110 setApnSelectList_: function(activeApn) { |
111 // Copy the list of APNs from this.networkProperties. | 111 // Copy the list of APNs from this.networkProperties. |
112 var result = this.getApnList_().slice(); | 112 var result = this.getApnList_().slice(); |
113 | 113 |
114 // Test whether |activeApn| is in the current APN list in networkProperties. | 114 // Test whether |activeApn| is in the current APN list in networkProperties. |
115 var activeApnInList = activeApn && result.some( | 115 var activeApnInList = activeApn && result.some(function(a) { |
116 function(a) { return a.AccessPointName == activeApn.AccessPointName; }); | 116 return a.AccessPointName == activeApn.AccessPointName; |
| 117 }); |
117 | 118 |
118 // If |activeApn| is specified and not in the list, use the active | 119 // If |activeApn| is specified and not in the list, use the active |
119 // properties for 'other'. Otherwise use any existing 'other' properties. | 120 // properties for 'other'. Otherwise use any existing 'other' properties. |
120 var otherApnProperties = | 121 var otherApnProperties = |
121 (activeApn && !activeApnInList) ? activeApn : this.otherApn; | 122 (activeApn && !activeApnInList) ? activeApn : this.otherApn; |
122 var otherApn = this.createApnObject_(otherApnProperties); | 123 var otherApn = this.createApnObject_(otherApnProperties); |
123 | 124 |
124 // Always use 'Other' for the name of custom APN entries (the name does | 125 // Always use 'Other' for the name of custom APN entries (the name does |
125 // not get saved). | 126 // not get saved). |
126 otherApn.Name = 'Other'; | 127 otherApn.Name = 'Other'; |
127 | 128 |
128 // If no 'active' or 'other' AccessPointName was provided, use the default. | 129 // If no 'active' or 'other' AccessPointName was provided, use the default. |
129 otherApn.AccessPointName = | 130 otherApn.AccessPointName = |
130 otherApn.AccessPointName || this.DefaultAccessPointName; | 131 otherApn.AccessPointName || this.DefaultAccessPointName; |
131 | 132 |
132 // Save the 'other' properties. | 133 // Save the 'other' properties. |
133 this.otherApn = otherApn; | 134 this.otherApn = otherApn; |
134 | 135 |
135 // Append 'other' to the end of the list of APNs. | 136 // Append 'other' to the end of the list of APNs. |
136 result.push(otherApn); | 137 result.push(otherApn); |
137 | 138 |
138 this.set('apnSelectList', result); | 139 this.apnSelectList = result; |
139 this.set( | 140 this.selectedApn = |
140 'selectedApn', | 141 (activeApn && activeApn.AccessPointName) || otherApn.AccessPointName; |
141 (activeApn && activeApn.AccessPointName) || otherApn.AccessPointName); | 142 // We need to flush the DOM here, otherwise the paper-dropdown-menu will |
| 143 // not update to correctly display the selected AccessPointName. |
| 144 Polymer.dom.flush(); |
142 }, | 145 }, |
143 | 146 |
144 /** | 147 /** |
145 * @param {!CrOnc.APNProperties|undefined=} apnProperties | 148 * @param {!CrOnc.APNProperties|undefined=} apnProperties |
146 * @return {!CrOnc.APNProperties} A new APN object with properties from | 149 * @return {!CrOnc.APNProperties} A new APN object with properties from |
147 * |apnProperties| if provided. | 150 * |apnProperties| if provided. |
148 * @private | 151 * @private |
149 */ | 152 */ |
150 createApnObject_: function(apnProperties) { | 153 createApnObject_: function(apnProperties) { |
151 var newApn = {AccessPointName: ''}; | 154 var newApn = {AccessPointName: ''}; |
(...skipping 12 matching lines...) Expand all Loading... |
164 return []; | 167 return []; |
165 /** @type {!chrome.networkingPrivate.ManagedAPNList|undefined} */ var | 168 /** @type {!chrome.networkingPrivate.ManagedAPNList|undefined} */ var |
166 apnlist = this.networkProperties.Cellular.APNList; | 169 apnlist = this.networkProperties.Cellular.APNList; |
167 if (!apnlist) | 170 if (!apnlist) |
168 return []; | 171 return []; |
169 return /** @type {!Array<!CrOnc.APNProperties>} */ ( | 172 return /** @type {!Array<!CrOnc.APNProperties>} */ ( |
170 CrOnc.getActiveValue(apnlist)); | 173 CrOnc.getActiveValue(apnlist)); |
171 }, | 174 }, |
172 | 175 |
173 /** | 176 /** |
174 * We need to update the select value after the dom-repeat template updates: | |
175 * 1. Rebuilding the template options resets the select value property. | |
176 * 2. The template update occurs after any property changed events. | |
177 * TODO(stevenjb): Remove once we use cr-dropdown-menu which (hopefully) | |
178 * won't require this. | |
179 * @private | |
180 */ | |
181 onSelectApnUpdated_: function() { | |
182 this.$.selectApn.value = this.selectedApn; | |
183 }, | |
184 | |
185 /** | |
186 * Event triggered when the selectApn selection changes. | 177 * Event triggered when the selectApn selection changes. |
187 * @param {Event} event The select node change event. | 178 * @param {!{detail: !{selected: string}}} e |
188 * @private | 179 * @private |
189 */ | 180 */ |
190 onSelectApnChange_: function(event) { | 181 onSelectApnChange_: function(e) { |
191 var selectedApn = event.target.value; | 182 var selectedApn = e.detail.selected; |
192 // When selecting 'Other', don't set a change event unless a valid | 183 // When selecting 'Other', don't set a change event unless a valid |
193 // non-default value has been set for Other. | 184 // non-default value has been set for Other. |
194 if (this.isOtherSelected_(this.networkProperties, selectedApn) && | 185 if (this.isOtherSelected_(this.networkProperties, selectedApn) && |
195 (!this.otherApn || !this.otherApn.AccessPointName || | 186 (!this.otherApn || !this.otherApn.AccessPointName || |
196 this.otherApn.AccessPointName == this.DefaultAccessPointName)) { | 187 this.otherApn.AccessPointName == this.DefaultAccessPointName)) { |
197 return; | 188 return; |
198 } | 189 } |
199 this.sendApnChange_(selectedApn); | 190 this.sendApnChange_(selectedApn); |
200 }, | 191 }, |
201 | 192 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 * @private | 259 * @private |
269 */ | 260 */ |
270 findApnInList: function(apnList, accessPointName) { | 261 findApnInList: function(apnList, accessPointName) { |
271 for (let a of apnList) { | 262 for (let a of apnList) { |
272 if (a.AccessPointName == accessPointName) | 263 if (a.AccessPointName == accessPointName) |
273 return a; | 264 return a; |
274 } | 265 } |
275 return undefined; | 266 return undefined; |
276 } | 267 } |
277 }); | 268 }); |
278 })(); | |
OLD | NEW |