-
Notifications
You must be signed in to change notification settings - Fork 639
/
Severity.ts
90 lines (79 loc) · 2.39 KB
/
Severity.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
import {SeverityEnum} from './Enum/Severity';
/**
* Module: TYPO3/CMS/Backend/Severity
* Severity for the TYPO3 backend
*/
class Severity {
public static notice: number = SeverityEnum.notice;
public static info: number = SeverityEnum.info;
public static ok: number = SeverityEnum.ok;
public static warning: number = SeverityEnum.warning;
public static error: number = SeverityEnum.error;
/**
* Gets the CSS class for the severity
*
* @param {SeverityEnum} severity
* @returns {string}
*/
public static getCssClass(severity: SeverityEnum): string {
let severityClass: string;
switch (severity) {
case SeverityEnum.notice:
severityClass = 'notice';
break;
case SeverityEnum.ok:
severityClass = 'success';
break;
case SeverityEnum.warning:
severityClass = 'warning';
break;
case SeverityEnum.error:
severityClass = 'danger';
break;
case SeverityEnum.info:
default:
severityClass = 'info';
}
return severityClass;
}
}
let severityObject;
try {
// fetch from opening window
if (window.opener && window.opener.TYPO3 && window.opener.TYPO3.Severity) {
severityObject = window.opener.TYPO3.Severity;
}
// fetch from parent
if (parent && parent.window.TYPO3 && parent.window.TYPO3.Severity) {
severityObject = parent.window.TYPO3.Severity;
}
// fetch object from outer frame
if (top && top.TYPO3 && top.TYPO3.Severity) {
severityObject = top.TYPO3.Severity;
}
} catch (e) {
// This only happens if the opener, parent or top is some other url (eg a local file)
// which loaded the current window. Then the browser's cross domain policy jumps in
// and raises an exception.
// For this case we are safe and we can create our global object below.
}
if (!severityObject) {
severityObject = Severity;
// attach to global frame
if (typeof TYPO3 !== 'undefined') {
TYPO3.Severity = severityObject;
}
}
export = severityObject;