[TASK] Migrate Toolbar/ClearCacheMenu to TypeScript 02/56002/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Sun, 4 Mar 2018 17:35:45 +0000 (18:35 +0100)
committerBenni Mack <benni@typo3.org>
Sun, 4 Mar 2018 21:57:43 +0000 (22:57 +0100)
Resolves: #84127
Releases: master
Change-Id: I60ee74644a04354e6939aa8e5acc452004e1f582
Reviewed-on: https://review.typo3.org/56002
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/ClearCacheMenu.ts [new file with mode: 0644]
typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/ClearCacheMenu.js

diff --git a/typo3/sysext/backend/Resources/Private/TypeScript/Toolbar/ClearCacheMenu.ts b/typo3/sysext/backend/Resources/Private/TypeScript/Toolbar/ClearCacheMenu.ts
new file mode 100644 (file)
index 0000000..f8de18f
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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 Notification = require('../Notification');
+import Viewport = require('../Viewport');
+
+enum Identifiers {
+  containerSelector = '#typo3-cms-backend-backend-toolbaritems-clearcachetoolbaritem',
+  menuItemSelector = 'a.toolbar-cache-flush-action',
+  toolbarIconSelector = '.toolbar-item-icon .t3js-icon'
+}
+
+/**
+ * Module: TYPO3/CMS/Backend/Toolbar/ClearCacheMenu
+ * main functionality for clearing caches via the top bar
+ * reloading the clear cache icon
+ */
+class ClearCacheMenu {
+  constructor() {
+    Viewport.Topbar.Toolbar.registerEvent(this.initializeEvents);
+  }
+
+  /**
+   * Registers listeners for the icons inside the dropdown to trigger
+   * the clear cache call
+   */
+  private initializeEvents = (): void => {
+    $(Identifiers.containerSelector).on('click', Identifiers.menuItemSelector, (evt: JQueryEventObject): void => {
+      evt.preventDefault();
+      const ajaxUrl = $(evt.currentTarget).attr('href');
+      if (ajaxUrl) {
+        this.clearCache(ajaxUrl);
+      }
+    });
+  }
+
+  /**
+   * Calls TYPO3 to clear a cache, then changes the topbar icon
+   * to a spinner. Restores the original topbar icon when the request completed.
+   *
+   * @param {string} ajaxUrl The URL to load
+   */
+  private clearCache(ajaxUrl: string): void {
+    // Close clear cache menu
+    $(Identifiers.containerSelector).removeClass('open');
+
+    const $toolbarItemIcon = $(Identifiers.toolbarIconSelector, Identifiers.containerSelector);
+    const $existingIcon = $toolbarItemIcon.clone();
+
+    Icons.getIcon('spinner-circle-light', Icons.sizes.small).done((spinner: string): void => {
+      $toolbarItemIcon.replaceWith(spinner);
+    });
+
+    $.ajax({
+      url: ajaxUrl,
+      type: 'post',
+      cache: false,
+      complete: (jqXHRObject: JQueryXHR, status: string): void => {
+        $(Identifiers.toolbarIconSelector, Identifiers.containerSelector).replaceWith($existingIcon);
+        if (status !== 'success' || jqXHRObject.responseText !== '') {
+          Notification.error(
+            'An error occurred',
+            'An error occurred while clearing the cache. It is likely not all caches were cleared as expected.'
+          );
+        }
+      }
+    });
+  }
+}
+
+export = new ClearCacheMenu();
index 88a00a2..1841d89 100644 (file)
  *
  * The TYPO3 project - inspiring people to share!
  */
  *
  * The TYPO3 project - inspiring people to share!
  */
