| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 /** | 6 /** |
| 7 * Creates a new network list div. | 7 * Creates a new network list div. |
| 8 * @param {Object=} opt_propertyBag Optional properties. | 8 * @param {Object=} opt_propertyBag Optional properties. |
| 9 * @constructor | 9 * @constructor |
| 10 * @extends {HTMLDivElement} | 10 * @extends {HTMLDivElement} |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 handleClick_: function(e) { | 40 handleClick_: function(e) { |
| 41 // We shouldn't respond to click events selecting an input, | 41 // We shouldn't respond to click events selecting an input, |
| 42 // so return on those. | 42 // so return on those. |
| 43 if (e.target.tagName == 'INPUT') { | 43 if (e.target.tagName == 'INPUT') { |
| 44 return; | 44 return; |
| 45 } | 45 } |
| 46 // Handle left button click | 46 // Handle left button click |
| 47 if (e.button == 0) { | 47 if (e.button == 0) { |
| 48 var el = e.target; | 48 var el = e.target; |
| 49 // If click is on action buttons of a network item. | 49 // If click is on action buttons of a network item. |
| 50 if (el.buttonType && el.networkType && el.servicePath) { | 50 if (!(el.buttonType && el.networkType && el.servicePath)) { |
| 51 chrome.send('buttonClickCallback', | |
| 52 [String(el.networkType), el.servicePath, el.buttonType]); | |
| 53 } else { | |
| 54 if (el.className == 'other-network' || el.buttonType) { | 51 if (el.className == 'other-network' || el.buttonType) { |
| 55 return; | 52 return; |
| 56 } | 53 } |
| 57 // If click is on a network item or its label, walk up the DOM tree | 54 // If click is on a network item or its label, walk up the DOM tree |
| 58 // to find the network item. | 55 // to find the network item. |
| 59 var item = el; | 56 var item = el; |
| 60 while (item && !item.data) { | 57 while (item && !item.data) { |
| 61 item = item.parentNode; | 58 item = item.parentNode; |
| 62 } | 59 } |
| 63 if (item.connecting) | 60 if (item.connecting) |
| 64 return; | 61 return; |
| 65 | 62 |
| 66 if (item) { | 63 if (item) { |
| 67 var data = item.data; | 64 var data = item.data; |
| 68 // Don't try to connect to Ethernet. | 65 // Don't try to connect to Ethernet or unactivated Cellular. |
| 69 if (data && data.networkType == 1) | 66 if (data && (data.networkType == 1 || |
| 67 (data.networkType == 5 && data.activation_state != 1))) |
| 70 return; | 68 return; |
| 71 for (var i = 0; i < this.childNodes.length; i++) { | 69 for (var i = 0; i < this.childNodes.length; i++) { |
| 72 if (this.childNodes[i] != item) | 70 if (this.childNodes[i] != item) |
| 73 this.childNodes[i].hidePassword(); | 71 this.childNodes[i].hidePassword(); |
| 74 } | 72 } |
| 75 // If clicked on other networks item. | 73 // If clicked on other networks item. |
| 76 if (data && data.servicePath == '?') { | 74 if (data && data.servicePath == '?') { |
| 77 item.showOtherLogin(); | 75 item.showOtherLogin(); |
| 78 } else if (data) { | 76 } else if (data) { |
| 79 if (!data.connecting && !data.connected) { | 77 if (!data.connecting && !data.connected) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 this.data.activation_state != | 189 this.data.activation_state != |
| 192 NetworkItem.ACTIVATION_STATE_ACTIVATED && | 190 NetworkItem.ACTIVATION_STATE_ACTIVATED && |
| 193 this.data.activation_state != | 191 this.data.activation_state != |
| 194 NetworkItem.ACTIVATION_STATE_ACTIVATING; | 192 NetworkItem.ACTIVATION_STATE_ACTIVATING; |
| 195 | 193 |
| 196 // Disconnect button if not ethernet and if cellular it should be | 194 // Disconnect button if not ethernet and if cellular it should be |
| 197 // activated. | 195 // activated. |
| 198 if (this.data.networkType != NetworkItem.TYPE_ETHERNET && | 196 if (this.data.networkType != NetworkItem.TYPE_ETHERNET && |
| 199 !show_activate && this.data.connected) { | 197 !show_activate && this.data.connected) { |
| 200 buttonsDiv.appendChild( | 198 buttonsDiv.appendChild( |
| 201 this.createButton_('disconnect_button', | 199 this.createButton_('disconnect_button', 'disconnect', |
| 202 function(e) { | 200 function(e) { |
| 203 chrome.send('buttonClickCallback', | 201 chrome.send('buttonClickCallback', |
| 204 [String(self.data.networkType), | 202 [String(self.data.networkType), |
| 205 self.data.servicePath, | 203 self.data.servicePath, |
| 206 'disconnect']); | 204 'disconnect']); |
| 207 })); | 205 })); |
| 208 } | 206 } |
| 209 // Show [Activate] button for non-activated Cellular network. | 207 // Show [Activate] button for non-activated Cellular network. |
| 210 if (show_activate) { | 208 if (show_activate) { |
| 211 buttonsDiv.appendChild( | 209 buttonsDiv.appendChild( |
| 212 this.createButton_('activate_button', | 210 this.createButton_('activate_button', 'activate', |
| 213 function(e) { | 211 function(e) { |
| 214 chrome.send('buttonClickCallback', | 212 chrome.send('buttonClickCallback', |
| 215 [String(self.data.networkType), | 213 [String(self.data.networkType), |
| 216 self.data.servicePath, | 214 self.data.servicePath, |
| 217 'activate']); | 215 'activate']); |
| 218 })); | 216 })); |
| 219 } | 217 } |
| 220 if (this.data.connected) { | 218 if (this.data.connected) { |
| 221 buttonsDiv.appendChild( | 219 buttonsDiv.appendChild( |
| 222 this.createButton_('options_button', | 220 this.createButton_('options_button', 'options', |
| 223 function(e) { | 221 function(e) { |
| 224 chrome.send('buttonClickCallback', | 222 chrome.send('buttonClickCallback', |
| 225 [String(self.data.networkType), | 223 [String(self.data.networkType), |
| 226 self.data.servicePath, | 224 self.data.servicePath, |
| 227 'options']); | 225 'options']); |
| 228 })); | 226 })); |
| 229 } | 227 } |
| 230 } else { | 228 } else { |
| 231 // Put "Forget this network" button. | 229 // Put "Forget this network" button. |
| 232 var button = this.createButton_('forget_button', | 230 var button = this.createButton_('forget_button', |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 ssid.disabled = true; | 368 ssid.disabled = true; |
| 371 pass.disabled = true; | 369 pass.disabled = true; |
| 372 chrome.send('loginToNetwork', [ssid.value, pass.value]); | 370 chrome.send('loginToNetwork', [ssid.value, pass.value]); |
| 373 }, | 371 }, |
| 374 | 372 |
| 375 /** | 373 /** |
| 376 * Creates a button for interacting with a network. | 374 * Creates a button for interacting with a network. |
| 377 * @param {Object} name The name of the localStrings to use for the text. | 375 * @param {Object} name The name of the localStrings to use for the text. |
| 378 * @param {Object} type The type of button. | 376 * @param {Object} type The type of button. |
| 379 */ | 377 */ |
| 380 createButton_: function(name, callback) { | 378 createButton_: function(name, type, callback) { |
| 381 var buttonEl = this.ownerDocument.createElement('button'); | 379 var buttonEl = this.ownerDocument.createElement('button'); |
| 380 buttonEl.buttonType = type; |
| 382 buttonEl.textContent = localStrings.getString(name); | 381 buttonEl.textContent = localStrings.getString(name); |
| 383 buttonEl.addEventListener('click', callback); | 382 buttonEl.addEventListener('click', callback); |
| 384 return buttonEl; | 383 return buttonEl; |
| 385 } | 384 } |
| 386 }; | 385 }; |
| 387 | 386 |
| 388 /** | 387 /** |
| 389 * Whether the underlying network is connected. Only used for display purpose. | 388 * Whether the underlying network is connected. Only used for display purpose. |
| 390 * @type {boolean} | 389 * @type {boolean} |
| 391 */ | 390 */ |
| 392 cr.defineProperty(NetworkItem, 'connected', cr.PropertyKind.BOOL_ATTR); | 391 cr.defineProperty(NetworkItem, 'connected', cr.PropertyKind.BOOL_ATTR); |
| 393 | 392 |
| 394 /** | 393 /** |
| 395 * Whether the underlying network is currently connecting. | 394 * Whether the underlying network is currently connecting. |
| 396 * Only used for display purpose. | 395 * Only used for display purpose. |
| 397 * @type {boolean} | 396 * @type {boolean} |
| 398 */ | 397 */ |
| 399 cr.defineProperty(NetworkItem, 'connecting', cr.PropertyKind.BOOL_ATTR); | 398 cr.defineProperty(NetworkItem, 'connecting', cr.PropertyKind.BOOL_ATTR); |
| 400 | 399 |
| 401 return { | 400 return { |
| 402 NetworkElement: NetworkElement | 401 NetworkElement: NetworkElement |
| 403 }; | 402 }; |
| 404 }); | 403 }); |
| OLD | NEW |