MOBILE-3833 core: Block logout when a form is active

main
Dani Palou 2022-04-07 10:05:28 +02:00
parent ef405e4309
commit 8c41be3520
4 changed files with 24 additions and 1 deletions

View File

@ -1465,6 +1465,7 @@
"core.cannotconnecttrouble": "local_moodlemobileapp",
"core.cannotconnectverify": "local_moodlemobileapp",
"core.cannotdownloadfiles": "local_moodlemobileapp",
"core.cannotlogoutpageblocks": "local_moodlemobileapp",
"core.cannotopeninapp": "local_moodlemobileapp",
"core.cannotopeninappdownload": "local_moodlemobileapp",
"core.captureaudio": "local_moodlemobileapp",

View File

@ -28,7 +28,7 @@ import {
import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { ModalController } from '@singletons';
import { ModalController, Translate } from '@singletons';
import { Subscription } from 'rxjs';
/**
@ -172,6 +172,12 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
* @param event Click event
*/
async logout(event: Event): Promise<void> {
if (CoreNavigator.currentRouteCanBlockLeave()) {
await CoreDomUtils.showAlert(undefined, Translate.instant('core.cannotlogoutpageblocks'));
return;
}
if (this.removeAccountOnLogout) {
// Ask confirm.
const siteName = this.siteName ?
@ -200,6 +206,12 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
* @param event Click event
*/
async switchAccounts(event: Event): Promise<void> {
if (CoreNavigator.currentRouteCanBlockLeave()) {
await CoreDomUtils.showAlert(undefined, Translate.instant('core.cannotlogoutpageblocks'));
return;
}
const thisModal = await ModalController.getTop();
event.preventDefault();

View File

@ -18,6 +18,7 @@
"cannotconnecttrouble": "We're having trouble connecting to your site.",
"cannotconnectverify": "<strong>Please check the address is correct.</strong>",
"cannotdownloadfiles": "File downloading is disabled. Please contact your site administrator.",
"cannotlogoutpageblocks": "Please save or discard your changes before continuing.",
"cannotopeninapp": "This file may not work as expected on this device. Would you like to open it anyway?",
"cannotopeninappdownload": "This file may not work as expected on this device. Would you like to download it anyway?",
"captureaudio": "Record audio",

View File

@ -658,6 +658,15 @@ export class CoreNavigatorService {
}
}
/**
* Check if the current route page can block leaving the route.
*
* @return Whether the current route page can block leaving the route.
*/
currentRouteCanBlockLeave(): boolean {
return !!this.getCurrentRoute().snapshot.routeConfig?.canDeactivate?.length;
}
}
export const CoreNavigator = makeSingleton(CoreNavigatorService);