2018-01-24 19:15:48 +03:00
|
|
|
$(function() {
|
2018-08-09 03:16:07 +03:00
|
|
|
$('#klipper-settings a:first').tab('show');
|
2018-01-24 19:15:48 +03:00
|
|
|
function KlipperSettingsViewModel(parameters) {
|
|
|
|
var self = this;
|
|
|
|
self.settings = parameters[0];
|
2018-08-09 03:16:07 +03:00
|
|
|
self.klipperConfig = ko.observable();
|
2018-01-24 19:15:48 +03:00
|
|
|
|
|
|
|
self.addMacro = function() {
|
2018-01-25 01:07:55 +03:00
|
|
|
self.settings.settings.plugins.klipper.macros.push({
|
|
|
|
name: 'Macro',
|
|
|
|
macro: '',
|
|
|
|
sidebar: true,
|
|
|
|
tab: true
|
|
|
|
});
|
2018-01-24 19:15:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
self.removeMacro = function(macro) {
|
|
|
|
self.settings.settings.plugins.klipper.macros.remove(macro);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.moveMacroUp = function(macro) {
|
|
|
|
self.moveItemUp(self.settings.settings.plugins.klipper.macros, macro)
|
|
|
|
}
|
|
|
|
|
|
|
|
self.moveMacroDown = function(macro) {
|
|
|
|
self.moveItemDown(self.settings.settings.plugins.klipper.macros, macro)
|
|
|
|
}
|
|
|
|
|
|
|
|
self.addProbePoint = function() {
|
|
|
|
self.settings.settings.plugins.klipper.probePoints.push({x: 0, y:0, z:0});
|
|
|
|
}
|
|
|
|
|
|
|
|
self.removeProbePoint = function(point) {
|
|
|
|
self.settings.settings.plugins.klipper.probePoints.remove(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.moveProbePointUp = function(macro) {
|
|
|
|
self.moveItemUp(self.settings.settings.plugins.klipper.probePoints, macro)
|
|
|
|
}
|
|
|
|
|
|
|
|
self.moveProbePointDown = function(macro) {
|
|
|
|
self.moveItemDown(self.settings.settings.plugins.klipper.probePoints, macro)
|
|
|
|
}
|
|
|
|
|
|
|
|
self.moveItemDown = function(list, item) {
|
|
|
|
var i = list().indexOf(item);
|
|
|
|
if (i < list().length - 1) {
|
|
|
|
var rawList = list();
|
|
|
|
list.splice(i, 2, rawList[i + 1], rawList[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.moveItemUp = function(list, item) {
|
|
|
|
var i = list().indexOf(item);
|
|
|
|
if (i > 0) {
|
|
|
|
var rawList = list();
|
|
|
|
list.splice(i-1, 2, rawList[i], rawList[i-1]);
|
|
|
|
}
|
|
|
|
}
|
2018-08-09 03:16:07 +03:00
|
|
|
|
|
|
|
self.loadKlipperConfig = function() {
|
|
|
|
$.ajax({
|
|
|
|
method: "GET",
|
|
|
|
url: "/api/plugin/klipper",
|
|
|
|
headers: {'X-Api-Key': '2CE2F6BA87244897B7F3A1BED3B1A3ED'}
|
|
|
|
})
|
|
|
|
.done(function( msg ) {
|
|
|
|
self.klipperConfig(msg)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
self.saveKlipperConfig = function() {
|
|
|
|
$.ajax({
|
|
|
|
method: "POST",
|
|
|
|
url: "/api/plugin/klipper",
|
|
|
|
headers: {
|
|
|
|
"x-api-key": "2CE2F6BA87244897B7F3A1BED3B1A3ED",
|
|
|
|
"content-type": "application/json",
|
|
|
|
"cache-control": "no-cache"
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
command: "save_config",
|
|
|
|
text: encodeURI(self.klipperConfig)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.done(function( msg ) {
|
|
|
|
console.log(msg);
|
|
|
|
});
|
|
|
|
}
|
2018-01-24 19:15:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
OCTOPRINT_VIEWMODELS.push({
|
|
|
|
construct: KlipperSettingsViewModel,
|
|
|
|
dependencies: ["settingsViewModel"],
|
|
|
|
elements: ["#settings_plugin_klipper"]
|
|
|
|
});
|
|
|
|
});
|