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