0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-11 05:33:23 +01:00
doodle3d-client/js/api/ConfigAPI.js

96 lines
2.9 KiB
JavaScript
Raw Normal View History

/*
* This file is part of the Doodle3D project (http://doodle3d.com).
*
* Copyright (c) 2013, Doodle3D
* This software is licensed under the terms of the GNU GPL v2 or later.
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
*/
function ConfigAPI() {
2015-04-27 23:38:01 +02:00
var className = 'ConfigAPI';
function init() {
console.log(className,'init is deprecated');
}
function loadAll(success,fail) {
2015-06-02 14:38:55 +02:00
API.get('config/all',{},success,fail);
};
2015-06-02 14:38:55 +02:00
function load(dataObject,success,fail) {
// console.log(className,'load',dataObject);
API.get('config', dataObject, function(res) {
console.log(className,'load get config cb',dataObject,res);
if (success) success(res);
},fail);
2014-02-04 22:56:58 +01:00
};
function save(newSettings,success,fail) {
console.log(className,'save',newSettings);
API.post('config',newSettings,success,fail);
};
function resetAll(success,fail) {
API.post('config/resetall',{},success,fail)
};
function getSetting(key,success,fail) {
2015-06-02 14:38:55 +02:00
console.log(className,'getSetting',key);
API.get('config/?'+key+'=',{},function(response) {
if (success) success(response[key]);
},fail);
}
function getStartCode(success,fail) {
loadAll(function(data) {
var startcode = subsituteVariables(data['printer.startcode'],data);
if (success) success(startcode);
},fail);
}
function getEndCode(success,fail) {
loadAll(function(data) {
var endcode = subsituteVariables(data['printer.endcode'],data);
if (success) success(endcode);
},fail);
}
function subsituteVariables(gcode,settings) {
//,temperature,bedTemperature,preheatTemperature,preheatBedTemperature
var temperature = settings["printer.temperature"];
var bedTemperature = settings["printer.bed.temperature"];
var preheatTemperature = settings["printer.heatup.temperature"];
var preheatBedTemperature = settings["printer.heatup.bed.temperature"];
var printerType = settings["printer.type"];
var heatedbed = settings["printer.heatedbed"];
switch (printerType) {
case "makerbot_replicator2": printerType = "r2"; break;
case "makerbot_replicator2x": printerType = "r2x"; break;
case "makerbot_thingomatic": printerType = "t6"; break;
case "makerbot_generic": printerType = "r2"; break;
case "_3Dison_plus": printerType = "r2"; break;
}
var heatedBedReplacement = (heatedbed)? "" : ";";
gcode = gcode.replace(/{printingTemp}/gi ,temperature);
gcode = gcode.replace(/{printingBedTemp}/gi ,bedTemperature);
gcode = gcode.replace(/{preheatTemp}/gi ,preheatTemperature);
gcode = gcode.replace(/{preheatBedTemp}/gi ,preheatBedTemperature);
gcode = gcode.replace(/{printerType}/gi ,printerType);
gcode = gcode.replace(/{if heatedBed}/gi ,heatedBedReplacement);
return gcode;
}
return {
2015-04-27 23:38:01 +02:00
init: init,
loadAll: loadAll,
load: load,
save: save,
resetAll: resetAll,
getSetting: getSetting,
getStartCode: getStartCode,
getEndCode: getEndCode,
}
}