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

Communicating networkMode to UpdatePanel

This commit is contained in:
peteruithoven 2014-02-07 12:35:15 +01:00
parent fd8520698e
commit 1dbbf0c88c
3 changed files with 25 additions and 17 deletions

View File

@ -14,12 +14,13 @@ function NetworkPanel() {
var NOT_CONNECTED = "not connected"; // used as first item in networks list
// network mode
var NETWORK_MODE = {
NetworkPanel.NETWORK_MODE = {
NEITHER: "neither",
CLIENT: "clientMode",
ACCESS_POINT: "accessPointMode"
};
var _networkMode = NETWORK_MODE.NETWORK_MODE_NEITHER;
var _networkMode = NetworkPanel.NETWORK_MODE.NEITHER;
var _networkModeChangedHandler;
var _api = new NetworkAPI();
var _networks = {};
@ -149,16 +150,16 @@ function NetworkPanel() {
// Determine which network mode ui to show
switch(data.status) {
case NetworkAPI.STATUS.NOT_CONNECTED:
setNetworkMode(NETWORK_MODE.NEITHER);
setNetworkMode(NetworkPanel.NETWORK_MODE.NEITHER);
break;
case NetworkAPI.STATUS.CONNECTING_FAILED:
case NetworkAPI.STATUS.CONNECTING:
case NetworkAPI.STATUS.CONNECTED:
setNetworkMode(NETWORK_MODE.CLIENT);
setNetworkMode(NetworkPanel.NETWORK_MODE.CLIENT);
break;
case NetworkAPI.STATUS.CREATING:
case NetworkAPI.STATUS.CREATED:
setNetworkMode(NETWORK_MODE.ACCESS_POINT);
setNetworkMode(NetworkPanel.NETWORK_MODE.ACCESS_POINT);
break;
}
// update info
@ -207,24 +208,23 @@ function NetworkPanel() {
//console.log("NetworkPanel:setNetworkMode: ",_networkMode,">",mode);
if(mode == _networkMode) return;
switch(mode) {
case NETWORK_MODE.NEITHER:
case NetworkPanel.NETWORK_MODE.NEITHER:
_apFieldSet.show();
_clientFieldSet.show();
break;
case NETWORK_MODE.CLIENT:
case NetworkPanel.NETWORK_MODE.CLIENT:
_clientRadioButton.prop('checked',true);
_apFieldSet.hide();
_clientFieldSet.show();
break;
case NETWORK_MODE.ACCESS_POINT:
case NetworkPanel.NETWORK_MODE.ACCESS_POINT:
_apRadioButton.prop('checked',true);
_apFieldSet.show();
_clientFieldSet.hide();
break;
}
// TODO
//self.updatePanel.setNetworkMode(mode);
_networkMode = mode;
if(_networkModeChangedHandler) _networkModeChangedHandler(_networkMode);
}
this.selectNetwork = function(ssid) {
@ -328,4 +328,8 @@ function NetworkPanel() {
_retrieveNetworkStatusDelay = setTimeout(function() { _self.retrieveNetworkStatus(true); }, _retrieveNetworkStatusDelayTime);
});
};
this.setNetworkModeChangedHandler = function(handler) {
_networkModeChangedHandler = handler;
}
}

View File

@ -91,7 +91,10 @@ function SettingsWindow() {
// update panel
var $updatePanelElement = self.form.find("#updatePanel");
self.updatePanel.init(wifiboxURL,$updatePanelElement);
_networkPanel.setNetworkModeChangedHandler(function(networkMode) {
var inAccessPointMode = (networkMode == NetworkPanel.NETWORK_MODE.ACCESS_POINT);
self.updatePanel.setInAccessPointMode(inAccessPointMode);
});
// printer panel
var $printerPanelElement = self.form.find("#printerPanel");
self.printerPanel.init(wifiboxURL,wifiboxCGIBinURL,$printerPanelElement);

View File

@ -23,6 +23,7 @@ function UpdatePanel() {
this.newestVersion;
this.progress;
this.imageSize;
var _inAccessPointMode;
// states from api, see Doodle3D firmware src/script/d3d-updater.lua
UpdatePanel.NONE = 1; // default state
@ -36,8 +37,6 @@ function UpdatePanel() {
this.state; // update state from api
this.stateText = ""; // update state text from api
this.networkMode; // network modes from SettingsWindow
var self = this;
this.init = function(wifiboxURL,updatePanelElement) {
@ -174,7 +173,7 @@ function UpdatePanel() {
this.setState = function(newState,refresh) {
console.log("UpdatePanel:setState");
if(!refresh && this.state == newState) return;
console.log("UpdatePanel:setState: ",this.state," > ",newState,"(",this.stateText,") (networkMode: ",self.networkMode,") (newestVersion: ",self.newestVersion,") (refresh: ",refresh,")");
console.log("UpdatePanel:setState: ",this.state," > ",newState,"(",this.stateText,") (in Access Point Mode: ",_inAccessPointMode,") (newestVersion: ",self.newestVersion,") (refresh: ",refresh,")");
this.state = newState;
// should personal sketches and settings be retained over update?
@ -239,7 +238,7 @@ function UpdatePanel() {
break;
}
} else {
if(self.networkMode == SettingsWindow.NETWORK_MODE_ACCESS_POINT) {
if(_inAccessPointMode) {
text = "Can't access internet in access point mode.";
} else {
text = "Can't access internet.";
@ -256,7 +255,9 @@ function UpdatePanel() {
}
self.infoDisplay.html(html);
}
this.setNetworkMode = function(networkMode) {
self.networkMode = networkMode;
this.setInAccessPointMode = function(inAccessPointMode) {
_inAccessPointMode = inAccessPointMode;
self.updateStatusDisplay();
}
}