Skip to content

Commit

Permalink
[TASK] Migrate Severity to TypeScript
Browse files Browse the repository at this point in the history
Change-Id: I5b738983f733da77100830b841419ba9d12fdf23
Resolves: #83955
Releases: master
Reviewed-on: https://review.typo3.org/55780
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Tested-by: Andreas Wolf <andreas.wolf@typo3.org>
  • Loading branch information
andreaskienast authored and andreaswolf committed Feb 18, 2018
1 parent 0a1f7db commit f9152bc
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 101 deletions.
12 changes: 0 additions & 12 deletions Build/types/TYPO3/index.d.ts
Expand Up @@ -46,14 +46,6 @@ declare namespace TYPO3 {
public error(title: string, message: string, duration: Number): string;
public showMessage(title: string, message: string, severity: Number, duration?: Number): string;
}
export class Severity {
public readonly notice: number;
public readonly info: number;
public readonly ok: number;
public readonly warning: number;
public readonly: number;
public getCssClass(severity: number): string;
}
}
}
}
Expand All @@ -78,10 +70,6 @@ declare module 'TYPO3/CMS/Backend/Notification' {
export = new TYPO3.CMS.Backend.Notification();
}

declare module 'TYPO3/CMS/Backend/Severity' {
export = new TYPO3.CMS.Backend.Severity();
}

