Merge pull request #4259 from GabrielInTheWorld/4258

Prevent mistakenly closing the window
This commit is contained in:
Sean 2019-02-06 10:39:42 +01:00 committed by GitHub
commit eab6e9bfd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import { ActivatedRoute, Router } from '@angular/router'; 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 { DomSanitizer, SafeHtml, Title } from '@angular/platform-browser';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { MatDialog, MatExpansionPanel, MatSnackBar, MatCheckboxChange, ErrorStateMatcher } from '@angular/material'; import { MatDialog, MatExpansionPanel, MatSnackBar, MatCheckboxChange, ErrorStateMatcher } from '@angular/material';
@ -1177,6 +1177,19 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
this.personalNoteService.setPersonalNoteStar(this.motion.motion, !this.motion.star); 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 * Translate the state's css class into a color
* *