0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-22 01:07:56 +01:00

Separating logic in network/status handler

This commit is contained in:
peteruithoven 2014-02-04 15:52:37 +01:00
parent 556fc0dd1e
commit c4ec82c9a7

View File

@ -144,42 +144,44 @@ function NetworkPanel() {
} }
console.log("NetworkPanel:retrievedStatus status: ",data.status,data.statusMessage); console.log("NetworkPanel:retrievedStatus status: ",data.status,data.statusMessage);
// Determine which network settings to show // if status changed
switch(data.status) { if(data.status != _currentNetworkStatus) {
case NetworkAPI.STATUS.NOT_CONNECTED: // Determine which network mode ui to show
setNetworkMode(NETWORK_MODE.NEITHER); switch(data.status) {
break; case NetworkAPI.STATUS.NOT_CONNECTED:
case NetworkAPI.STATUS.CONNECTING_FAILED: setNetworkMode(NETWORK_MODE.NEITHER);
case NetworkAPI.STATUS.CONNECTING: break;
case NetworkAPI.STATUS.CONNECTED: case NetworkAPI.STATUS.CONNECTING_FAILED:
setNetworkMode(NETWORK_MODE.CLIENT); case NetworkAPI.STATUS.CONNECTING:
case NetworkAPI.STATUS.CONNECTED:
if(data.status == NetworkAPI.STATUS.CONNECTED) { setNetworkMode(NETWORK_MODE.CLIENT);
_networkSelector.val(data.ssid); 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; _currentNetwork = data.ssid;
_currentLocalIP = data.localip; _currentLocalIP = data.localip;
_self.selectNetwork(data.ssid); _self.selectNetwork(data.ssid);
} else { break;
case NetworkAPI.STATUS.CONNECTING_FAILED:
case NetworkAPI.STATUS.CONNECTING:
_currentLocalIP = ""; _currentLocalIP = "";
} break;
break; case NetworkAPI.STATUS.CREATING:
case NetworkAPI.STATUS.CREATING: case NetworkAPI.STATUS.CREATED:
case NetworkAPI.STATUS.CREATED: _currentNetwork = undefined;
setNetworkMode(NETWORK_MODE.ACCESS_POINT); _self.selectNetwork(NOT_CONNECTED);
if(data.ssid && data.status == NetworkAPI.STATUS.CREATED) {
_currentNetwork = undefined; _currentAP = data.ssid;
_self.selectNetwork(NOT_CONNECTED); }
_networkSelector.val(NOT_CONNECTED); break;
}
if(data.ssid && data.status == NetworkAPI.STATUS.CREATED) { // update ui
_currentAP = data.ssid;
}
break;
}
// update ui if status changed
if(data.status != _currentNetworkStatus) {
updateClientModeUI(data.status,data.statusMessage); updateClientModeUI(data.status,data.statusMessage);
updateAPModeUI(data.status,""); updateAPModeUI(data.status,"");
} }
@ -250,15 +252,16 @@ function NetworkPanel() {
case NetworkAPI.STATUS.CREATED: case NetworkAPI.STATUS.CREATED:
_btnConnect.removeAttr("disabled"); _btnConnect.removeAttr("disabled");
msg = "Not connected"; msg = "Not connected";
_networkSelector.val(NOT_CONNECTED);
break; break;
case NetworkAPI.STATUS.CONNECTED: case NetworkAPI.STATUS.CONNECTED:
_btnConnect.removeAttr("disabled"); _btnConnect.removeAttr("disabled");
msg = "Connected to: <b>"+_currentNetwork+"</b>."; msg = "Connected to: <b>"+_currentNetwork+"</b>.";
if(_currentLocalIP != undefined && _currentLocalIP != "") { if(_currentLocalIP != undefined && _currentLocalIP != "") {
var a = "<a href='http://"+_currentLocalIP+"' target='_black'>"+_currentLocalIP+"</a>"; var a = "<a href='http://"+_currentLocalIP+"' target='_black'>"+_currentLocalIP+"</a>";
msg += " (IP: "+a+")"; msg += " (IP: "+a+")";
} }
_networkSelector.val(_currentNetwork);
break; break;
case NetworkAPI.STATUS.CONNECTING: case NetworkAPI.STATUS.CONNECTING:
_btnConnect.attr("disabled", true); _btnConnect.attr("disabled", true);