[TASK] Cleanup TYPO3/CMS/Backend/Notification 56/60256/3
authorFrank Naegler <frank.naegler@typo3.org>
Fri, 15 Mar 2019 10:41:33 +0000 (11:41 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Sun, 17 Mar 2019 05:33:53 +0000 (06:33 +0100)
Cleanup the Notification.ts file:
- format code
- make optional parameter really optional
- import jquery as everywhere to get correct dependencies

Resolves: #87921
Releases: master
Change-Id: I819f0d7621537415b35a06337f8cd7dc42c5c1a7
Reviewed-on: https://review.typo3.org/c/60256
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/backend/Resources/Private/TypeScript/Notification.ts
typo3/sysext/backend/Resources/Public/JavaScript/Notification.js

index a792b00..5503457 100644 (file)
@@ -11,6 +11,7 @@
  * The TYPO3 project - inspiring people to share!
  */
 
  * The TYPO3 project - inspiring people to share!
  */
 
+import * as $ from 'jquery';
 import {SeverityEnum} from './Enum/Severity';
 import Severity = require('./Severity');
 
 import {SeverityEnum} from './Enum/Severity';
 import Severity = require('./Severity');
 
@@ -29,7 +30,7 @@ class Notification {
    * @param {string} message
    * @param {number} duration
    */
    * @param {string} message
    * @param {number} duration
    */
-  public static notice(title: string, message: string, duration: number): void {
+  public static notice(title: string, message?: string, duration?: number): void {
     Notification.showMessage(title, message, SeverityEnum.notice, duration);
   }
 
     Notification.showMessage(title, message, SeverityEnum.notice, duration);
   }
 
@@ -40,7 +41,7 @@ class Notification {
    * @param {string} message
    * @param {number} duration
    */
    * @param {string} message
    * @param {number} duration
    */
-  public static info(title: string, message: string, duration: number): void {
+  public static info(title: string, message?: string, duration?: number): void {
     Notification.showMessage(title, message, SeverityEnum.info, duration);
   }
 
     Notification.showMessage(title, message, SeverityEnum.info, duration);
   }
 
@@ -51,7 +52,7 @@ class Notification {
    * @param {string} message
    * @param {number} duration
    */
    * @param {string} message
    * @param {number} duration
    */
-  public static success(title: string, message: string, duration: number): void {
+  public static success(title: string, message?: string, duration?: number): void {
     Notification.showMessage(title, message, SeverityEnum.ok, duration);
   }
 
     Notification.showMessage(title, message, SeverityEnum.ok, duration);
   }
 
@@ -62,7 +63,7 @@ class Notification {
    * @param {string} message
    * @param {number} duration
    */
    * @param {string} message
    * @param {number} duration
    */
-  public static warning(title: string, message: string, duration: number): void {
+  public static warning(title: string, message?: string, duration?: number): void {
     Notification.showMessage(title, message, SeverityEnum.warning, duration);
   }
 
     Notification.showMessage(title, message, SeverityEnum.warning, duration);
   }
 
@@ -73,7 +74,7 @@ class Notification {
    * @param {string} message
    * @param {number} duration
    */
    * @param {string} message
    * @param {number} duration
    */
-  public static error(title: string, message: string, duration: number = 0): void {
+  public static error(title: string, message?: string, duration: number = 0): void {
     Notification.showMessage(title, message, SeverityEnum.error, duration);
   }
 
     Notification.showMessage(title, message, SeverityEnum.error, duration);
   }
 
@@ -84,8 +85,8 @@ class Notification {
    * @param {number} duration
    */
   public static showMessage(title: string,
    * @param {number} duration
    */
   public static showMessage(title: string,
-                            message: string,
-                            severity: SeverityEnum,
+                            message?: string,
+                            severity: SeverityEnum = SeverityEnum.info,
                             duration: number | string = this.duration): void {
     const className = Severity.getCssClass(severity);
     let icon = '';
                             duration: number | string = this.duration): void {
     const className = Severity.getCssClass(severity);
     let icon = '';
@@ -116,26 +117,26 @@ class Notification {
       );
 
     if (this.messageContainer === null) {
       );
 
     if (this.messageContainer === null) {
-      this.messageContainer = $('<div id="alert-container"></div>').appendTo('body');
+      this.messageContainer = $('<div>', {'id': 'alert-container'}).appendTo('body');
     }
     const $box = $(
       '<div class="alert alert-' + className + ' alert-dismissible fade" role="alert">' +
     }
     const $box = $(
       '<div class="alert alert-' + className + ' alert-dismissible fade" role="alert">' +
-      '<button type="button" class="close" data-dismiss="alert">' +
-      '<span aria-hidden="true"><i class="fa fa-times-circle"></i></span>' +
-      '<span class="sr-only">Close</span>' +
-      '</button>' +
-      '<div class="media">' +
-      '<div class="media-left">' +
-      '<span class="fa-stack fa-lg">' +
-      '<i class="fa fa-circle fa-stack-2x"></i>' +
-      '<i class="fa fa-' + icon + ' fa-stack-1x"></i>' +
-      '</span>' +
-      '</div>' +
-      '<div class="media-body">' +
-      '<h4 class="alert-title"></h4>' +
-      '<p class="alert-message text-pre-wrap"></p>' +
-      '</div>' +
-      '</div>' +
+        '<button type="button" class="close" data-dismiss="alert">' +
+          '<span aria-hidden="true"><i class="fa fa-times-circle"></i></span>' +
+          '<span class="sr-only">Close</span>' +
+        '</button>' +
+        '<div class="media">' +
+          '<div class="media-left">' +
+            '<span class="fa-stack fa-lg">' +
+              '<i class="fa fa-circle fa-stack-2x"></i>' +
+              '<i class="fa fa-' + icon + ' fa-stack-1x"></i>' +
+            '</span>' +
+          '</div>' +
+          '<div class="media-body">' +
+            '<h4 class="alert-title"></h4>' +
+            '<p class="alert-message text-pre-wrap"></p>' +
+          '</div>' +
+        '</div>' +
       '</div>',
     );
     $box.find('.alert-title').text(title);
       '</div>',
     );
     $box.find('.alert-title').text(title);
index 78cda3d..81fd73a 100644 (file)
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","./Enum/Severity","./Severity"],function(e,i,t,a){"use strict";var n,s=function(){function e(){}return e.notice=function(i,a,n){e.showMessage(i,a,t.SeverityEnum.notice,n)},e.info=function(i,a,n){e.showMessage(i,a,t.SeverityEnum.info,n)},e.success=function(i,a,n){e.showMessage(i,a,t.SeverityEnum.ok,n)},e.warning=function(i,a,n){e.showMessage(i,a,t.SeverityEnum.warning,n)},e.error=function(i,a,n){void 0===n&&(n=0),e.showMessage(i,a,t.SeverityEnum.error,n)},e.showMessage=function(e,i,n,s){void 0===s&&(s=this.duration);var r=a.getCssClass(n),o="";switch(n){case t.SeverityEnum.notice:o="lightbulb-o";break;case t.SeverityEnum.ok:o="check";break;case t.SeverityEnum.warning:o="exclamation";break;case t.SeverityEnum.error:o="times";break;case t.SeverityEnum.info:default:o="info"}s=void 0===s?this.duration:"string"==typeof s?parseFloat(s):s,null===this.messageContainer&&(this.messageContainer=$('<div id="alert-container"></div>').appendTo("body"));var c=$('<div class="alert alert-'+r+' alert-dismissible fade" role="alert"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true"><i class="fa fa-times-circle"></i></span><span class="sr-only">Close</span></button><div class="media"><div class="media-left"><span class="fa-stack fa-lg"><i class="fa fa-circle fa-stack-2x"></i><i class="fa fa-'+o+' fa-stack-1x"></i></span></div><div class="media-body"><h4 class="alert-title"></h4><p class="alert-message text-pre-wrap"></p></div></div></div>');c.find(".alert-title").text(e),c.find(".alert-message").text(i),c.on("close.bs.alert",function(e){e.preventDefault();var i=$(e.currentTarget);i.clearQueue().queue(function(e){i.removeClass("in"),e()}).slideUp(function(){i.remove()})}),c.appendTo(this.messageContainer),c.delay(200).queue(function(e){c.addClass("in"),e()}),s>0&&c.delay(1e3*s).queue(function(e){c.alert("close"),e()})},e.duration=5,e.messageContainer=null,e}();try{parent&&parent.window.TYPO3&&parent.window.TYPO3.Notification&&(n=parent.window.TYPO3.Notification),top&&top.TYPO3.Notification&&(n=top.TYPO3.Notification)}catch(e){}return n||(n=s,"undefined"!=typeof TYPO3&&(TYPO3.Notification=n)),n});
\ No newline at end of file
+define(["require","exports","jquery","./Enum/Severity","./Severity"],function(e,i,t,a,n){"use strict";var s,r=function(){function e(){}return e.notice=function(i,t,n){e.showMessage(i,t,a.SeverityEnum.notice,n)},e.info=function(i,t,n){e.showMessage(i,t,a.SeverityEnum.info,n)},e.success=function(i,t,n){e.showMessage(i,t,a.SeverityEnum.ok,n)},e.warning=function(i,t,n){e.showMessage(i,t,a.SeverityEnum.warning,n)},e.error=function(i,t,n){void 0===n&&(n=0),e.showMessage(i,t,a.SeverityEnum.error,n)},e.showMessage=function(e,i,s,r){void 0===s&&(s=a.SeverityEnum.info),void 0===r&&(r=this.duration);var o=n.getCssClass(s),c="";switch(s){case a.SeverityEnum.notice:c="lightbulb-o";break;case a.SeverityEnum.ok:c="check";break;case a.SeverityEnum.warning:c="exclamation";break;case a.SeverityEnum.error:c="times";break;case a.SeverityEnum.info:default:c="info"}r=void 0===r?this.duration:"string"==typeof r?parseFloat(r):r,null===this.messageContainer&&(this.messageContainer=t("<div>",{id:"alert-container"}).appendTo("body"));var l=t('<div class="alert alert-'+o+' alert-dismissible fade" role="alert"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true"><i class="fa fa-times-circle"></i></span><span class="sr-only">Close</span></button><div class="media"><div class="media-left"><span class="fa-stack fa-lg"><i class="fa fa-circle fa-stack-2x"></i><i class="fa fa-'+c+' fa-stack-1x"></i></span></div><div class="media-body"><h4 class="alert-title"></h4><p class="alert-message text-pre-wrap"></p></div></div></div>');l.find(".alert-title").text(e),l.find(".alert-message").text(i),l.on("close.bs.alert",function(e){e.preventDefault();var i=t(e.currentTarget);i.clearQueue().queue(function(e){i.removeClass("in"),e()}).slideUp(function(){i.remove()})}),l.appendTo(this.messageContainer),l.delay(200).queue(function(e){l.addClass("in"),e()}),r>0&&l.delay(1e3*r).queue(function(e){l.alert("close"),e()})},e.duration=5,e.messageContainer=null,e}();try{parent&&parent.window.TYPO3&&parent.window.TYPO3.Notification&&(s=parent.window.TYPO3.Notification),top&&top.TYPO3.Notification&&(s=top.TYPO3.Notification)}catch(e){}return s||(s=r,"undefined"!=typeof TYPO3&&(TYPO3.Notification=s)),s});
\ No newline at end of file