Files
OctoPrint-CalibrationTools/octoprint_CalibrationTools/static/js/GeneralViewModel.js
T
sergiuToporjinschi d294fa5724 -refactoring js files,
-implementing 3 decimal observer
-reusing load steps and save steps event
-adding settings for xyzSteps
-subsection macro default spacing = true
2022-02-05 13:44:49 +02:00

37 lines
1.5 KiB
JavaScript

$(function () {
function CalibrationToolsGeneralViewModel(parameters) {
this.loginState = parameters[0];
this.decimal3 = function (defaultVal) {
return {
numeric: {
decimals: 3,
default: defaultVal
}
}
}
ko.extenders.numeric = function (target, options) {
var returnObs = ko.pureComputed({
read: target,
write: function (value) {
var newVal = options.decimals ? parseFloat(value).toFixed(options.decimals) : parseInt(value);
target(isNaN(newVal) ? options.default : newVal);
}
}).extend({
notify: 'always'
});
returnObs(target());
return returnObs;
};
}
// OCTOPRINT_VIEWMODELS.push([GeneralViewModel, ["loginStateViewModel"], []]);
OCTOPRINT_VIEWMODELS.push({
// This is the constructor to call for instantiating the plugin
construct: CalibrationToolsGeneralViewModel,
name: "calibrationToolsGeneralViewModel",
// This is a list of dependencies to inject into the plugin, the order which you request
// here is the order in which the dependencies will be injected into your view model upon
// instantiation via the parameters argument
dependencies: ["loginStateViewModel"]
// Finally, this is the list of selectors for all elements we want this view model to be bound to.
});
});