From 21f9715623e5b5bcb6be6af6975b7b65da37b9e5 Mon Sep 17 00:00:00 2001 From: GabrielMeyer Date: Tue, 5 Feb 2019 14:34:40 +0100 Subject: [PATCH] Fixes #4258 - Added a listener to the `onBeforeUnload`-event. - This prevent reloading or closing the window including `F5, Shift+F5, Ctrl+R, Ctrl+Shift+R, Crtl+W, closing the tab by 'x'` Added comment to the event-function. --- .../motion-detail/motion-detail.component.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts index 0fa95c1b5..abf91aad8 100644 --- a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts +++ b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts @@ -1,5 +1,5 @@ import { ActivatedRoute, Router } from '@angular/router'; -import { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; +import { Component, OnInit, ViewChild, ElementRef, HostListener } from '@angular/core'; import { DomSanitizer, SafeHtml, Title } from '@angular/platform-browser'; import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; import { MatDialog, MatExpansionPanel, MatSnackBar, MatCheckboxChange, ErrorStateMatcher } from '@angular/material'; @@ -1172,6 +1172,19 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { this.personalNoteService.setPersonalNoteStar(this.motion.motion, !this.motion.star); } + /** + * Function to prevent automatically closing the window/tab, + * if the user is editing a motion. + * + * @param $event The event object from 'onUnbeforeUnload'. + */ + @HostListener('window:beforeunload', ['$event']) + public stopClosing($event: Event): void { + if (this.editMotion) { + $event.returnValue = null; + } + } + /** * Translate the state's css class into a color *