Only show wizard when firstRun is true or user is admin

This commit is contained in:
Gina Häußge 2015-07-14 20:21:31 +02:00
parent c7e602d342
commit 33cbd3dcbd

View file

@ -1,10 +1,18 @@
$(function() { $(function() {
function WizardViewModel() { function WizardViewModel(parameters) {
var self = this; var self = this;
self.loginState = parameters[0];
self.wizardDialog = undefined; self.wizardDialog = undefined;
self.isDialogActive = function() {
return self.wizardDialog.is(":visible");
};
self.showDialog = function() { self.showDialog = function() {
if (!CONFIG_WIZARD || !(CONFIG_FIRST_RUN || self.loginState.isAdmin())) return;
self.wizardDialog.modal({ self.wizardDialog.modal({
minHeight: function() { return Math.max($.fn.modal.defaults.maxHeight() - 80, 250); } minHeight: function() { return Math.max($.fn.modal.defaults.maxHeight() - 80, 250); }
}).css({ }).css({
@ -21,74 +29,88 @@ $(function() {
self.wizardDialog = $("#wizard_dialog"); self.wizardDialog = $("#wizard_dialog");
}; };
self.onUserLoggedIn = function() {
self.showDialog();
};
self.onAllBound = function(allViewModels) { self.onAllBound = function(allViewModels) {
if (CONFIG_WIZARD) { self.wizardDialog.bootstrapWizard({
self.wizardDialog.bootstrapWizard({ tabClass: "nav nav-list",
tabClass: "nav nav-list", nextSelector: ".button-next",
nextSelector: ".button-next", previousSelector: ".button-previous",
previousSelector: ".button-previous", finishSelector: ".button-finish",
finishSelector: ".button-finish", onTabClick: function() {
onTabClick: function() { // we don't allow clicking on the tabs
// we don't allow clicking on the tabs return false;
return false; },
}, onTabShow: function(tab, navigation, index) {
onTabShow: function(tab, navigation, index) { if (index < 0 || tab.length == 0) {
if (index < 0 || tab.length == 0) { return true;
return true;
}
var total = self.wizardDialog.bootstrapWizard("navigationLength");
if (index == total) {
self.wizardDialog.find(".button-next").hide();
self.wizardDialog.find(".button-finish").show().removeClass("disabled");
} else {
self.wizardDialog.find(".button-finish").hide();
self.wizardDialog.find(".button-next").show();
}
var active = tab[0].id;
if (active != undefined) {
_.each(allViewModels, function(viewModel) {
if (viewModel.hasOwnProperty("onAfterWizardTabChange")) {
viewModel.onAfterWizardTabChange(active);
}
});
}
},
onTabChange: function(tab, navigation, index, nextTabIndex, nextTab) {
var current, next;
if (index == undefined || index < 0 ||
nextTabIndex == undefined || nextTabIndex < 0 ||
index == nextTabIndex ||
tab.length == 0 || nextTab.length == 0) {
// let's ignore that nonsense
return;
}
current = tab[0].id;
next = nextTab[0].id;
if (current != undefined && next != undefined) {
var result = true;
_.each(allViewModels, function(viewModel) {
if (viewModel.hasOwnProperty("onWizardTabChange")) {
result = result && viewModel.onWizardTabChange(current, next);
}
});
return result;
}
} }
});
self.showDialog(); var total = self.wizardDialog.bootstrapWizard("navigationLength");
}
} if (index == total) {
self.wizardDialog.find(".button-next").hide();
self.wizardDialog.find(".button-finish").show().removeClass("disabled");
} else {
self.wizardDialog.find(".button-finish").hide();
self.wizardDialog.find(".button-next").show();
}
var active = tab[0].id;
if (active != undefined) {
_.each(allViewModels, function(viewModel) {
if (viewModel.hasOwnProperty("onAfterWizardTabChange")) {
viewModel.onAfterWizardTabChange(active);
}
});
}
},
onTabChange: function(tab, navigation, index, nextTabIndex, nextTab) {
var current, next;
if (index == undefined || index < 0 ||
nextTabIndex == undefined || nextTabIndex < 0 ||
index == nextTabIndex ||
tab.length == 0 || nextTab.length == 0) {
// let's ignore that nonsense
return;
}
current = tab[0].id;
next = nextTab[0].id;
if (current != undefined && next != undefined) {
var result = true;
_.each(allViewModels, function(viewModel) {
if (viewModel.hasOwnProperty("onWizardTabChange")) {
result = result && (viewModel.onWizardTabChange(current, next) !== false);
}
});
return result;
}
},
onFinish: function(tab, navigation, index) {
var closeDialog = true;
_.each(allViewModels, function(viewModel) {
if (viewModel.hasOwnProperty("onWizardFinish")) {
closeDialog = closeDialog && (viewModel.onWizardFinish() !== false);
}
});
if (closeDialog) {
self.closeDialog();
}
}
});
self.showDialog();
};
} }
OCTOPRINT_VIEWMODELS.push([ OCTOPRINT_VIEWMODELS.push([
WizardViewModel, WizardViewModel,
[], ["loginStateViewModel"],
"#wizard_dialog" "#wizard_dialog"
]); ]);
}); });