✨ New frontend callback "onBeforePrintStart"

Can be used to hook into and prevent the start of a print job via click
on "Start" in the print state or click on select & print in the file
list.
This commit is contained in:
Gina Häußge committed 2021-06-15 11:35:29 +02:00
1 parent cae4f1a0b7
commit b0917feba7
3 files changed
+58 -7

No files matched your search

+6
View File
@@ -225,6 +225,12 @@ onUserPermissionsChanged(user)
will be provided as only parameter. Note that this may also be triggered for not logged in guests if the guest
group is modified. In this case ``user`` will be undefined.
onBeforePrintStart(callback)
Called before a print is started either by clicking the "Print" button in the state panel or the select & print icon
in the file list. The callback to actually proceed with starting the print is provided as the only parameter. By returning
``false`` from this, plugins may prevent a print from actually starting, optionally starting it at a later date by
calling ``callback`` themselves. This can be used for example to implement an additional confirmation dialog.
onTabChange(next, current)
Called before the main tab view switches to a new tab, so `before` the new tab becomes visible. Called with the
next (changed to) and current (still visible) tab's hash (e.g. ``#control``). Note that ``current`` might be undefined
@@ -9,6 +9,8 @@ $(function () {
self.printerProfiles = parameters[4];
self.access = parameters[5];
self.allViewModels = undefined;
self.filesListVisible = ko.observable(true);
self.showInternalFilename = ko.observable(true);
@@ -629,13 +631,32 @@ $(function () {
return;
}
var proceed = function (p) {
var prevented = false;
var callback = function () {
OctoPrint.files.select(data.origin, data.path, p);
};
if (p) {
callViewModels(self.allViewModels, "onBeforePrintStart", function (
method
) {
prevented = prevented || method(callback) === false;
});
}
if (!prevented) {
callback();
}
};
if (
printAfterLoad &&
self.listHelper.isSelected(data) &&
self.enablePrint(data)
) {
// file was already selected, just start the print job
OctoPrint.job.start();
self.printerState.print();
} else {
// select file, start print job (if requested and within dimensions)
var withinPrintDimensions = self.evaluatePrintDimensions(data, true);
@@ -650,12 +671,12 @@ $(function () {
cancel: gettext("No"),
proceed: gettext("Yes"),
onproceed: function () {
OctoPrint.files.select(data.origin, data.path, print);
proceed(print);
},
nofade: true
});
} else {
OctoPrint.files.select(data.origin, data.path, print);
proceed(print);
}
}
};
@@ -1718,6 +1739,9 @@ $(function () {
self.settingsViewModel.settings.appearance.showInternalFilename()
);
};
self.onAllBound = function (allViewModels) {
self.allViewModels = allViewModels;
};
}
OCTOPRINT_VIEWMODELS.push({
@@ -6,6 +6,8 @@ $(function () {
self.settings = parameters[1];
self.access = parameters[2];
self.allViewModels = undefined;
self.stateString = ko.observable(undefined);
self.errorString = ko.observable(undefined);
self.hasErrorString = ko.pureComputed(function () {
@@ -433,8 +435,25 @@ $(function () {
}
});
} else {
var proceed = function (p) {
var prevented = false;
var callback = function () {
OctoPrint.job.start();
};
callViewModels(self.allViewModels, "onBeforePrintStart", function (
method
) {
prevented = prevented || method(callback) === false;
});
if (!prevented) {
callback();
}
};
if (!self.settings.feature_printStartConfirmation()) {
OctoPrint.job.start();
proceed();
} else {
showConfirmationDialog({
message: gettext(
@@ -443,9 +462,7 @@ $(function () {
question: gettext("Do you want to start the print job now?"),
cancel: gettext("No"),
proceed: gettext("Yes"),
onproceed: function () {
OctoPrint.job.start();
},
onproceed: proceed,
nofade: true
});
}
@@ -479,6 +496,10 @@ $(function () {
});
}
};
self.onAllBound = function (allViewModels) {
self.allViewModels = allViewModels;
};
}
OCTOPRINT_VIEWMODELS.push({