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

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

Issue 2300783002: MD Settings: Internet: Cleanup JS (Closed)
Patch Set: Created 4 years, 3 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 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 Polymer({ 9 Polymer({
10 is: 'network-apnlist', 10 is: 'network-apnlist',
11 11
12 properties: { 12 properties: {
13 /** 13 /**
14 * The current set of properties for the network matching |guid|. 14 * The current set of properties for the network matching |guid|.
15 * @type {!CrOnc.NetworkProperties|undefined} 15 * @type {!CrOnc.NetworkProperties|undefined}
16 */ 16 */
17 networkProperties: { 17 networkProperties: {
18 type: Object, 18 type: Object,
19 observer: 'networkPropertiesChanged_', 19 observer: 'networkPropertiesChanged_',
20 }, 20 },
21 21
22 /** 22 /** The CrOnc.APNProperties.AccessPointName value of the selected APN. */
23 * The CrOnc.APNProperties.AccessPointName value of the selected APN. 23 selectedApn_: {
24 */
25 selectedApn: {
26 type: String, 24 type: String,
27 value: '', 25 value: '',
28 }, 26 },
29 27
30 /** 28 /**
31 * Selectable list of APN dictionaries for the UI. Includes an entry 29 * Selectable list of APN dictionaries for the UI. Includes an entry
32 * corresponding to |otherApn| (see below). 30 * corresponding to |otherApn| (see below).
33 * @type {!Array<!CrOnc.APNProperties>} 31 * @type {!Array<!CrOnc.APNProperties>}
34 */ 32 */
35 apnSelectList: { 33 apnSelectList_: {
36 type: Array, 34 type: Array,
37 value: function() { 35 value: function() {
38 return []; 36 return [];
39 } 37 }
40 }, 38 },
41 39
42 /** 40 /**
43 * The user settable properties for a new ('other') APN. The values for 41 * The user settable properties for a new ('other') APN. The values for
44 * AccessPointName, Username, and Password will be set to the currently 42 * AccessPointName, Username, and Password will be set to the currently
45 * active APN if it does not match an existing list entry. 43 * active APN if it does not match an existing list entry.
46 * @type {CrOnc.APNProperties|undefined} 44 * @type {CrOnc.APNProperties|undefined}
47 */ 45 */
48 otherApn: { 46 otherApn_: {
49 type: Object, 47 type: Object,
50 }, 48 },
51 49
52 /** 50 /**
53 * Array of property names to pass to the Other APN property list. 51 * Array of property names to pass to the Other APN property list.
54 * @type {!Array<string>} 52 * @type {!Array<string>}
55 */ 53 */
56 otherApnFields_: { 54 otherApnFields_: {
57 type: Array, 55 type: Array,
58 value: function() { 56 value: function() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 activeApn = /** @type {!CrOnc.APNProperties|undefined} */ ( 93 activeApn = /** @type {!CrOnc.APNProperties|undefined} */ (
96 CrOnc.getSimpleActiveProperties(apn)); 94 CrOnc.getSimpleActiveProperties(apn));
97 } else if (cellular.LastGoodAPN && cellular.LastGoodAPN.AccessPointName) { 95 } else if (cellular.LastGoodAPN && cellular.LastGoodAPN.AccessPointName) {
98 activeApn = cellular.LastGoodAPN; 96 activeApn = cellular.LastGoodAPN;
99 } 97 }
100 this.setApnSelectList_(activeApn); 98 this.setApnSelectList_(activeApn);
101 }, 99 },
102 100
103 /** 101 /**
104 * Sets the list of selectable APNs for the UI. Appends an 'Other' entry 102 * Sets the list of selectable APNs for the UI. Appends an 'Other' entry
105 * (see comments for |otherApn| above). 103 * (see comments for |otherApn_| above).
106 * @param {CrOnc.APNProperties|undefined} activeApn The currently active APN 104 * @param {CrOnc.APNProperties|undefined} activeApn The currently active APN
107 * properties. 105 * properties.
108 * @private 106 * @private
109 */ 107 */
110 setApnSelectList_: function(activeApn) { 108 setApnSelectList_: function(activeApn) {
111 // Copy the list of APNs from this.networkProperties. 109 // Copy the list of APNs from this.networkProperties.
112 var result = this.getApnList_().slice(); 110 var result = this.getApnList_().slice();
113 111
114 // Test whether |activeApn| is in the current APN list in networkProperties. 112 // Test whether |activeApn| is in the current APN list in networkProperties.
115 var activeApnInList = activeApn && result.some(function(a) { 113 var activeApnInList = activeApn && result.some(function(a) {
116 return a.AccessPointName == activeApn.AccessPointName; 114 return a.AccessPointName == activeApn.AccessPointName;
117 }); 115 });
118 116
119 // If |activeApn| is specified and not in the list, use the active 117 // If |activeApn| is specified and not in the list, use the active
120 // properties for 'other'. Otherwise use any existing 'other' properties. 118 // properties for 'other'. Otherwise use any existing 'other' properties.
121 var otherApnProperties = 119 var otherApnProperties =
122 (activeApn && !activeApnInList) ? activeApn : this.otherApn; 120 (activeApn && !activeApnInList) ? activeApn : this.otherApn_;
123 var otherApn = this.createApnObject_(otherApnProperties); 121 var otherApn = this.createApnObject_(otherApnProperties);
124 122
125 // Always use 'Other' for the name of custom APN entries (the name does 123 // Always use 'Other' for the name of custom APN entries (the name does
126 // not get saved). 124 // not get saved).
127 otherApn.Name = 'Other'; 125 otherApn.Name = 'Other';
128 126
129 // If no 'active' or 'other' AccessPointName was provided, use the default. 127 // If no 'active' or 'other' AccessPointName was provided, use the default.
130 otherApn.AccessPointName = 128 otherApn.AccessPointName =
131 otherApn.AccessPointName || this.DefaultAccessPointName; 129 otherApn.AccessPointName || this.DefaultAccessPointName;
132 130
133 // Save the 'other' properties. 131 // Save the 'other' properties.
134 this.otherApn = otherApn; 132 this.otherApn_ = otherApn;
135 133
136 // Append 'other' to the end of the list of APNs. 134 // Append 'other' to the end of the list of APNs.
137 result.push(otherApn); 135 result.push(otherApn);
138 136
139 this.apnSelectList = result; 137 this.apnSelectList_ = result;
140 this.selectedApn = 138 this.selectedApn_ =
141 (activeApn && activeApn.AccessPointName) || otherApn.AccessPointName; 139 (activeApn && activeApn.AccessPointName) || otherApn.AccessPointName;
142 // We need to flush the DOM here, otherwise the paper-dropdown-menu-light 140 // We need to flush the DOM here, otherwise the paper-dropdown-menu-light
143 // will not update to correctly display the selected AccessPointName. 141 // will not update to correctly display the selected AccessPointName.
144 Polymer.dom.flush(); 142 Polymer.dom.flush();
145 }, 143 },
146 144
147 /** 145 /**
148 * @param {!CrOnc.APNProperties|undefined=} apnProperties 146 * @param {!CrOnc.APNProperties|undefined=} apnProperties
149 * @return {!CrOnc.APNProperties} A new APN object with properties from 147 * @return {!CrOnc.APNProperties} A new APN object with properties from
150 * |apnProperties| if provided. 148 * |apnProperties| if provided.
(...skipping 17 matching lines...) Expand all
168 /** @type {!chrome.networkingPrivate.ManagedAPNList|undefined} */ var 166 /** @type {!chrome.networkingPrivate.ManagedAPNList|undefined} */ var
169 apnlist = this.networkProperties.Cellular.APNList; 167 apnlist = this.networkProperties.Cellular.APNList;
170 if (!apnlist) 168 if (!apnlist)
171 return []; 169 return [];
172 return /** @type {!Array<!CrOnc.APNProperties>} */ ( 170 return /** @type {!Array<!CrOnc.APNProperties>} */ (
173 CrOnc.getActiveValue(apnlist)); 171 CrOnc.getActiveValue(apnlist));
174 }, 172 },
175 173
176 /** 174 /**
177 * Event triggered when the selectApn selection changes. 175 * Event triggered when the selectApn selection changes.
178 * @param {!{detail: !{selected: string}}} e 176 * @param {!{detail: !{selected: string}}} event
Dan Beam 2016/08/31 21:59:47 nit: CustomEvent (and then cast detail to {selecte
179 * @private 177 * @private
180 */ 178 */
181 onSelectApnChange_: function(e) { 179 onSelectApnChange_: function(event) {
182 var selectedApn = e.detail.selected; 180 var selectedApn = event.detail.selected;
183 // When selecting 'Other', don't set a change event unless a valid 181 // When selecting 'Other', don't set a change event unless a valid
184 // non-default value has been set for Other. 182 // non-default value has been set for Other.
185 if (this.isOtherSelected_(this.networkProperties, selectedApn) && 183 if (this.isOtherSelected_(selectedApn) &&
186 (!this.otherApn || !this.otherApn.AccessPointName || 184 (!this.otherApn_ || !this.otherApn_.AccessPointName ||
187 this.otherApn.AccessPointName == this.DefaultAccessPointName)) { 185 this.otherApn_.AccessPointName == this.DefaultAccessPointName)) {
188 return; 186 return;
189 } 187 }
190 this.sendApnChange_(selectedApn); 188 this.sendApnChange_(selectedApn);
191 }, 189 },
192 190
193 /** 191 /**
194 * Event triggered when any 'Other' APN network property changes. 192 * Event triggered when any 'Other' APN network property changes.
195 * @param {!{detail: {field: string, value: string}}} event 193 * @param {!{detail: {field: string, value: string}}} event
196 * @private 194 * @private
197 */ 195 */
198 onOtherApnChange_: function(event) { 196 onOtherApnChange_: function(event) {
199 this.set('otherApn.' + event.detail.field, event.detail.value); 197 this.set('otherApn.' + event.detail.field, event.detail.value);
200 // Don't send a change event for 'Other' until the 'Save' button is tapped. 198 // Don't send a change event for 'Other' until the 'Save' button is tapped.
201 }, 199 },
202 200
203 /** 201 /**
204 * Event triggered when the Other APN 'Save' button is tapped. 202 * Event triggered when the Other APN 'Save' button is tapped.
205 * @param {Event} event 203 * @param {Event} event
206 * @private 204 * @private
207 */ 205 */
208 onSaveOtherTap_: function(event) { 206 onSaveOtherTap_: function(event) {
209 this.sendApnChange_(this.selectedApn); 207 this.sendApnChange_(this.selectedApn_);
210 }, 208 },
211 209
212 /** 210 /**
213 * Send the apn-change event. 211 * Send the apn-change event.
214 * @param {string} selectedApn 212 * @param {string} selectedApn
215 * @private 213 * @private
216 */ 214 */
217 sendApnChange_: function(selectedApn) { 215 sendApnChange_: function(selectedApn) {
218 var apnList = this.getApnList_(); 216 var apnList = this.getApnList_();
219 var apn = this.findApnInList(apnList, selectedApn); 217 var apn = this.findApnInList(apnList, selectedApn);
220 if (apn == undefined) { 218 if (apn == undefined) {
221 apn = this.createApnObject_(); 219 apn = this.createApnObject_();
222 if (this.otherApn) { 220 if (this.otherApn_) {
223 apn.AccessPointName = this.otherApn.AccessPointName; 221 apn.AccessPointName = this.otherApn_.AccessPointName;
224 apn.Username = this.otherApn.Username; 222 apn.Username = this.otherApn_.Username;
225 apn.Password = this.otherApn.Password; 223 apn.Password = this.otherApn_.Password;
226 } 224 }
227 } 225 }
228 this.fire('apn-change', {field: 'APN', value: apn}); 226 this.fire('apn-change', {field: 'APN', value: apn});
229 }, 227 },
230 228
231 /** 229 /**
232 * @param {!CrOnc.NetworkProperties|undefined} networkProperties
233 * @param {string} selectedApn 230 * @param {string} selectedApn
Dan Beam 2016/08/31 21:59:47 are you mixing this.* with @params?
stevenjb 2016/08/31 22:10:16 I'm not sure I understand your question. I am avo
234 * @return {boolean} True if the 'other' APN is currently selected. 231 * @return {boolean} True if the 'other' APN is currently selected.
235 * @private 232 * @private
236 */ 233 */
237 isOtherSelected_: function(networkProperties, selectedApn) { 234 isOtherSelected_: function(selectedApn) {
238 if (!networkProperties || !networkProperties.Cellular) 235 if (!this.networkProperties || !this.networkProperties.Cellular)
239 return false; 236 return false;
240 var apnList = this.getApnList_(); 237 var apnList = this.getApnList_();
241 var apn = this.findApnInList(apnList, selectedApn); 238 var apn = this.findApnInList(apnList, selectedApn);
242 return apn == undefined; 239 return apn == undefined;
243 }, 240 },
244 241
245 /** 242 /**
246 * @param {!CrOnc.APNProperties} apn 243 * @param {!CrOnc.APNProperties} apn
247 * @return {string} The most descriptive name for the access point. 244 * @return {string} The most descriptive name for the access point.
248 * @private 245 * @private
(...skipping 10 matching lines...) Expand all
259 * @private 256 * @private
260 */ 257 */
261 findApnInList: function(apnList, accessPointName) { 258 findApnInList: function(apnList, accessPointName) {
262 for (let a of apnList) { 259 for (let a of apnList) {
263 if (a.AccessPointName == accessPointName) 260 if (a.AccessPointName == accessPointName)
264 return a; 261 return a;
265 } 262 }
266 return undefined; 263 return undefined;
267 } 264 }
268 }); 265 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698