MOBILE-3833 core: Block logout when a form is active
parent
ef405e4309
commit
8c41be3520
|
@ -1465,6 +1465,7 @@
|
||||||
"core.cannotconnecttrouble": "local_moodlemobileapp",
|
"core.cannotconnecttrouble": "local_moodlemobileapp",
|
||||||
"core.cannotconnectverify": "local_moodlemobileapp",
|
"core.cannotconnectverify": "local_moodlemobileapp",
|
||||||
"core.cannotdownloadfiles": "local_moodlemobileapp",
|
"core.cannotdownloadfiles": "local_moodlemobileapp",
|
||||||
|
"core.cannotlogoutpageblocks": "local_moodlemobileapp",
|
||||||
"core.cannotopeninapp": "local_moodlemobileapp",
|
"core.cannotopeninapp": "local_moodlemobileapp",
|
||||||
"core.cannotopeninappdownload": "local_moodlemobileapp",
|
"core.cannotopeninappdownload": "local_moodlemobileapp",
|
||||||
"core.captureaudio": "local_moodlemobileapp",
|
"core.captureaudio": "local_moodlemobileapp",
|
||||||
|
|
|
@ -28,7 +28,7 @@ import {
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { ModalController } from '@singletons';
|
import { ModalController, Translate } from '@singletons';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,6 +172,12 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
|
||||||
* @param event Click event
|
* @param event Click event
|
||||||
*/
|
*/
|
||||||
async logout(event: Event): Promise<void> {
|
async logout(event: Event): Promise<void> {
|
||||||
|
if (CoreNavigator.currentRouteCanBlockLeave()) {
|
||||||
|
await CoreDomUtils.showAlert(undefined, Translate.instant('core.cannotlogoutpageblocks'));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.removeAccountOnLogout) {
|
if (this.removeAccountOnLogout) {
|
||||||
// Ask confirm.
|
// Ask confirm.
|
||||||
const siteName = this.siteName ?
|
const siteName = this.siteName ?
|
||||||
|
@ -200,6 +206,12 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
|
||||||
* @param event Click event
|
* @param event Click event
|
||||||
*/
|
*/
|
||||||
async switchAccounts(event: Event): Promise<void> {
|
async switchAccounts(event: Event): Promise<void> {
|
||||||
|
if (CoreNavigator.currentRouteCanBlockLeave()) {
|
||||||
|
await CoreDomUtils.showAlert(undefined, Translate.instant('core.cannotlogoutpageblocks'));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const thisModal = await ModalController.getTop();
|
const thisModal = await ModalController.getTop();
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
"cannotconnecttrouble": "We're having trouble connecting to your site.",
|
"cannotconnecttrouble": "We're having trouble connecting to your site.",
|
||||||
"cannotconnectverify": "<strong>Please check the address is correct.</strong>",
|
"cannotconnectverify": "<strong>Please check the address is correct.</strong>",
|
||||||
"cannotdownloadfiles": "File downloading is disabled. Please contact your site administrator.",
|
"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?",
|
"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?",
|
"cannotopeninappdownload": "This file may not work as expected on this device. Would you like to download it anyway?",
|
||||||
"captureaudio": "Record audio",
|
"captureaudio": "Record audio",
|
||||||
|
|
|
@ -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);
|
export const CoreNavigator = makeSingleton(CoreNavigatorService);
|
||||||
|
|
Loading…
Reference in New Issue