blob: 18f08d48f387be6ccd7149dcf19c94acf5f41422 [file] [log] [blame]
Philipp Schradercf915462022-03-16 23:42:22 -07001import {Component, ElementRef, ViewChild} from '@angular/core';
Alex Perryb3168082022-01-22 13:36:13 -08002
Philipp Schrader72beced2022-03-07 05:29:52 -08003type Tab = 'Entry'|'ImportMatchList';
4
Alex Perryb3168082022-01-22 13:36:13 -08005@Component({
6 selector: 'my-app',
7 templateUrl: './app.ng.html',
Philipp Schrader72beced2022-03-07 05:29:52 -08008 styleUrls: ['./common.css']
Alex Perryb3168082022-01-22 13:36:13 -08009})
10export class App {
Philipp Schrader72beced2022-03-07 05:29:52 -080011 tab: Tab = 'Entry';
12
Philipp Schradercf915462022-03-16 23:42:22 -070013 @ViewChild("block_alerts") block_alerts: ElementRef;
14
Alex Perryd3ccac92022-03-12 13:48:04 -080015 constructor() {
16 window.addEventListener('beforeunload', (e) => {
Philipp Schradercf915462022-03-16 23:42:22 -070017 if (!this.block_alerts.nativeElement.checked) {
18 // Based on https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#example
19 // This combination ensures a dialog will be shown on most browsers.
20 e.preventDefault();
21 e.returnValue = '';
22 }
Alex Perryd3ccac92022-03-12 13:48:04 -080023 });
24 }
25
Philipp Schrader72beced2022-03-07 05:29:52 -080026 tabIs(tab: Tab) {
27 return this.tab == tab;
28 }
29
30 switchTabTo(tab: Tab) {
Alex Perry19a87962022-03-12 13:36:10 -080031 let shouldSwitch = true;
32 if (tab === 'ImportMatchList') {
33 shouldSwitch = window.confirm('Leave data scouting page?');
34 }
35 if (shouldSwitch) {
36 this.tab = tab;
37 }
Philipp Schrader72beced2022-03-07 05:29:52 -080038 }
Alex Perryb3168082022-01-22 13:36:13 -080039}