From 12ee1d2b5c7c6599deacc05613522b0045d453f1 Mon Sep 17 00:00:00 2001 From: Alive Kuo Date: Fri, 28 Dec 2012 02:38:00 +0800 Subject: [PATCH] Bug 824457 - Make FTU Wifi usable, r=evelyn, a=blocking-basecamp --- apps/communications/ftu/js/ui.js | 13 ++++++++++--- apps/communications/ftu/js/wifi.js | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/apps/communications/ftu/js/ui.js b/apps/communications/ftu/js/ui.js index 526f311d7385..eca8b12c056f 100644 --- a/apps/communications/ftu/js/ui.js +++ b/apps/communications/ftu/js/ui.js @@ -323,7 +323,7 @@ var UIManager = { li.dataset.ssid = network.ssid; // Show authentication method var keys = network.capabilities; - if (network.connected) { + if (WifiManager.isConnectedTo(network)) { small.textContent = _('shortStatus-connected'); } else { if (keys && keys.length) { @@ -340,7 +340,11 @@ var UIManager = { li.appendChild(ssidp); li.appendChild(small); // Append to DOM - networksDOM.appendChild(li); + if (WifiManager.isConnectedTo(network)) { + networksDOM.insertBefore(li, networksDOM.firstChild); + } else { + networksDOM.appendChild(li); + } } } }, @@ -352,8 +356,11 @@ var UIManager = { }, updateNetworkStatus: function uim_uns(ssid, status) { + if (!document.getElementById(ssid)) + return; + document.getElementById(ssid). - querySelector('p:last-child').innerHTML = status; + querySelector('p:last-child').innerHTML = _('shortStatus-' + status); }, updateDataConnectionStatus: function uim_udcs(status) { diff --git a/apps/communications/ftu/js/wifi.js b/apps/communications/ftu/js/wifi.js index e77ec7d30d9a..b59d0e8f3cb6 100644 --- a/apps/communications/ftu/js/wifi.js +++ b/apps/communications/ftu/js/wifi.js @@ -9,6 +9,21 @@ var WifiManager = { this.gCurrentNetwork = this.api.connection.network; } }, + isConnectedTo: function wn_isConnectedTo(network) { + /** + * XXX the API should expose a 'connected' property on 'network', + * and 'gWifiManager.connection.network' should be comparable to 'network'. + * Until this is properly implemented, we just compare SSIDs and capabilities + * to tell wether the network is already connected or not. + */ + var currentNetwork = this.api.connection.network; + if (!currentNetwork || this.api.connection.status != 'connected') + return false; + var key = network.ssid + '+' + network.capabilities.join('+'); + var curkey = currentNetwork.ssid + '+' + + currentNetwork.capabilities.join('+'); + return (key == curkey); + }, scan: function wn_scan(callback) { if ('mozWifiManager' in window.navigator) { var req = WifiManager.api.getNetworks(); @@ -84,6 +99,7 @@ var WifiManager = { } } else { // Connect directly + this.gCurrentNetwork = network; this.api.associate(network); return; } @@ -113,6 +129,9 @@ var WifiManager = { UIManager.updateNetworkStatus(self.ssid, event.status); if (event.status == 'connected') { self.isConnected = true; + if (self.networks && self.networks.length) { + UIManager.renderNetworks(self.networks); + } } else { self.isConnected = false; }