Alex Perry | b316808 | 2022-01-22 13:36:13 -0800 | [diff] [blame] | 1 | import {Component} from '@angular/core'; |
| 2 | |
Philipp Schrader | 72beced | 2022-03-07 05:29:52 -0800 | [diff] [blame] | 3 | type Tab = 'Entry'|'ImportMatchList'; |
| 4 | |
Alex Perry | b316808 | 2022-01-22 13:36:13 -0800 | [diff] [blame] | 5 | @Component({ |
| 6 | selector: 'my-app', |
| 7 | templateUrl: './app.ng.html', |
Philipp Schrader | 72beced | 2022-03-07 05:29:52 -0800 | [diff] [blame] | 8 | styleUrls: ['./common.css'] |
Alex Perry | b316808 | 2022-01-22 13:36:13 -0800 | [diff] [blame] | 9 | }) |
| 10 | export class App { |
Philipp Schrader | 72beced | 2022-03-07 05:29:52 -0800 | [diff] [blame] | 11 | tab: Tab = 'Entry'; |
| 12 | |
Alex Perry | d3ccac9 | 2022-03-12 13:48:04 -0800 | [diff] [blame^] | 13 | constructor() { |
| 14 | window.addEventListener('beforeunload', (e) => { |
| 15 | // Based on https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#example |
| 16 | // This combination ensures a dialog will be shown on most browsers. |
| 17 | e.preventDefault(); |
| 18 | e.returnValue = ''; |
| 19 | }); |
| 20 | } |
| 21 | |
Philipp Schrader | 72beced | 2022-03-07 05:29:52 -0800 | [diff] [blame] | 22 | tabIs(tab: Tab) { |
| 23 | return this.tab == tab; |
| 24 | } |
| 25 | |
| 26 | switchTabTo(tab: Tab) { |
Alex Perry | 19a8796 | 2022-03-12 13:36:10 -0800 | [diff] [blame] | 27 | let shouldSwitch = true; |
| 28 | if (tab === 'ImportMatchList') { |
| 29 | shouldSwitch = window.confirm('Leave data scouting page?'); |
| 30 | } |
| 31 | if (shouldSwitch) { |
| 32 | this.tab = tab; |
| 33 | } |
Philipp Schrader | 72beced | 2022-03-07 05:29:52 -0800 | [diff] [blame] | 34 | } |
Alex Perry | b316808 | 2022-01-22 13:36:13 -0800 | [diff] [blame] | 35 | } |