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"); //console.log("Printer:checkTemperature");
var getData = { id: 0 }; var getData = { id: 0 };
var self = this; var self = this;
$.ajax({ if (communicateWithWifibox) {
url: this.wifiboxURL + "/printer/temperature", $.ajax({
data: getData, url: this.wifiboxURL + "/printer/temperature",
dataType: 'json', data: getData,
timeout: this.timeoutTime, dataType: 'json',
success: function(data){ timeout: this.timeoutTime,
//console.log("Printer:temperature response: ",data); success: function(data){
if(data.status == "success") { //console.log("Printer:temperature response: ",data);
//console.log("temp: ",response.data.hotend+"/"+response.data.hotend_target+" ("+response.data.last_mod+")"); if(data.status == "success") {
self.temperature = data.data.hotend; //console.log("temp: ",response.data.hotend+"/"+response.data.hotend_target+" ("+response.data.last_mod+")");
if(data.data.hotend_target != undefined) { self.temperature = data.data.hotend;
self.targetTemperature = data.data.hotend_target; if(data.data.hotend_target != undefined) {
} self.targetTemperature = data.data.hotend_target;
self.alive = (data.data.last_mod < self.maxTempLastMod); }
} else { self.alive = (data.data.last_mod < self.maxTempLastMod);
self.alive = false; } 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); }).fail(function() {
$(document).trigger(Printer.UPDATE); console.log("Printer:checkTemperature: failed");
clearTimeout(self.retryCheckTemperatureDelay);
self.checkTemperatureDelay = setTimeout(function() { self.checkTemperature() },self.checkTemperatureInterval); self.retryCheckTemperatureDelay = setTimeout(function() { self.checkTemperature() },self.retryDelay); // retry after delay
} });
}).fail(function() { } else {
console.log("Printer:checkTemperature: failed"); console.log ("Printer >> f:checkTemperature() >> communicateWithWifibox is false, so not executing this function");
clearTimeout(self.retryCheckTemperatureDelay); }
self.retryCheckTemperatureDelay = setTimeout(function() { self.checkTemperature() },self.retryDelay); // retry after delay
});
} }
this.checkProgress = function() { this.checkProgress = function() {
//console.log("Printer:checkProgress"); //console.log("Printer:checkProgress");
var getData = { id: 0 }; var getData = { id: 0 };
var self = this; var self = this;
$.ajax({ if (communicateWithWifibox) {
url: this.wifiboxURL + "/printer/progress", $.ajax({
data: getData, url: this.wifiboxURL + "/printer/progress",
dataType: 'json', data: getData,
timeout: this.timeoutTime, dataType: 'json',
success: function(data){ timeout: this.timeoutTime,
if(data.status == "success") { 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
});
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()"); console.log("f:initSettingsPopup()");
wifiboxURL = apiURL; wifiboxURL = apiURL;
loadSettings(); if (communicateWithWifibox) loadSettings();
$("#contentOverlay").hide(); $("#contentOverlay").hide();
$("div.content .btnOK").click(function(e) { $("div.content .btnOK").click(function(e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
// TODO something like a callback or feedback that saving went well / or failed // TODO something like a callback or feedback that saving went well / or failed
saveSettings();
if (communicateWithWifibox) saveSettings();
$("#contentOverlay").fadeOut(375, function() { $("#contentOverlay").fadeOut(375, function() {
document.body.addEventListener('touchmove',prevent,false); document.body.addEventListener('touchmove',prevent,false);
@ -56,9 +58,10 @@ function initSettingsPopup(apiURL) {
function showSettings() { function showSettings() {
console.log("f:showSettings()"); console.log("f:showSettings()");
if (!communicateWithWifibox) console.log(" communicateWithWifibox is false: settings aren't being loaded from wifibox...")
$("#contentOverlay").fadeIn(375, function() { $("#contentOverlay").fadeIn(375, function() {
console.log("#contentOverlay faded in..."); console.log("#contentOverlay faded in...");
loadSettings(); if (communicateWithWifibox) loadSettings();
document.body.removeEventListener('touchmove',prevent,false); document.body.removeEventListener('touchmove',prevent,false);
}); });
} }
@ -99,7 +102,7 @@ function loadSettings() {
} }
function saveSettings(callback) { 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(" printer.layerHeight:" + $("#formpje input[name='printer.layerHeight']").attr('value'));
// console.log(" first layer slow (checkbox):" + $('#firstLayerSlow').prop('checked')); // console.log(" first layer slow (checkbox):" + $('#firstLayerSlow').prop('checked'));
// console.log(" use sublayers (checkbox):" + $('#useSubLayers').prop('checked')); // console.log(" use sublayers (checkbox):" + $('#useSubLayers').prop('checked'));
@ -154,7 +157,7 @@ var maxScale = 1;
var shape = "%"; var shape = "%";
var twists = 0; var twists = 0;
var useSubLayers = true; var useSubLayers = true;
var debug = false; //var debug = false; // debug moved to main.js
var loglevel = 2; var loglevel = 2;
var zOffset = 0; var zOffset = 0;
var serverport = 8888; var serverport = 8888;