0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-05 03:33:23 +01:00
doodle3d-client/js/PrinterPanel.js
2014-01-09 18:10:54 +01:00

76 lines
2.2 KiB
JavaScript

function PrinterPanel() {
this.wifiboxURL;
this.element;
this.retryDelay = 1000;
this.retryDelayer; // setTimout instance
//this.timeoutTime = 3000;
this.printerType;
this.printerSettingsNames;
var self = this;
this.init = function(wifiboxURL,element) {
self.wifiboxURL = wifiboxURL;
self.element = element;
self.printerSelector = element.find("#printerType");
self.printerSelector.change(self.printerSelectorChanged);
var formElements = element.find("[name]");
self.printerSettingsNames = [];
formElements.each( function(index,element) {
self.printerSettingsNames.push(element.name);
});
var gcodePanel = element.find("#gcodePanel");
gcodePanel.coolfieldset({collapsed:true});
}
this.printerSelectorChanged = function(e) {
console.log("PrinterPanel:printerSelectorChanged");
console.log("self: ", self);
self.printerType = self.printerSelector.find("option:selected").val();
self.savePrinterType(self.loadPrinterSettings);
}
this.savePrinterType = function(complete) {
console.log("PrinterPanel:savePrinterType");
var postData = {};
postData[self.printerSelector.attr("name")] = self.printerType;
console.log("postData: ",postData);
$.ajax({
url: self.wifiboxURL + "/config/",
type: "POST",
dataType: 'json',
data: postData,
success: function(response){
console.log("PrinterPanel:savePrinterType response: ",response);
if(complete) complete();
}
}).fail(function() {
console.log("PrinterPanel:savePrinterType: failed");
});
}
this.loadPrinterSettings = function() {
console.log("PrinterPanel:loadPrinterSettings");
console.log(" self.printerSettingsNames: ",self.printerSettingsNames);
var getData = {};
$.each(self.printerSettingsNames, function(key, val) {
getData[val] = "";
});
console.log("getData: ",getData);
$.ajax({
url: self.wifiboxURL + "/config/",
dataType: 'json',
data: getData,
success: function(response){
console.log("PrinterPanel:loadPrinterSettings response: ",response);
self.fillForm(response.data,self.element);
}
}).fail(function() {
console.log("PrinterPanel:loadPrinterSettings: failed");
});
}
}