cf5288ce51eb574239541858fe4a1577c8394b6b
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / Severity.js
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 /**
15 * Module: TYPO3/CMS/Backend/Severity
16 * Severity for the TYPO3 backend
17 */
18 define(function() {
19 'use strict';
20
21 try {
22 // fetch from opening window
23 if (window.opener && window.opener.TYPO3 && window.opener.TYPO3.Severity) {
24 return window.opener.TYPO3.Severity;
25 }
26
27 // fetch from parent
28 if (parent && parent.window.TYPO3 && parent.window.TYPO3.Severity) {
29 return parent.window.TYPO3.Severity;
30 }
31
32 // fetch object from outer frame
33 if (top && top.TYPO3 && top.TYPO3.Severity) {
34 return top.TYPO3.Severity;
35 }
36 } catch (e) {
37 // This only happens if the opener, parent or top is some other url (eg a local file)
38 // which loaded the current window. Then the browser's cross domain policy jumps in
39 // and raises an exception.
40 // For this case we are safe and we can create our global object below.
41 }
42
43 /**
44 * Severity object
45 *
46 * @type {{notice: number, information: number, info: number, ok: number, warning: number, error: number}}
47 * @exports TYPO3/CMS/Backend/Severity
48 */
49 var Severity = {
50 notice: -2,
51 info: -1,
52 ok: 0,
53 warning: 1,
54 error: 2
55 };
56
57 /**
58 * Gets the CSS class for the severity
59 *
60 * @param {Number} severity
61 * @returns {String}
62 */
63 Severity.getCssClass = function(severity) {
64 var severityClass;
65 switch (severity) {
66 case Severity.notice:
67 severityClass = 'notice';
68 break;
69 case Severity.ok:
70 severityClass = 'success';
71 break;
72 case Severity.warning:
73 severityClass = 'warning';
74 break;
75 case Severity.error:
76 severityClass = 'danger';
77 break;
78 case Severity.info:
79 default:
80 severityClass = 'info';
81 }
82 return severityClass;
83 };
84
85 // attach to global frame
86 if (typeof TYPO3 !== 'undefined') {
87 TYPO3.Severity = Severity;
88 }
89
90 return Severity;
91 });