diff --git a/docs/plugins/viewmodels.rst b/docs/plugins/viewmodels.rst index dc8d9cace..91759647f 100644 --- a/docs/plugins/viewmodels.rst +++ b/docs/plugins/viewmodels.rst @@ -259,6 +259,10 @@ onUserSettingsShown() onUserSettingsHidden() Called when the user settings dialog is hidden. +onUserSettingsBeforeSave() + Called just before the user settings view model is sent to the server. This is useful, for example, if your plugin + needs to compute persisted settings from a custom view model. + onWizardDetails(response) Called with the response from the wizard detail API call initiated before opening the wizard dialog. Will contain the data from all :class:`~octoprint.plugin.WizardPlugin` implementations returned by their :meth:`~octoprint.plugin.WizardPlugin.get_wizard_details` diff --git a/src/octoprint/static/js/app/viewmodels/usersettings.js b/src/octoprint/static/js/app/viewmodels/usersettings.js index c796b6d3b..39828c365 100644 --- a/src/octoprint/static/js/app/viewmodels/usersettings.js +++ b/src/octoprint/static/js/app/viewmodels/usersettings.js @@ -79,6 +79,8 @@ $(function () { self.save = function () { if (!CONFIG_ACCESS_CONTROL) return; + self.userSettingsDialog.trigger("beforeSave"); + if (self.access_password() && !self.passwordMismatch()) { self.users.updatePassword( self.currentUser().name, @@ -162,6 +164,9 @@ $(function () { self.userSettingsDialog.on("hidden", function () { callViewModels(allViewModels, "onUserSettingsHidden"); }); + self.userSettingsDialog.on("beforeSave", function () { + callViewModels(allViewModels, "onUserSettingsBeforeSave"); + }); }; }