From c4ec82c9a7ab7d29d716cd4a97242af43618620e Mon Sep 17 00:00:00 2001 From: peteruithoven Date: Tue, 4 Feb 2014 15:52:37 +0100 Subject: [PATCH] Separating logic in network/status handler --- js/settings/NetworkPanel.js | 69 +++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/js/settings/NetworkPanel.js b/js/settings/NetworkPanel.js index f7b7c63..fa40311 100644 --- a/js/settings/NetworkPanel.js +++ b/js/settings/NetworkPanel.js @@ -144,42 +144,44 @@ function NetworkPanel() { } console.log("NetworkPanel:retrievedStatus status: ",data.status,data.statusMessage); - // Determine which network settings to show - switch(data.status) { - case NetworkAPI.STATUS.NOT_CONNECTED: - setNetworkMode(NETWORK_MODE.NEITHER); - break; - case NetworkAPI.STATUS.CONNECTING_FAILED: - case NetworkAPI.STATUS.CONNECTING: - case NetworkAPI.STATUS.CONNECTED: - setNetworkMode(NETWORK_MODE.CLIENT); - - if(data.status == NetworkAPI.STATUS.CONNECTED) { - _networkSelector.val(data.ssid); - + // if status changed + if(data.status != _currentNetworkStatus) { + // Determine which network mode ui to show + switch(data.status) { + case NetworkAPI.STATUS.NOT_CONNECTED: + setNetworkMode(NETWORK_MODE.NEITHER); + break; + case NetworkAPI.STATUS.CONNECTING_FAILED: + case NetworkAPI.STATUS.CONNECTING: + case NetworkAPI.STATUS.CONNECTED: + setNetworkMode(NETWORK_MODE.CLIENT); + break; + case NetworkAPI.STATUS.CREATING: + case NetworkAPI.STATUS.CREATED: + setNetworkMode(NETWORK_MODE.ACCESS_POINT); + break; + } + // update info + switch(data.status) { + case NetworkAPI.STATUS.CONNECTED: _currentNetwork = data.ssid; _currentLocalIP = data.localip; _self.selectNetwork(data.ssid); - } else { + break; + case NetworkAPI.STATUS.CONNECTING_FAILED: + case NetworkAPI.STATUS.CONNECTING: _currentLocalIP = ""; - } - break; - case NetworkAPI.STATUS.CREATING: - case NetworkAPI.STATUS.CREATED: - setNetworkMode(NETWORK_MODE.ACCESS_POINT); - - _currentNetwork = undefined; - _self.selectNetwork(NOT_CONNECTED); - _networkSelector.val(NOT_CONNECTED); - - if(data.ssid && data.status == NetworkAPI.STATUS.CREATED) { - _currentAP = data.ssid; - } - break; - } - - // update ui if status changed - if(data.status != _currentNetworkStatus) { + break; + case NetworkAPI.STATUS.CREATING: + case NetworkAPI.STATUS.CREATED: + _currentNetwork = undefined; + _self.selectNetwork(NOT_CONNECTED); + if(data.ssid && data.status == NetworkAPI.STATUS.CREATED) { + _currentAP = data.ssid; + } + break; + } + // update ui updateClientModeUI(data.status,data.statusMessage); updateAPModeUI(data.status,""); } @@ -250,15 +252,16 @@ function NetworkPanel() { case NetworkAPI.STATUS.CREATED: _btnConnect.removeAttr("disabled"); msg = "Not connected"; + _networkSelector.val(NOT_CONNECTED); break; case NetworkAPI.STATUS.CONNECTED: _btnConnect.removeAttr("disabled"); - msg = "Connected to: "+_currentNetwork+"."; if(_currentLocalIP != undefined && _currentLocalIP != "") { var a = ""+_currentLocalIP+""; msg += " (IP: "+a+")"; } + _networkSelector.val(_currentNetwork); break; case NetworkAPI.STATUS.CONNECTING: _btnConnect.attr("disabled", true);