[TASK] Migrate Toolbar/SystemInformationMenu to TypeScript 03/56003/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Sun, 4 Mar 2018 17:50:26 +0000 (18:50 +0100)
committerBenni Mack <benni@typo3.org>
Sun, 4 Mar 2018 22:12:39 +0000 (23:12 +0100)
Resolves: #84129
Releases: master
Change-Id: Ifafd271ff12de3bfab1ff57fcf51d178ddac0a2a
Reviewed-on: https://review.typo3.org/56003
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: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/backend/Resources/Private/TypeScript/Toolbar/SystemInformationMenu.ts [new file with mode: 0644]
typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/SystemInformationMenu.js

diff --git a/typo3/sysext/backend/Resources/Private/TypeScript/Toolbar/SystemInformationMenu.ts b/typo3/sysext/backend/Resources/Private/TypeScript/Toolbar/SystemInformationMenu.ts
new file mode 100644 (file)
index 0000000..81b4666
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * 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 * as $ from 'jquery';
+import Icons = require('../Icons');
+import PersistentStorage = require('../Storage/Persistent');
+import Viewport = require('../Viewport');
+
+enum Identifiers {
+  containerSelector = '#typo3-cms-backend-backend-toolbaritems-systeminformationtoolbaritem',
+  toolbarIconSelector = '.toolbar-item-icon .t3js-icon',
+  menuContainerSelector = '.dropdown-menu',
+  moduleLinks = '.t3js-systeminformation-module',
+  counter = '.t3js-systeminformation-counter'
+}
+
+/**
+ * Module: TYPO3/CMS/Backend/Toolbar/SystemInformationMenu
+ * System information menu handler
+ */
+class SystemInformationMenu {
+  private timer: number = null;
+
+  /**
+   * Updates the counter
+   */
+  private static updateCounter(): void {
+    const $container = $(Identifiers.containerSelector).find(Identifiers.menuContainerSelector).find('.t3js-systeminformation-container');
+    const $counter = $(Identifiers.counter);
+    const count = $container.data('count');
+    const badgeClass = $container.data('severityclass');
+
+    $counter.text(count).toggle(parseInt(count, 10) > 0);
+
+    // ensure all default classes are available and previous
+    // (at this time in processing unknown) class is removed
+    $counter.removeClass();
+    $counter.addClass('t3js-systeminformation-counter toolbar-item-badge badge');
+    // badgeClass e.g. could be 'badge-info', 'badge-danger', ...
+    if (badgeClass !== '') {
+      $counter.addClass(badgeClass);
+    }
+  }
+
+  constructor() {
+    Viewport.Topbar.Toolbar.registerEvent(this.updateMenu);
+  }
+
+  private updateMenu = (): void => {
+    const $toolbarItemIcon = $(Identifiers.toolbarIconSelector, Identifiers.containerSelector);
+    const $existingIcon = $toolbarItemIcon.clone();
+    const $menuContainer = $(Identifiers.containerSelector).find(Identifiers.menuContainerSelector);
+
+    if (this.timer !== null) {
+      clearTimeout(this.timer);
+      this.timer = null;
+    }
+
+    Icons.getIcon('spinner-circle-light', Icons.sizes.small).done((spinner: string): void => {
+      $toolbarItemIcon.replaceWith(spinner);
+    });
+
+    $.ajax({
+      url: TYPO3.settings.ajaxUrls.systeminformation_render,
+      type: 'post',
+      cache: false,
+      success: (data: string): void => {
+        $menuContainer.html(data);
+        SystemInformationMenu.updateCounter();
+        $(Identifiers.moduleLinks).on('click', this.openModule);
+      },
+      complete: (): void => {
+        $(Identifiers.toolbarIconSelector, Identifiers.containerSelector).replaceWith($existingIcon);
+      }
+    }).done((): void => {
+      // reload error data every five minutes
+      this.timer = setTimeout(
+        this.updateMenu,
+        1000 * 300
+      );
+    });
+  }
+
+  /**
+   * Updates the UC and opens the linked module
+   *
+   * @param {Event} e
+   */
+  private openModule(e: JQueryEventObject): void {
+    e.preventDefault();
+    e.stopPropagation();
+
+    let storedSystemInformationSettings = {};
+    const moduleStorageObject: { [key: string]: Object } = {};
+    const requestedModule: string = $(e.currentTarget).data('modulename');
+    const moduleParams = $(e.currentTarget).data('moduleparams');
+    const timestamp = Math.floor((new Date()).getTime() / 1000);
+
+    if (PersistentStorage.isset('systeminformation')) {
+      storedSystemInformationSettings = JSON.parse(PersistentStorage.get('systeminformation'));
+    }
+
+    moduleStorageObject[requestedModule] = {lastAccess: timestamp};
+    $.extend(true, storedSystemInformationSettings, moduleStorageObject);
+    const $ajax = PersistentStorage.set('systeminformation', JSON.stringify(storedSystemInformationSettings));
+    $ajax.done((): void => {
+      // finally, open the module now
+      TYPO3.ModuleMenu.App.showModule(requestedModule, moduleParams);
+      Viewport.Topbar.refresh();
+    });
+  }
+}
+
+export = new SystemInformationMenu();
index 4349d0c..6b99d03 100644 (file)
  *
  * The TYPO3 project - inspiring people to share!
  */
