diff --git a/js_src/SettingsWindow.js b/js_src/SettingsWindow.js
index 9eb7191..9c56c0c 100644
--- a/js_src/SettingsWindow.js
+++ b/js_src/SettingsWindow.js
@@ -26,6 +26,11 @@ var settings = {
}
+//wrapper to prevent scoping issues in showSettings()
+function openSettingsWindow() {
+ settingsWindow.showSettings();
+}
+
function SettingsWindow() {
this.wifiboxURL;
this.wifiboxCGIBinURL
@@ -34,7 +39,7 @@ function SettingsWindow() {
this.timeoutTime = 3000;
this.retryDelay = 2000; // retry setTimout delay
this.retryRetrieveNetworkStatusDelayTime = 1000;// retry setTimout delay
-
+
this.retryLoadSettingsDelay; // retry setTimout instance
this.retrySaveSettingsDelay; // retry setTimout instance
this.retryRetrieveNetworkStatusDelay;// retry setTimout instance
@@ -45,11 +50,11 @@ function SettingsWindow() {
this.networks;
this.currentNetwork; // the ssid of the network the box is on
this.selectedNetwork; // the ssid of the selected network in the client mode settings
- this.currentLocalIP = "";
+ this.currentLocalIP = "";
this.clientModeState = SettingsWindow.NOT_CONNECTED;
this.currentAP;
this.apModeState = SettingsWindow.NO_AP;
-
+
// after switching wifi network or creating a access point we delay the status retrieval
// because the webserver needs time to switch
this.retrieveNetworkStatusDelay; // setTimout delay
@@ -63,28 +68,28 @@ function SettingsWindow() {
SettingsWindow.CONNECTED = "connected";
SettingsWindow.CONNECTING = "connecting";
SettingsWindow.CONNECTING_FAILED = "connecting failed"
-
+
// network access point mode states
SettingsWindow.NO_AP = "no ap";
SettingsWindow.AP = "ap";
SettingsWindow.CREATING_AP = "creating ap";
-
+
SettingsWindow.API_CONNECTING_FAILED = -1
SettingsWindow.API_NOT_CONNECTED = 0
SettingsWindow.API_CONNECTING = 1
SettingsWindow.API_CONNECTED = 2
- SettingsWindow.API_CREATING = 3
- SettingsWindow.API_CREATED = 4
-
+ SettingsWindow.API_CREATING = 3
+ SettingsWindow.API_CREATED = 4
+
// network mode
SettingsWindow.NETWORK_MODE_NEITHER = "neither";
SettingsWindow.NETWORK_MODE_CLIENT = "clientMode";
SettingsWindow.NETWORK_MODE_ACCESS_POINT = "accessPointMode";
-
+
this.networkMode = SettingsWindow.NETWORK_MODE_NEITHER;
-
+
this.updatePanel = new UpdatePanel();
-
+
var self = this;
this.init = function(wifiboxURL,wifiboxCGIBinURL) {
@@ -100,7 +105,7 @@ function SettingsWindow() {
self.form.submit(function (e) { self.submitwindow(e) });
self.loadSettings();
-
+
var btnAP = self.form.find("label[for='ap']");
var btnClient = self.form.find("label[for='client']");
var btnRefresh = self.form.find("#refreshNetworks");
@@ -116,7 +121,7 @@ function SettingsWindow() {
btnConnect.on('touchstart mousedown',self.connectToNetwork);
btnCreate.on('touchstart mousedown',self.createAP);
networkSelector.change(self.networkSelectorChanged);
-
+
// update panel
var $updatePanelElement = self.form.find("#updatePanel");
self.updatePanel.init(wifiboxURL,$updatePanelElement);
@@ -128,7 +133,7 @@ function SettingsWindow() {
self.saveSettings(self.readForm(),function(){
self.hideSettings();
});
-
+
clearTimeout(self.retryRetrieveNetworkStatusDelay);
}
@@ -256,7 +261,7 @@ function SettingsWindow() {
$(element).removeClass("error");
});
}
-
+
this.readForm = function() {
//console.log("SettingsWindow:readForm");
var settings = {};
@@ -341,7 +346,7 @@ function SettingsWindow() {
}
}
}).fail(function() {
-
+
});
}
}
@@ -357,22 +362,22 @@ function SettingsWindow() {
success: function(response){
console.log("Settings:retrieveNetworkStatus response: ",response);
if(response.status == "error") {
-
+
} else {
var data = response.data;
-
+
if(typeof data.status === 'string') {
data.status = parseInt(data.status);
}
//console.log(" data.status: ",data.status,data.statusMessage);
-
+
// Determine which network settings to show
switch(data.status) {
case SettingsWindow.API_NOT_CONNECTED:
//console.log(" not connected & not a access point");
self.apFieldSet.show();
self.clientFieldSet.show();
-
+
self.networkMode = SettingsWindow.NETWORK_MODE_NEITHER;
break;
case SettingsWindow.API_CONNECTING_FAILED:
@@ -380,14 +385,14 @@ function SettingsWindow() {
case SettingsWindow.API_CONNECTED:
//console.log(" client mode");
self.form.find("#client").prop('checked',true);
-
+
self.apFieldSet.hide();
self.clientFieldSet.show();
-
+
if(data.status == SettingsWindow.API_CONNECTED) {
var networkSelector = self.form.find("#network");
networkSelector.val(data.ssid);
-
+
self.currentNetwork = data.ssid;
self.currentLocalIP = data.localip;
self.selectNetwork(data.ssid);
@@ -400,31 +405,31 @@ function SettingsWindow() {
case SettingsWindow.API_CREATED:
//console.log(" access point mode");
self.form.find("#ap").prop('checked',true);
-
+
self.apFieldSet.show();
self.clientFieldSet.hide();
-
+
self.currentNetwork = undefined;
self.selectNetwork(SettingsWindow.NOT_CONNECTED);
var networkSelector = self.form.find("#network");
networkSelector.val(SettingsWindow.NOT_CONNECTED);
-
- if(data.ssid && data.status == SettingsWindow.API_CREATED) {
+
+ if(data.ssid && data.status == SettingsWindow.API_CREATED) {
self.currentAP = data.ssid;
}
self.networkMode = SettingsWindow.NETWORK_MODE_ACCESS_POINT;
break;
}
self.updatePanel.setNetworkMode(self.networkMode);
-
+
// update status message
switch(data.status) {
case SettingsWindow.API_CONNECTING_FAILED:
- self.setClientModeState(SettingsWindow.CONNECTING_FAILED,data.statusMessage);
+ self.setClientModeState(SettingsWindow.CONNECTING_FAILED,data.statusMessage);
self.setAPModeState(SettingsWindow.NO_AP,"");
break;
- case SettingsWindow.API_NOT_CONNECTED:
- self.setClientModeState(SettingsWindow.NOT_CONNECTED,"");
+ case SettingsWindow.API_NOT_CONNECTED:
+ self.setClientModeState(SettingsWindow.NOT_CONNECTED,"");
self.setAPModeState(SettingsWindow.NO_AP,"");
break;
case SettingsWindow.API_CONNECTING:
@@ -436,15 +441,15 @@ function SettingsWindow() {
self.setAPModeState(SettingsWindow.NO_AP,"");
break;
case SettingsWindow.API_CREATING:
- self.setClientModeState(SettingsWindow.NOT_CONNECTED,"");
+ self.setClientModeState(SettingsWindow.NOT_CONNECTED,"");
self.setAPModeState(SettingsWindow.CREATING_AP,"");
break;
case SettingsWindow.API_CREATED:
- self.setClientModeState(SettingsWindow.NOT_CONNECTED,"");
+ self.setClientModeState(SettingsWindow.NOT_CONNECTED,"");
self.setAPModeState(SettingsWindow.AP,"");
break;
}
-
+
// Keep checking for updates?
if(connecting) {
switch(data.status) {
@@ -495,7 +500,7 @@ function SettingsWindow() {
this.form.find("#passwordLabel").hide();
this.form.find("#password").hide();
}
-
+
this.setClientModeState = function(state,msg) {
var field = this.form.find("#clientModeState");
var btnConnect = self.form.find("#connectToNetwork");
@@ -506,7 +511,7 @@ function SettingsWindow() {
break;
case SettingsWindow.CONNECTED:
btnConnect.removeAttr("disabled");
-
+
var fieldText = "Connected to: "+this.currentNetwork+".";
if(this.currentLocalIP != undefined && this.currentLocalIP != "") {
var a = ""+this.currentLocalIP+"";
@@ -520,7 +525,7 @@ function SettingsWindow() {
break;
case SettingsWindow.CONNECTING_FAILED:
btnConnect.removeAttr("disabled");
- field.html(msg);
+ field.html(msg);
break;
}
this.clientModeState = state;
@@ -555,10 +560,10 @@ function SettingsWindow() {
}
console.log(" postData: ",postData);
if (communicateWithWifibox) {
-
+
// save network related settings and on complete, connect to network
self.saveSettings(self.readForm(),function() {
-
+
$.ajax({
url: self.wifiboxCGIBinURL + "/network/associate",
type: "POST",
@@ -576,7 +581,7 @@ function SettingsWindow() {
});
}
self.setClientModeState(SettingsWindow.CONNECTING,"");
-
+
// after switching wifi network or creating a access point we delay the status retrieval
// because the webserver needs time to switch
clearTimeout(self.retrieveNetworkStatusDelay);
@@ -586,7 +591,7 @@ function SettingsWindow() {
this.createAP = function() {
console.log("createAP");
if (communicateWithWifibox) {
-
+
// save network related settings and on complete, create access point
self.saveSettings(self.readForm(),function() {
self.setAPModeState(SettingsWindow.CREATING_AP); // get latest substituted ssid
@@ -603,7 +608,7 @@ function SettingsWindow() {
//clearTimeout(self.retrySaveSettingsDelay);
//self.retrySaveSettingsDelay = setTimeout(function() { self.saveSettings() },self.retryDelay); // retry after delay
});
-
+
self.setAPModeState(SettingsWindow.CREATING_AP,"");
// after switching wifi network or creating a access point we delay the status retrieval
diff --git a/js_src/buttonbehaviors.js b/js_src/buttonbehaviors.js
index 8b8d01a..7ce03c4 100644
--- a/js_src/buttonbehaviors.js
+++ b/js_src/buttonbehaviors.js
@@ -160,11 +160,8 @@ function initButtonBehavior() {
loadSettings();
});
}*/
- btnSettings.bind('touchstart mousedown',function () {
- //e.preventDefault();
- //console.log("btnSettings clicked");
- settingsWindow.showSettings();
- });
+ enableButton(btnSettings, openSettingsWindow);
+
// btnSettings.on('touchend', function(e) {
// e.preventDefault();
// console.log("btnSettings touchend");
@@ -214,14 +211,14 @@ function print(e) {
//setState(Printer.BUFFERING_STATE,printer.hasControl);
printer.overruleState(Printer.BUFFERING_STATE);
-
+
btnStop.css("display","none"); // hack
-
- // we put the gcode generation in a little delay
+
+ // we put the gcode generation in a little delay
// so that for example the print button is disabled right away
clearTimeout(gcodeGenerateDelayer);
- gcodeGenerateDelayer = setTimeout(function() {
-
+ gcodeGenerateDelayer = setTimeout(function() {
+
var gcode = generate_gcode();
if (sendPrintCommands) {
if(gcode.length > 0) {
@@ -238,7 +235,7 @@ function print(e) {
$("#textdump").text("");
$("#textdump").text(gcode.join("\n"));
}
-
+
}, gcodeGenerateDelay);
} else {
console.log("f:print >> not enough points!");
@@ -318,11 +315,11 @@ function update() {
progressbar.update(printer.currentLine, printer.totalLines);
}
-function setState(newState,newHasControl) {
+function setState(newState,newHasControl) {
if(newState == state && newHasControl == hasControl) return;
prevState = state;
-
+
console.log("setState: ",prevState," > ",newState," ( ",newHasControl,")");
setDebugText("State: "+newState);
@@ -350,38 +347,60 @@ function setState(newState,newHasControl) {
// thermometer
switch(newState) {
- case Printer.IDLE_STATE:
- case Printer.BUFFERING_STATE:
- case Printer.PRINTING_STATE:
+ case Printer.IDLE_STATE: /* fall-through */
+ case Printer.BUFFERING_STATE: /* fall-through */
+ case Printer.PRINTING_STATE: /* fall-through */
case Printer.STOPPING_STATE:
- thermometer.show();
+ thermometer.show();
break;
default:
- thermometer.hide();
+ thermometer.hide();
break;
}
// progress indicator
switch(newState) {
case Printer.PRINTING_STATE:
- progressbar.show();
+ progressbar.show();
break;
default:
progressbar.hide();
break;
}
-
+
+ /* settings button */
+ switch(newState) {
+ case Printer.IDLE_STATE:
+ enableButton(btnSettings, openSettingsWindow);
+ break;
+ case Printer.WIFIBOX_DISCONNECTED_STATE: /* fall-through */
+ case Printer.BUFFERING_STATE: /* fall-through */
+ case Printer.PRINTING_STATE: /* fall-through */
+ case Printer.STOPPING_STATE:
+ disableButton(btnSettings);
+ break;
+ default:
+ enableButton(btnSettings, openSettingsWindow);
+ break;
+}
+
if(newState == Printer.WIFIBOX_DISCONNECTED_STATE) {
message.set("Lost connection to WiFi box",Message.ERROR);
} else if(prevState == Printer.WIFIBOX_DISCONNECTED_STATE) {
message.set("Connected to WiFi box",Message.INFO,true);
} else if(newState == Printer.DISCONNECTED_STATE) {
message.set("Printer disconnected",Message.WARNING,true);
- } else if(prevState == Printer.DISCONNECTED_STATE && newState == Printer.IDLE_STATE ||
+ } else if(prevState == Printer.DISCONNECTED_STATE && newState == Printer.IDLE_STATE ||
prevState == Printer.UNKNOWN_STATE && newState == Printer.IDLE_STATE) {
message.set("Printer connected",Message.INFO,true);
+ } else if(prevState == Printer.PRINTING_STATE && newState == Printer.STOPPING_STATE) {
+ console.log("stopmsg show");
+ message.set("Printer stopping",Message.INFO,false);
+ } else if(prevState == Printer.STOPPING_STATE && newState == Printer.IDLE_STATE) {
+ console.log("stopmsg hide");
+ message.hide();
}
-
+
state = newState;
hasControl = newHasControl;
}
diff --git a/js_src/main.js b/js_src/main.js
index e28694f..adc2a89 100644
--- a/js_src/main.js
+++ b/js_src/main.js
@@ -107,6 +107,19 @@ $(function() {
}
});
+function enableButton(elem, handler) {
+ //var elem = $('#'+domId);
+ elem.removeClass("disabled");
+ elem.unbind('touchstart mousedown');
+ elem.bind('touchstart mousedown', handler);
+}
+
+function disableButton(elem) {
+ //var elem = $('#'+domId);
+ elem.addClass("disabled");
+ elem.unbind('touchstart mousedown');
+}
+
function showOrHideThermo() {
console.log("f:showOrHideThermo()");
if (showOrHide) {