From 681def9d6c305b7a6dcbb0e1a3c2c65bdf869bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 16 Jul 2015 14:00:53 +0200 Subject: [PATCH] Wizard fetches details and saves enqueued setting on finish Plugins may implement onWizardDetails, onWizardBeforeFinish and onWizardFinish to react to wizard events. --- .../static/js/app/viewmodels/wizard.js | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/wizard.js b/src/octoprint/static/js/app/viewmodels/wizard.js index 1fe81e03..3a29c32a 100644 --- a/src/octoprint/static/js/app/viewmodels/wizard.js +++ b/src/octoprint/static/js/app/viewmodels/wizard.js @@ -3,9 +3,12 @@ $(function() { var self = this; self.loginState = parameters[0]; + self.settingsViewModel = parameters[1]; self.wizardDialog = undefined; + self.allViewModels = undefined; + self.isDialogActive = function() { return self.wizardDialog.is(":visible"); }; @@ -13,11 +16,19 @@ $(function() { self.showDialog = function() { if (!CONFIG_WIZARD || !(CONFIG_FIRST_RUN || self.loginState.isAdmin())) return; - self.wizardDialog.modal({ - minHeight: function() { return Math.max($.fn.modal.defaults.maxHeight() - 80, 250); } - }).css({ - width: 'auto', - 'margin-left': function() { return -($(this).width() /2); } + self.getWizardDetails(function(response) { + _.each(self.allViewModels, function(viewModel) { + if (viewModel.hasOwnProperty("onWizardDetails")) { + viewModel.onWizardDetails(response); + } + }); + + self.wizardDialog.modal({ + minHeight: function() { return Math.max($.fn.modal.defaults.maxHeight() - 80, 250); } + }).css({ + width: 'auto', + 'margin-left': function() { return -($(this).width() /2); } + }); }); }; @@ -34,6 +45,7 @@ $(function() { }; self.onAllBound = function(allViewModels) { + self.allViewModels = allViewModels; self.wizardDialog.bootstrapWizard({ tabClass: "nav nav-list", nextSelector: ".button-next", @@ -94,23 +106,40 @@ $(function() { onFinish: function(tab, navigation, index) { var closeDialog = true; _.each(allViewModels, function(viewModel) { - if (viewModel.hasOwnProperty("onWizardFinish")) { - closeDialog = closeDialog && (viewModel.onWizardFinish() !== false); + if (viewModel.hasOwnProperty("onBeforeWizardFinish")) { + closeDialog = closeDialog && (viewModel.onBeforeWizardFinish() !== false); } }); if (closeDialog) { + _.each(allViewModels, function(viewModel) { + if (viewModel.hasOwnProperty("onWizardFinish")) { + viewModel.onWizardFinish(); + } + }); + self.settingsViewModel.saveEnqueued(); self.closeDialog(); } } }); self.showDialog(); }; + + self.getWizardDetails = function(callback) { + if (!callback) return; + + $.ajax({ + url: API_BASEURL + "setup/wizard", + type: "GET", + dataType: "json", + success: callback + }); + } } OCTOPRINT_VIEWMODELS.push([ WizardViewModel, - ["loginStateViewModel"], + ["loginStateViewModel", "settingsViewModel"], "#wizard_dialog" ]); });