-
-/**
- * Module: TYPO3/CMS/Backend/Toolbar/SystemInformationMenu
- * System information menu handler
- */
-define([
-  'jquery',
-  'TYPO3/CMS/Backend/Icons',
-  'TYPO3/CMS/Backend/Storage/Persistent',
-  'TYPO3/CMS/Backend/Viewport'
-], function($, Icons, PersistentStorage, Viewport) {
-  'use strict';
-
-  /**
-   *
-   * @type {{identifier: {containerSelector: string, toolbarIconSelector: string, menuContainerSelector: string, moduleLinks: string}, elements: {$counter: (*|jQuery|HTMLElement)}}}
-   * @exports TYPO3/CMS/Backend/Toolbar/SystemInformationMenu
-   */
-  var SystemInformationMenu = {
-    identifier: {
-      containerSelector: '#typo3-cms-backend-backend-toolbaritems-systeminformationtoolbaritem',
-      toolbarIconSelector: '.toolbar-item-icon .t3js-icon',
-      menuContainerSelector: '.dropdown-menu',
-      moduleLinks: '.t3js-systeminformation-module',
-      counter: '.t3js-systeminformation-counter'
-    }
-  };
-
-  /**
-   * Initialize the events
-   */
-  SystemInformationMenu.initialize = function() {
-    $(SystemInformationMenu.identifier.moduleLinks).on('click', SystemInformationMenu.openModule);
-  };
-
-  /**
-   * Timer for auto reloading the SystemInformation
-   */
-  SystemInformationMenu.timer = null;
-
-  /**
-   * Updates the menu
-   */
-  SystemInformationMenu.updateMenu = function() {
-    var $toolbarItemIcon = $(SystemInformationMenu.identifier.toolbarIconSelector, SystemInformationMenu.identifier.containerSelector),
-      $existingIcon = $toolbarItemIcon.clone(),
-      $menuContainer = $(SystemInformationMenu.identifier.containerSelector).find(SystemInformationMenu.identifier.menuContainerSelector);
-
-    if (SystemInformationMenu.timer !== null) {
-      clearTimeout(SystemInformationMenu.timer);
-      SystemInformationMenu.timer = null;
-    }
-
-    Icons.getIcon('spinner-circle-light', Icons.sizes.small).done(function(spinner) {
-      $toolbarItemIcon.replaceWith(spinner);
-    });
-
-    $.ajax({
-      url: TYPO3.settings.ajaxUrls['systeminformation_render'],
-      type: 'post',
-      cache: false,
-      success: function(data) {
-        $menuContainer.html(data);
-        SystemInformationMenu.updateCounter();
-
-        SystemInformationMenu.initialize();
-      },
-      complete: function() {
-        $(SystemInformationMenu.identifier.toolbarIconSelector, SystemInformationMenu.identifier.containerSelector).replaceWith($existingIcon);
-      }
-    }).done(function() {
-      // reload error data every five minutes
-      SystemInformationMenu.timer = setTimeout(
-        SystemInformationMenu.updateMenu,
-        1000 * 300
-      );
-    });
-  };
-
-  /**
-   * Updates the counter
-   */
-  SystemInformationMenu.updateCounter = function() {
-    var $container = $(SystemInformationMenu.identifier.containerSelector).find(SystemInformationMenu.identifier.menuContainerSelector).find('.t3js-systeminformation-container'),
-      $counter = $(SystemInformationMenu.identifier.counter),
-      count = $container.data('count'),
-      badgeClass = $container.data('severityclass');
-
-    $counter.text(count).toggle(parseInt(count) > 0);
-
-    // ensure all default classes are available and previous
-    // (at this time in processing unknown) class is removed
-    $counter.removeClass();
-    $counter.addClass('t3js-systeminformation-counter toolbar-item-badge badge');
-    // badgeClass e.g. could be 'badge-info', 'badge-danger', ...
-    if (badgeClass !== '') {
-      $counter.addClass(badgeClass);
-    }
-  };
-
-  /**
-   * Updates the UC and opens the linked module
-   *
-   * @param {Event} e
-   */
-  SystemInformationMenu.openModule = function(e) {
-    e.preventDefault();
-    e.stopPropagation();
-
-    var storedSystemInformationSettings = {},
-      moduleStorageObject = {},
-      requestedModule = $(e.currentTarget).data('modulename'),
-      moduleParams = $(e.currentTarget).data('moduleparams'),
-      timestamp = Math.floor((new Date()).getTime() / 1000);
-
-    if (PersistentStorage.isset('systeminformation')) {
-      storedSystemInformationSettings = JSON.parse(PersistentStorage.get('systeminformation'));
-    }
-
-    moduleStorageObject[requestedModule] = {lastAccess: timestamp};
-    $.extend(true, storedSystemInformationSettings, moduleStorageObject);
-    var $ajax = PersistentStorage.set('systeminformation', JSON.stringify(storedSystemInformationSettings));
-    $ajax.done(function() {
-      // finally, open the module now
-      TYPO3.ModuleMenu.App.showModule(requestedModule, moduleParams);
-      Viewport.Topbar.refresh();
-    });
-  };
-
-  Viewport.Topbar.Toolbar.registerEvent(SystemInformationMenu.updateMenu);
-
-  return SystemInformationMenu;
-});
+define(["require","exports","jquery","../Icons","../Storage/Persistent","../Viewport"],function(e,t,n,o,r,i){"use strict";var a,s;return(s=a||(a={})).containerSelector="#typo3-cms-backend-backend-toolbaritems-systeminformationtoolbaritem",s.toolbarIconSelector=".toolbar-item-icon .t3js-icon",s.menuContainerSelector=".dropdown-menu",s.moduleLinks=".t3js-systeminformation-module",s.counter=".t3js-systeminformation-counter",new(function(){function e(){var t=this;this.timer=null,this.updateMenu=function(){var r=n(a.toolbarIconSelector,a.containerSelector),i=r.clone(),s=n(a.containerSelector).find(a.menuContainerSelector);null!==t.timer&&(clearTimeout(t.timer),t.timer=null),o.getIcon("spinner-circle-light",o.sizes.small).done(function(e){r.replaceWith(e)}),n.ajax({url:TYPO3.settings.ajaxUrls.systeminformation_render,type:"post",cache:!1,success:function(o){s.html(o),e.updateCounter(),n(a.moduleLinks).on("click",t.openModule)},complete:function(){n(a.toolbarIconSelector,a.containerSelector).replaceWith(i)}}).done(function(){t.timer=setTimeout(t.updateMenu,3e5)})},i.Topbar.Toolbar.registerEvent(this.updateMenu)}return e.updateCounter=function(){var e=n(a.containerSelector).find(a.menuContainerSelector).find(".t3js-systeminformation-container"),t=n(a.counter),o=e.data("count"),r=e.data("severityclass");t.text(o).toggle(parseInt(o,10)>0),t.removeClass(),t.addClass("t3js-systeminformation-counter toolbar-item-badge badge"),""!==r&&t.addClass(r)},e.prototype.openModule=function(e){e.preventDefault(),e.stopPropagation();var t={},o={},a=n(e.currentTarget).data("modulename"),s=n(e.currentTarget).data("moduleparams"),c=Math.floor((new Date).getTime()/1e3);r.isset("systeminformation")&&(t=JSON.parse(r.get("systeminformation"))),o[a]={lastAccess:c},n.extend(!0,t,o),r.set("systeminformation",JSON.stringify(t)).done(function(){TYPO3.ModuleMenu.App.showModule(a,s),i.Topbar.refresh()})},e}())});
\ No newline at end of file