0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-22 09:17: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 var NOT_CONNECTED = "not connected"; // used as first item in networks list
// network mode // network mode
var NETWORK_MODE = { NetworkPanel.NETWORK_MODE = {
NEITHER: "neither", NEITHER: "neither",
CLIENT: "clientMode", CLIENT: "clientMode",
ACCESS_POINT: "accessPointMode" ACCESS_POINT: "accessPointMode"
}; };
var _networkMode = NETWORK_MODE.NETWORK_MODE_NEITHER; var _networkMode = NetworkPanel.NETWORK_MODE.NEITHER;
var _networkModeChangedHandler;
var _api = new NetworkAPI(); var _api = new NetworkAPI();
var _networks = {}; var _networks = {};
@ -149,16 +150,16 @@ function NetworkPanel() {
// Determine which network mode ui to show // Determine which network mode ui to show
switch(data.status) { switch(data.status) {
case NetworkAPI.STATUS.NOT_CONNECTED: case NetworkAPI.STATUS.NOT_CONNECTED:
setNetworkMode(NETWORK_MODE.NEITHER); setNetworkMode(NetworkPanel.NETWORK_MODE.NEITHER);
break; break;
case NetworkAPI.STATUS.CONNECTING_FAILED: case NetworkAPI.STATUS.CONNECTING_FAILED:
case NetworkAPI.STATUS.CONNECTING: case NetworkAPI.STATUS.CONNECTING:
case NetworkAPI.STATUS.CONNECTED: case NetworkAPI.STATUS.CONNECTED:
setNetworkMode(NETWORK_MODE.CLIENT); setNetworkMode(NetworkPanel.NETWORK_MODE.CLIENT);
break; break;
case NetworkAPI.STATUS.CREATING: case NetworkAPI.STATUS.CREATING:
case NetworkAPI.STATUS.CREATED: case NetworkAPI.STATUS.CREATED:
setNetworkMode(NETWORK_MODE.ACCESS_POINT); setNetworkMode(NetworkPanel.NETWORK_MODE.ACCESS_POINT);
break; break;
} }
// update info // update info
@ -207,24 +208,23 @@ function NetworkPanel() {
//console.log("NetworkPanel:setNetworkMode: ",_networkMode,">",mode); //console.log("NetworkPanel:setNetworkMode: ",_networkMode,">",mode);
if(mode == _networkMode) return; if(mode == _networkMode) return;
switch(mode) { switch(mode) {
case NETWORK_MODE.NEITHER: case NetworkPanel.NETWORK_MODE.NEITHER:
_apFieldSet.show(); _apFieldSet.show();
_clientFieldSet.show(); _clientFieldSet.show();
break; break;
case NETWORK_MODE.CLIENT: case NetworkPanel.NETWORK_MODE.CLIENT:
_clientRadioButton.prop('checked',true); _clientRadioButton.prop('checked',true);
_apFieldSet.hide(); _apFieldSet.hide();
_clientFieldSet.show(); _clientFieldSet.show();
break; break;
case NETWORK_MODE.ACCESS_POINT: case NetworkPanel.NETWORK_MODE.ACCESS_POINT:
_apRadioButton.prop('checked',true); _apRadioButton.prop('checked',true);
_apFieldSet.show(); _apFieldSet.show();
_clientFieldSet.hide(); _clientFieldSet.hide();
break; break;
} }
// TODO
//self.updatePanel.setNetworkMode(mode);
_networkMode = mode; _networkMode = mode;
if(_networkModeChangedHandler) _networkModeChangedHandler(_networkMode);
} }
this.selectNetwork = function(ssid) { this.selectNetwork = function(ssid) {
@ -328,4 +328,8 @@ function NetworkPanel() {
_retrieveNetworkStatusDelay = setTimeout(function() { _self.retrieveNetworkStatus(true); }, _retrieveNetworkStatusDelayTime); _retrieveNetworkStatusDelay = setTimeout(function() { _self.retrieveNetworkStatus(true); }, _retrieveNetworkStatusDelayTime);
}); });
}; };
this.setNetworkModeChangedHandler = function(handler) {
_networkModeChangedHandler = handler;
}
} }

View File

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

View File

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