added if-statements for the new variables which are grabbed from the query string (these allow us to enable/disable certain behaviors such as communicating with the wifibox, or being allowed to print)

This commit is contained in:
Adriaan Wormgoor 2013-08-16 22:25:25 +02:00
parent 70b59c923a
commit d420bde380
2 changed files with 68 additions and 58 deletions

View File

@ -154,64 +154,71 @@ function Printer() {
//console.log("Printer:checkTemperature");
var getData = { id: 0 };
var self = this;
$.ajax({
url: this.wifiboxURL + "/printer/temperature",
data: getData,
dataType: 'json',
timeout: this.timeoutTime,
success: function(data){
//console.log("Printer:temperature response: ",data);
if(data.status == "success") {
//console.log("temp: ",response.data.hotend+"/"+response.data.hotend_target+" ("+response.data.last_mod+")");
self.temperature = data.data.hotend;
if(data.data.hotend_target != undefined) {
self.targetTemperature = data.data.hotend_target;
}
self.alive = (data.data.last_mod < self.maxTempLastMod);
} else {
self.alive = false;
if (communicateWithWifibox) {
$.ajax({
url: this.wifiboxURL + "/printer/temperature",
data: getData,
dataType: 'json',
timeout: this.timeoutTime,
success: function(data){
//console.log("Printer:temperature response: ",data);
if(data.status == "success") {
//console.log("temp: ",response.data.hotend+"/"+response.data.hotend_target+" ("+response.data.last_mod+")");
self.temperature = data.data.hotend;
if(data.data.hotend_target != undefined) {
self.targetTemperature = data.data.hotend_target;
}
self.alive = (data.data.last_mod < self.maxTempLastMod);
} else {
self.alive = false;
}
//console.log(" this.alive: ",self.alive);
$(document).trigger(Printer.UPDATE);
self.checkTemperatureDelay = setTimeout(function() { self.checkTemperature() }, self.checkTemperatureInterval);
}
//console.log(" this.alive: ",self.alive);
$(document).trigger(Printer.UPDATE);
self.checkTemperatureDelay = setTimeout(function() { self.checkTemperature() },self.checkTemperatureInterval);
}
}).fail(function() {
console.log("Printer:checkTemperature: failed");
clearTimeout(self.retryCheckTemperatureDelay);
self.retryCheckTemperatureDelay = setTimeout(function() { self.checkTemperature() },self.retryDelay); // retry after delay
});
}).fail(function() {
console.log("Printer:checkTemperature: failed");
clearTimeout(self.retryCheckTemperatureDelay);
self.retryCheckTemperatureDelay = setTimeout(function() { self.checkTemperature() },self.retryDelay); // retry after delay
});
} else {
console.log ("Printer >> f:checkTemperature() >> communicateWithWifibox is false, so not executing this function");
}
}
this.checkProgress = function() {
//console.log("Printer:checkProgress");
var getData = { id: 0 };
var self = this;
$.ajax({
url: this.wifiboxURL + "/printer/progress",
data: getData,
dataType: 'json',
timeout: this.timeoutTime,
success: function(data){
if(data.status == "success") {
self.printing = data.data.printing;
self.currentLine = data.data.current_line;
self.num_lines = data.data.num_lines;
if(self.printing) {
console.log("progress: ",data.data.current_line+"/"+data.data.num_lines+" ("+data.data.last_mod+")");
}
}
//console.log(" this.alive: ",self.alive);
$(document).trigger(Printer.UPDATE);
self.checkProgressDelay = setTimeout(function() { self.checkProgress() },self.checkProgressInterval);
}
}).fail(function() {
console.log("Printer:checkProgress: failed");
clearTimeout(self.retryCheckProgressDelay);
self.retryCheckProgressDelay = setTimeout(function() { self.checkProgress() },self.retryDelay); // retry after delay
});
if (communicateWithWifibox) {
$.ajax({
url: this.wifiboxURL + "/printer/progress",
data: getData,
dataType: 'json',
timeout: this.timeoutTime,
success: function(data){
if(data.status == "success") {
self.printing = data.data.printing;
self.currentLine = data.data.current_line;
self.num_lines = data.data.num_lines;
if(self.printing) {
console.log("progress: ",data.data.current_line+"/"+data.data.num_lines+" ("+data.data.last_mod+")");
}
}
//console.log(" this.alive: ",self.alive);
$(document).trigger(Printer.UPDATE);
self.checkProgressDelay = setTimeout(function() { self.checkProgress() },self.checkProgressInterval);
}
}).fail(function() {
console.log("Printer:checkProgress: failed");
clearTimeout(self.retryCheckProgressDelay);
self.retryCheckProgressDelay = setTimeout(function() { self.checkProgress() },self.retryDelay); // retry after delay
});
} else {
console.log ("Printer >> f:checkProgress() >> communicateWithWifibox is false, so not executing this function");
}
}
}

View File

@ -36,15 +36,17 @@ function initSettingsPopup(apiURL) {
console.log("f:initSettingsPopup()");
wifiboxURL = apiURL;
loadSettings();
if (communicateWithWifibox) loadSettings();
$("#contentOverlay").hide();
$("div.content .btnOK").click(function(e) {
e.preventDefault();
e.stopPropagation();
// TODO something like a callback or feedback that saving went well / or failed
saveSettings();
if (communicateWithWifibox) saveSettings();
$("#contentOverlay").fadeOut(375, function() {
document.body.addEventListener('touchmove',prevent,false);
@ -56,9 +58,10 @@ function initSettingsPopup(apiURL) {
function showSettings() {
console.log("f:showSettings()");
if (!communicateWithWifibox) console.log(" communicateWithWifibox is false: settings aren't being loaded from wifibox...")
$("#contentOverlay").fadeIn(375, function() {
console.log("#contentOverlay faded in...");
loadSettings();
if (communicateWithWifibox) loadSettings();
document.body.removeEventListener('touchmove',prevent,false);
});
}
@ -99,7 +102,7 @@ function loadSettings() {
}
function saveSettings(callback) {
// console.log("settings form submitted");
console.log("settings form submitted");
// console.log(" printer.layerHeight:" + $("#formpje input[name='printer.layerHeight']").attr('value'));
// console.log(" first layer slow (checkbox):" + $('#firstLayerSlow').prop('checked'));
// console.log(" use sublayers (checkbox):" + $('#useSubLayers').prop('checked'));
@ -154,7 +157,7 @@ var maxScale = 1;
var shape = "%";
var twists = 0;
var useSubLayers = true;
var debug = false;
//var debug = false; // debug moved to main.js
var loglevel = 2;
var zOffset = 0;
var serverport = 8888;