mobile-wizard: restore tabs when switching windows

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: Ie28a1d06e54475623cf1d20510336b2267cdf338
This commit is contained in:
Szymon Kłos 2022-11-24 13:37:13 +01:00 committed by pedropintosilva
parent 433f4043e9
commit 80cb63ad91
2 changed files with 26 additions and 15 deletions

View file

@ -153,6 +153,12 @@ L.Control.MobileWizard = L.Control.extend({
L.DomUtil.updateElementsOrientation(['mobile-wizard', 'mobile-wizard-content']); L.DomUtil.updateElementsOrientation(['mobile-wizard', 'mobile-wizard-content']);
}, },
selectedTab: function(tabText) {
var topWindow = this.contents.length ? this.contents[this.contents.length - 1] : null;
if (topWindow)
topWindow.selectedTab(tabText);
},
_getContentForWindowId: function(id) { _getContentForWindowId: function(id) {
for (var i in this.contents) { for (var i in this.contents) {
if (this.contents[i].id === 'mobile-wizard-content-' + id) if (this.contents[i].id === 'mobile-wizard-content-' + id)

View file

@ -19,18 +19,18 @@ L.Control.MobileWizardWindow = L.Control.extend({
_customTitle: false, _customTitle: false,
_isTabMode: false, _isTabMode: false,
_currentPath: [], _currentPath: [],
_tabs: [],
_currentScrollPosition: 0, _currentScrollPosition: 0,
_isPopup: false, _isPopup: false,
initialize: function (mobileWizard, id) { initialize: function (mobileWizard, id) {
L.setOptions(this, this.options); L.setOptions(this, this.options);
this.id = id; this.id = id; // unique id of this window "mobile-wizard-content-N"
this.parent = mobileWizard; this.parent = mobileWizard; // reference to the parent mobile-wizard
this.isVisible = false; this.isVisible = false; // indicates if this window is currently visible inside mobile-wizard
this.tabs = []; // tabs we can later restore if dialog was hidden
var parent = document.getElementById('mobile-wizard-content'); var parentNode = document.getElementById('mobile-wizard-content');
this.content = L.DomUtil.create('div', 'mobile-wizard mobile-wizard-content', parent); this.content = L.DomUtil.create('div', 'mobile-wizard mobile-wizard-content', parentNode);
this.content.id = this.id; this.content.id = this.id;
}, },
@ -55,7 +55,7 @@ L.Control.MobileWizardWindow = L.Control.extend({
this.content.innerHTML = ''; this.content.innerHTML = '';
this.backButton.show(); this.backButton.show();
this.backButton.addClass('close-button'); this.backButton.addClass('close-button');
$('#mobile-wizard-tabs').empty(); $('#mobile-wizard-tabs').children().detach();
$('#mobile-wizard-tabs').hide(); $('#mobile-wizard-tabs').hide();
$('#mobile-wizard-titlebar').show(); $('#mobile-wizard-titlebar').show();
$('#mobile-wizard-titlebar').css('top', '0px'); $('#mobile-wizard-titlebar').css('top', '0px');
@ -65,7 +65,7 @@ L.Control.MobileWizardWindow = L.Control.extend({
$('#mobile-wizard').removeClass('snackbar'); $('#mobile-wizard').removeClass('snackbar');
this._isTabMode = false; this._isTabMode = false;
this._currentPath = []; this._currentPath = [];
this._tabs = []; this.tabs = [];
this._currentScrollPosition = 0; this._currentScrollPosition = 0;
this._isPopup = false; this._isPopup = false;
}, },
@ -84,6 +84,7 @@ L.Control.MobileWizardWindow = L.Control.extend({
showWindow: function() { showWindow: function() {
this.isVisible = true; this.isVisible = true;
$(this.content).show(); $(this.content).show();
this.restoreTabs();
}, },
_showWizard: function() { _showWizard: function() {
@ -136,14 +137,18 @@ L.Control.MobileWizardWindow = L.Control.extend({
}, },
setTabs: function(tabs) { setTabs: function(tabs) {
this._tabs = tabs; this.tabs = tabs;
$('#mobile-wizard-tabs').show(); $('#mobile-wizard-tabs').show();
$('#mobile-wizard-tabs').empty(); $('#mobile-wizard-tabs').children().detach();
$('#mobile-wizard-tabs').append(tabs); $('#mobile-wizard-tabs').append(tabs);
$('#mobile-wizard-titlebar').hide(); $('#mobile-wizard-titlebar').hide();
this._isTabMode = true; this._isTabMode = true;
}, },
restoreTabs: function() {
this.setTabs(this.tabs);
},
setCurrentScrollPosition: function() { setCurrentScrollPosition: function() {
this._currentScrollPosition = $(this.content).scrollTop(); this._currentScrollPosition = $(this.content).scrollTop();
}, },
@ -283,10 +288,10 @@ L.Control.MobileWizardWindow = L.Control.extend({
}, },
_selectTab: function(tabId) { _selectTab: function(tabId) {
if (this._tabs && tabId) { if (this.tabs && tabId) {
for (var index in this._tabs.children) { for (var index in this.tabs.children) {
if (this._tabs.children[index].id === tabId) { if (this.tabs.children[index].id === tabId) {
$(this._tabs.children[index]).trigger('click', {animate: false}); $(this.tabs.children[index]).trigger('click', {animate: false});
break; break;
} }
} }
@ -295,7 +300,7 @@ L.Control.MobileWizardWindow = L.Control.extend({
_goToPath: function(path) { _goToPath: function(path) {
// when dialog has tabs, tab selection triggers the callback, causes infinite regenetate loop // when dialog has tabs, tab selection triggers the callback, causes infinite regenetate loop
if (this._tabs && path && path.length && !this.map.dialog.hasDialogInMobilePanelOpened()) if (this.tabs && path && path.length && !this.map.dialog.hasDialogInMobilePanelOpened())
this._selectTab(path[0]); this._selectTab(path[0]);
var _path = []; var _path = [];