Reset scroll position and selected tab in settings dialog

Also added means to open settings dialog navigating directly to a specific tab
This commit is contained in:
Gina Häußge 2016-01-12 13:30:10 +01:00
parent 7743372ee4
commit 2a059cf0cb
2 changed files with 28 additions and 2 deletions

View file

@ -247,9 +247,20 @@ $(function() {
}
});
});
// reset scroll position on tab change
$('ul.nav-list a[data-toggle="tab"]', self.settingsDialog).on("show", function() {
self._resetScrollPosition();
});
};
self.show = function() {
self.show = function(tab) {
// select first or specified tab
self.selectTab(tab);
// reset scroll position
self._resetScrollPosition();
// show settings, ensure centered position
self.settingsDialog.modal({
minHeight: function() { return Math.max($.fn.modal.defaults.maxHeight() - 80, 250); }
@ -584,6 +595,21 @@ $(function() {
self.onEventSettingsUpdated = function() {
self.requestData();
};
self._resetScrollPosition = function() {
$('.scrollable', self.settingsDialog).scrollTop(0);
};
self.selectTab = function(tab) {
if (tab != undefined) {
if (!_.startsWith(tab, "#")) {
tab = "#" + tab;
}
$('ul.nav-list a[href="' + tab + '"]', self.settingsDialog).tab("show");
} else {
$('ul.nav-list a:first', self.settingsDialog).tab("show");
}
};
}
OCTOPRINT_VIEWMODELS.push([

View file

@ -1,3 +1,3 @@
<a id="navbar_show_settings" class="pull-right" href="#settings_dialog" data-bind="click: show">
<a id="navbar_show_settings" class="pull-right" href="#settings_dialog" data-bind="click: function() { $root.show(); }">
<i class="icon-wrench"></i> {{ _('Settings') }}
</a>