-
-/**
- * Module: TYPO3/CMS/Backend/Toolbar/ClearCacheMenu
- * main functionality for clearing caches via the top bar
- * reloading the clear cache icon
- */
-define([
-  'jquery',
-  'TYPO3/CMS/Backend/Icons',
-  'TYPO3/CMS/Backend/Notification',
-  'TYPO3/CMS/Backend/Viewport'
-], function($, Icons, Notification, Viewport) {
-  'use strict';
-
-  /**
-   *
-   * @type {{options: {containerSelector: string, menuItemSelector: string, toolbarIconSelector: string}}}
-   * @exports TYPO3/CMS/Backend/Toolbar/ClearCacheMenu
-   */
-  var ClearCacheMenu = {
-    options: {
-      containerSelector: '#typo3-cms-backend-backend-toolbaritems-clearcachetoolbaritem',
-      menuItemSelector: 'a.toolbar-cache-flush-action',
-      toolbarIconSelector: '.toolbar-item-icon .t3js-icon'
-    }
-  };
-
-  /**
-   * Registers listeners for the icons inside the dropdown to trigger
-   * the clear cache call
-   */
-  ClearCacheMenu.initializeEvents = function() {
-    $(ClearCacheMenu.options.containerSelector).on('click', ClearCacheMenu.options.menuItemSelector, function(evt) {
-      evt.preventDefault();
-      var ajaxUrl = $(this).attr('href');
-      if (ajaxUrl) {
-        ClearCacheMenu.clearCache(ajaxUrl);
-      }
-    });
-  };
-
-  /**
-   * calls TYPO3 to clear a cache, then changes the topbar icon
-   * to a spinner. Restores the original topbar icon when the request completed.
-   *
-   * @param {String} ajaxUrl the URL to load
-   */
-  ClearCacheMenu.clearCache = function(ajaxUrl) {
-    // Close clear cache menu
-    $(ClearCacheMenu.options.containerSelector).removeClass('open');
-
-    var $toolbarItemIcon = $(ClearCacheMenu.options.toolbarIconSelector, ClearCacheMenu.options.containerSelector),
-      $existingIcon = $toolbarItemIcon.clone();
-
-    Icons.getIcon('spinner-circle-light', Icons.sizes.small).done(function(spinner) {
-      $toolbarItemIcon.replaceWith(spinner);
-    });
-
-    $.ajax({
-      url: ajaxUrl,
-      type: 'post',
-      cache: false,
-      complete: function(jqXHRObject, status) {
-        $(ClearCacheMenu.options.toolbarIconSelector, ClearCacheMenu.options.containerSelector).replaceWith($existingIcon);
-        if (status !== 'success' || jqXHRObject.responseText !== '') {
-          Notification.error('An error occurs', 'An error occurred while clearing the cache. It is likely not all caches were cleared as expected.', 0);
-        }
-      }
-    });
-  };
-
-  Viewport.Topbar.Toolbar.registerEvent(ClearCacheMenu.initializeEvents);
-
-  return ClearCacheMenu;
-});
+define(["require","exports","jquery","../Icons","../Notification","../Viewport"],function(e,t,r,c,o,n){"use strict";var i,a;return(a=i||(i={})).containerSelector="#typo3-cms-backend-backend-toolbaritems-clearcachetoolbaritem",a.menuItemSelector="a.toolbar-cache-flush-action",a.toolbarIconSelector=".toolbar-item-icon .t3js-icon",new(function(){function e(){var e=this;this.initializeEvents=function(){r(i.containerSelector).on("click",i.menuItemSelector,function(t){t.preventDefault();var c=r(t.currentTarget).attr("href");c&&e.clearCache(c)})},n.Topbar.Toolbar.registerEvent(this.initializeEvents)}return e.prototype.clearCache=function(e){r(i.containerSelector).removeClass("open");var t=r(i.toolbarIconSelector,i.containerSelector),n=t.clone();c.getIcon("spinner-circle-light",c.sizes.small).done(function(e){t.replaceWith(e)}),r.ajax({url:e,type:"post",cache:!1,complete:function(e,t){r(i.toolbarIconSelector,i.containerSelector).replaceWith(n),"success"===t&&""===e.responseText||o.error("An error occurred","An error occurred while clearing the cache. It is likely not all caches were cleared as expected.")}})},e}())});
\ No newline at end of file