// type definition for global namespace object
interface Window {
TYPO3: any;
Expand Down
Expand Up @@ -20,7 +20,7 @@ import moment = require('moment');
import NProgress = require('nprogress');
import Modal = require('TYPO3/CMS/Backend/Modal');
import Notification = require('TYPO3/CMS/Backend/Notification');
import Severity = require('TYPO3/CMS/Backend/Severity');
import Severity = require('./Severity');

/**
* Possible actions for conflicts w/ existing files
Expand Down
Expand Up @@ -14,7 +14,7 @@
import 'bootstrap';
import * as $ from 'jquery';
import Modal = require('TYPO3/CMS/Backend/Modal');
import Severity = require('TYPO3/CMS/Backend/Severity');
import Severity = require('./Severity');

/**
* GridEditorConfigurationInterface
Expand Down
Expand Up @@ -12,7 +12,7 @@
*/

import Modal = require('TYPO3/CMS/Backend/Modal');
import Severity = require('TYPO3/CMS/Backend/Severity');
import Severity = require('./Severity');

/**
* Module: TYPO3/CMS/Backend/InfoWindow
Expand Down
Expand Up @@ -13,7 +13,7 @@

import * as $ from 'jquery';
import Modal = require('TYPO3/CMS/Backend/Modal');
import Severity = require('TYPO3/CMS/Backend/Severity');
import Severity = require('./Severity');

/**
* Module: TYPO3/CMS/Backend/RenameFile
Expand Down
92 changes: 92 additions & 0 deletions typo3/sysext/backend/Resources/Private/TypeScript/Severity.ts
@@ -0,0 +1,92 @@
/*
* 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!
*/

enum SeverityEnum {
notice = -2,
info = -1,
ok = 0,
warning = 1,
error = 2
}

/**
* 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;
}

TYPO3.Storage = severityObject;
export = severityObject;
Expand Up @@ -12,7 +12,7 @@
*/

import Modal = require('TYPO3/CMS/Backend/Modal');
import Severity = require('TYPO3/CMS/Backend/Severity');
import Severity = require('../Severity');

/**
* Module: TYPO3/CMS/Backend/Wizard/NewContentElement
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Expand Up @@ -10,4 +10,4 @@
*
* The TYPO3 project - inspiring people to share!
*/
define(["require","exports","TYPO3/CMS/Backend/Modal","TYPO3/CMS/Backend/Severity"],function(a,b,c,d){"use strict";var e=function(){function a(){}return a.showItem=function(a,b){c.advanced({type:c.types.iframe,size:c.sizes.large,content:TYPO3.settings.ShowItem.moduleUrl+"&table="+encodeURIComponent(a)+"&uid="+("number"==typeof b?b:encodeURIComponent(b)),severity:d.notice})},a}();return TYPO3.InfoWindow=e,e});
define(["require","exports","TYPO3/CMS/Backend/Modal","./Severity"],function(a,b,c,d){"use strict";var e=function(){function a(){}return a.showItem=function(a,b){c.advanced({type:c.types.iframe,size:c.sizes.large,content:TYPO3.settings.ShowItem.moduleUrl+"&table="+encodeURIComponent(a)+"&uid="+("number"==typeof b?b:encodeURIComponent(b)),severity:d.notice})},a}();return TYPO3.InfoWindow=e,e});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 1 addition & 79 deletions typo3/sysext/backend/Resources/Public/JavaScript/Severity.js
Expand Up @@ -10,82 +10,4 @@
*
* The TYPO3 project - inspiring people to share!
*/

/**
* Module: TYPO3/CMS/Backend/Severity
* Severity for the TYPO3 backend
*/
define(function() {
'use strict';

try {
// fetch from opening window
if (window.opener && window.opener.TYPO3 && window.opener.TYPO3.Severity) {
return window.opener.TYPO3.Severity;
}

// fetch from parent
if (parent && parent.window.TYPO3 && parent.window.TYPO3.Severity) {
return parent.window.TYPO3.Severity;
}

// fetch object from outer frame
if (top && top.TYPO3 && top.TYPO3.Severity) {
return 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.
}

/**
* Severity object
*
* @type {{notice: number, information: number, info: number, ok: number, warning: number, error: number}}
* @exports TYPO3/CMS/Backend/Severity
*/
var Severity = {
notice: -2,
info: -1,
ok: 0,
warning: 1,
error: 2
};

/**
* Gets the CSS class for the severity
*
* @param {Number} severity
* @returns {String}
*/
Severity.getCssClass = function(severity) {
var severityClass;
switch (severity) {
case Severity.notice:
severityClass = 'notice';
break;
case Severity.ok:
severityClass = 'success';
break;
case Severity.warning:
severityClass = 'warning';
break;
case Severity.error:
severityClass = 'danger';
break;
case Severity.info:
default:
severityClass = 'info';
}
return severityClass;
};

// attach to global frame
if (typeof TYPO3 !== 'undefined') {
TYPO3.Severity = Severity;
}

return Severity;
});
define(["require","exports"],function(a,b){"use strict";var c;!function(a){a[a.notice=-2]="notice",a[a.info=-1]="info",a[a.ok=0]="ok",a[a.warning=1]="warning",a[a.error=2]="error"}(c||(c={}));var d,e=function(){function a(){}return a.getCssClass=function(a){var b;switch(a){case c.notice:b="notice";break;case c.ok:b="success";break;case c.warning:b="warning";break;case c.error:b="danger";break;case c.info:default:b="info"}return b},a.notice=c.notice,a.info=c.info,a.ok=c.ok,a.warning=c.warning,a.error=c.error,a}();try{window.opener&&window.opener.TYPO3&&window.opener.TYPO3.Severity&&(d=window.opener.TYPO3.Severity),parent&&parent.window.TYPO3&&parent.window.TYPO3.Severity&&(d=parent.window.TYPO3.Severity),top&&top.TYPO3&&top.TYPO3.Severity&&(d=top.TYPO3.Severity)}catch(a){}return d||(d=e),TYPO3.Storage=d,d});
Expand Up @@ -10,4 +10,4 @@
*
* The TYPO3 project - inspiring people to share!
*/
define(["require","exports","TYPO3/CMS/Backend/Modal","TYPO3/CMS/Backend/Severity"],function(a,b,c,d){"use strict";var e=function(){function a(){}return a.wizard=function(a,b){c.advanced({callback:function(a){a.find(".t3js-modal-body").addClass("t3-new-content-element-wizard-window")},content:a,severity:d.notice,size:c.sizes.medium,title:b,type:c.types.ajax})},a}();return e});
define(["require","exports","TYPO3/CMS/Backend/Modal","../Severity"],function(a,b,c,d){"use strict";var e=function(){function a(){}return a.wizard=function(a,b){c.advanced({callback:function(a){a.find(".t3js-modal-body").addClass("t3-new-content-element-wizard-window")},content:a,severity:d.notice,size:c.sizes.medium,title:b,type:c.types.ajax})},a}();return e});

0 comments on commit f9152bc

Please sign in to comment.