OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('options.internet', function() { | 5 cr.define('options.internet', function() { |
6 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
7 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 7 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
8 /** @const */ var IPAddressField = options.internet.IPAddressField; | 8 /** @const */ var IPAddressField = options.internet.IPAddressField; |
9 | 9 |
10 /** | 10 /** |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 } | 56 } |
57 | 57 |
58 /** | 58 /** |
59 * UI pref change handler. | 59 * UI pref change handler. |
60 * @param {Event} e The update event. | 60 * @param {Event} e The update event. |
61 */ | 61 */ |
62 function handlePrefUpdate(e) { | 62 function handlePrefUpdate(e) { |
63 DetailsInternetPage.getInstance().updateControls(); | 63 DetailsInternetPage.getInstance().updateControls(); |
64 } | 64 } |
65 | 65 |
66 /** | |
67 * Simple helper method for converting a field to a string. It is used to | |
68 * easily assign an empty string from fields that may be unknown or undefined. | |
69 * @param {object} value that should be converted to a string. | |
70 * @return {string} the result. | |
71 */ | |
72 function stringFromValue(value) { | |
73 return value ? String(value) : ''; | |
74 } | |
75 | |
66 ///////////////////////////////////////////////////////////////////////////// | 76 ///////////////////////////////////////////////////////////////////////////// |
67 // DetailsInternetPage class: | 77 // DetailsInternetPage class: |
68 | 78 |
69 /** | 79 /** |
70 * Encapsulated handling of ChromeOS internet details overlay page. | 80 * Encapsulated handling of ChromeOS internet details overlay page. |
71 * @constructor | 81 * @constructor |
72 */ | 82 */ |
73 function DetailsInternetPage() { | 83 function DetailsInternetPage() { |
74 OptionsPage.call(this, | 84 OptionsPage.call(this, |
75 'detailsInternetPage', | 85 'detailsInternetPage', |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 var data = $('connection-state').data; | 163 var data = $('connection-state').data; |
154 var apnSelector = $('select-apn'); | 164 var apnSelector = $('select-apn'); |
155 | 165 |
156 if (data.userApnIndex != -1) { | 166 if (data.userApnIndex != -1) { |
157 apnSelector.remove(data.userApnIndex); | 167 apnSelector.remove(data.userApnIndex); |
158 data.userApnIndex = -1; | 168 data.userApnIndex = -1; |
159 } | 169 } |
160 | 170 |
161 if (data.providerApnList.value.length > 0) { | 171 if (data.providerApnList.value.length > 0) { |
162 var iApn = 0; | 172 var iApn = 0; |
163 data.apn.apn = data.providerApnList.value[iApn].apn; | 173 var defaultApn = data.providerApnList.value[iApn]; |
164 var username = data.providerApnList.value[iApn].username; | 174 data.apn.apn = stringFromValue(defaultApn.apn); |
165 var password = data.providerApnList.value[iApn].password; | 175 data.apn.username = stringFromValue(defaultApn.username); |
166 data.apn.username = username ? username : ''; | 176 data.apn.password = stringFromValue(defaultApn.password); |
167 data.apn.password = password ? password : ''; | |
168 chrome.send('setApn', [data.servicePath, | 177 chrome.send('setApn', [data.servicePath, |
169 String(data.apn.apn), | 178 data.apn.apn, |
170 String(data.apn.username), | 179 data.apn.username, |
171 String(data.apn.password)]); | 180 data.apn.password]); |
172 apnSelector.selectedIndex = iApn; | 181 apnSelector.selectedIndex = iApn; |
173 data.selectedApn = iApn; | 182 data.selectedApn = iApn; |
174 } else { | 183 } else { |
175 data.apn.apn = ''; | 184 data.apn.apn = ''; |
176 data.apn.username = ''; | 185 data.apn.username = ''; |
177 data.apn.password = ''; | 186 data.apn.password = ''; |
178 apnSelector.selectedIndex = -1; | 187 apnSelector.selectedIndex = -1; |
179 data.selectedApn = -1; | 188 data.selectedApn = -1; |
180 } | 189 } |
181 updateHidden('.apn-list-view', false); | 190 updateHidden('.apn-list-view', false); |
182 updateHidden('.apn-details-view', true); | 191 updateHidden('.apn-details-view', true); |
183 }); | 192 }); |
184 | 193 |
185 $('cellular-apn-set').addEventListener('click', function(event) { | 194 $('cellular-apn-set').addEventListener('click', function(event) { |
186 if ($('cellular-apn').value == '') | 195 if ($('cellular-apn').value == '') |
187 return; | 196 return; |
188 | 197 |
189 var data = $('connection-state').data; | 198 var data = $('connection-state').data; |
190 var apnSelector = $('select-apn'); | 199 var apnSelector = $('select-apn'); |
191 | 200 |
192 data.apn.apn = String($('cellular-apn').value); | 201 data.apn.apn = stringFromValue($('cellular-apn').value); |
193 data.apn.username = String($('cellular-apn-username').value); | 202 data.apn.username = stringFromValue($('cellular-apn-username').value); |
194 data.apn.password = String($('cellular-apn-password').value); | 203 data.apn.password = stringFromValue($('cellular-apn-password').value); |
204 data.userApn = { | |
205 'apn': data.apn.apn, | |
206 'username': data.apn.username, | |
207 'password': data.apn.password | |
208 }; | |
stevenjb
2013/09/03 21:44:32
nit/question: Could this just be data.userApn = da
armansito
2013/09/03 22:07:38
I think the code just modifies data.apn instead of
| |
195 chrome.send('setApn', [data.servicePath, | 209 chrome.send('setApn', [data.servicePath, |
196 String(data.apn.apn), | 210 data.apn.apn, |
197 String(data.apn.username), | 211 data.apn.username, |
198 String(data.apn.password)]); | 212 data.apn.password]); |
199 | 213 |
200 if (data.userApnIndex != -1) { | 214 if (data.userApnIndex != -1) { |
201 apnSelector.remove(data.userApnIndex); | 215 apnSelector.remove(data.userApnIndex); |
202 data.userApnIndex = -1; | 216 data.userApnIndex = -1; |
203 } | 217 } |
204 | 218 |
205 var option = document.createElement('option'); | 219 var option = document.createElement('option'); |
206 option.textContent = data.apn.apn; | 220 option.textContent = data.apn.apn; |
207 option.value = -1; | 221 option.value = -1; |
208 option.selected = true; | 222 option.selected = true; |
(...skipping 10 matching lines...) Expand all Loading... | |
219 updateHidden('.apn-list-view', false); | 233 updateHidden('.apn-list-view', false); |
220 updateHidden('.apn-details-view', true); | 234 updateHidden('.apn-details-view', true); |
221 }); | 235 }); |
222 | 236 |
223 $('select-apn').addEventListener('change', function(event) { | 237 $('select-apn').addEventListener('change', function(event) { |
224 var data = $('connection-state').data; | 238 var data = $('connection-state').data; |
225 var apnSelector = $('select-apn'); | 239 var apnSelector = $('select-apn'); |
226 if (apnSelector[apnSelector.selectedIndex].value != -1) { | 240 if (apnSelector[apnSelector.selectedIndex].value != -1) { |
227 var apnList = data.providerApnList.value; | 241 var apnList = data.providerApnList.value; |
228 chrome.send('setApn', [data.servicePath, | 242 chrome.send('setApn', [data.servicePath, |
229 String(apnList[apnSelector.selectedIndex].apn), | 243 stringFromValue(apnList[apnSelector.selectedIndex].apn), |
230 String(apnList[apnSelector.selectedIndex].username), | 244 stringFromValue(apnList[apnSelector.selectedIndex].username), |
231 String(apnList[apnSelector.selectedIndex].password) | 245 stringFromValue(apnList[apnSelector.selectedIndex].password)] |
232 ]); | 246 ); |
233 data.selectedApn = apnSelector.selectedIndex; | 247 data.selectedApn = apnSelector.selectedIndex; |
234 } else if (apnSelector.selectedIndex == data.userApnIndex) { | 248 } else if (apnSelector.selectedIndex == data.userApnIndex) { |
235 chrome.send('setApn', [data.servicePath, | 249 chrome.send('setApn', [data.servicePath, |
236 String(data.apn.apn), | 250 stringFromValue(data.userApn.apn), |
237 String(data.apn.username), | 251 stringFromValue(data.userApn.username), |
238 String(data.apn.password)]); | 252 stringFromValue(data.userApn.password)]); |
239 data.selectedApn = apnSelector.selectedIndex; | 253 data.selectedApn = apnSelector.selectedIndex; |
240 } else { | 254 } else { |
241 $('cellular-apn').value = data.apn.apn; | 255 $('cellular-apn').value = stringFromValue(data.apn.apn); |
242 var username = data.apn.username; | 256 $('cellular-apn-username').value = stringFromValue(data.apn.username); |
243 var password = data.apn.password; | 257 $('cellular-apn-password').value = stringFromValue(data.apn.password); |
244 $('cellular-apn-username').value = username ? username : ''; | |
245 $('cellular-apn-password').value = password ? password : ''; | |
246 | 258 |
247 updateHidden('.apn-list-view', true); | 259 updateHidden('.apn-list-view', true); |
248 updateHidden('.apn-details-view', false); | 260 updateHidden('.apn-details-view', false); |
249 } | 261 } |
250 }); | 262 }); |
251 | 263 |
252 $('sim-card-lock-enabled').addEventListener('click', function(event) { | 264 $('sim-card-lock-enabled').addEventListener('click', function(event) { |
253 var newValue = $('sim-card-lock-enabled').checked; | 265 var newValue = $('sim-card-lock-enabled').checked; |
254 // Leave value as is because user needs to enter PIN code first. | 266 // Leave value as is because user needs to enter PIN code first. |
255 // When PIN will be entered and value changed, | 267 // When PIN will be entered and value changed, |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1119 $(property).parentElement.hidden = true; | 1131 $(property).parentElement.hidden = true; |
1120 }; | 1132 }; |
1121 setContentOrHide('esn'); | 1133 setContentOrHide('esn'); |
1122 setContentOrHide('imei'); | 1134 setContentOrHide('imei'); |
1123 setContentOrHide('meid'); | 1135 setContentOrHide('meid'); |
1124 setContentOrHide('min'); | 1136 setContentOrHide('min'); |
1125 setContentOrHide('prl-version'); | 1137 setContentOrHide('prl-version'); |
1126 })(); | 1138 })(); |
1127 detailsPage.gsm = data.gsm; | 1139 detailsPage.gsm = data.gsm; |
1128 if (data.gsm) { | 1140 if (data.gsm) { |
1129 $('iccid').textContent = data.iccid ? data.iccid : ''; | 1141 $('iccid').textContent = stringFromValue(data.iccid); |
1130 $('imsi').textContent = data.imsi ? data.imsi : ''; | 1142 $('imsi').textContent = stringFromValue(data.imsi); |
1131 | 1143 |
1132 var apnSelector = $('select-apn'); | 1144 var apnSelector = $('select-apn'); |
1133 // Clear APN lists, keep only last element that "other". | 1145 // Clear APN lists, keep only last element that "other". |
1134 while (apnSelector.length != 1) | 1146 while (apnSelector.length != 1) |
1135 apnSelector.remove(0); | 1147 apnSelector.remove(0); |
1136 var otherOption = apnSelector[0]; | 1148 var otherOption = apnSelector[0]; |
1137 data.selectedApn = -1; | 1149 data.selectedApn = -1; |
1138 data.userApnIndex = -1; | 1150 data.userApnIndex = -1; |
1139 var apnList = data.providerApnList.value; | 1151 var apnList = data.providerApnList.value; |
1140 for (var i = 0; i < apnList.length; i++) { | 1152 for (var i = 0; i < apnList.length; i++) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1240 | 1252 |
1241 // Don't show page name in address bar and in history to prevent people | 1253 // Don't show page name in address bar and in history to prevent people |
1242 // navigate here by hand and solve issue with page session restore. | 1254 // navigate here by hand and solve issue with page session restore. |
1243 OptionsPage.showPageByName('detailsInternetPage', false); | 1255 OptionsPage.showPageByName('detailsInternetPage', false); |
1244 }; | 1256 }; |
1245 | 1257 |
1246 return { | 1258 return { |
1247 DetailsInternetPage: DetailsInternetPage | 1259 DetailsInternetPage: DetailsInternetPage |
1248 }; | 1260 }; |
1249 }); | 1261 }); |
OLD | NEW |