[BUGFIX] Render FlashMessages at ClearCache 81/61481/7
authorGuido Schmechel <guido.schmechel@brandung.de>
Thu, 8 Aug 2019 22:49:33 +0000 (00:49 +0200)
committerTobi Kretschmann <tobi@tobishome.de>
Tue, 15 Oct 2019 12:29:38 +0000 (14:29 +0200)
Custom Clear Cache implementations can provide their own summary of results.
The content of a JSON response can send a title and message to be displayed
as a Flash message. If an error occurs, a global error message is displayed.

Resolves: #88939
Releases: master, 9.5
Change-Id: I968a06f583bc6c58f9e406fdcb3b32871370b2d2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61481
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com>
Tested-by: Jörg Bösche <typo3@joergboesche.de>
Tested-by: Henning Liebe <h.liebe@neusta.de>
Tested-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Henning Liebe <h.liebe@neusta.de>
Reviewed-by: Felix P. <f.pachowsky@neusta.de>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Build/Sources/TypeScript/backend/Resources/Public/TypeScript/Toolbar/ClearCacheMenu.ts
typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/ClearCacheMenu.js

index 1bf537f..e7447b4 100644 (file)
@@ -67,15 +67,22 @@ class ClearCacheMenu {
       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.',
-          );
+      success: (data: any): void => {
+        if (data.success === true) {
+          Notification.success(data.title, data.message);
+        } else if (data.success === false) {
+          Notification.error(data.title, data.message);
         }
       },
+      error: (): void => {
+        Notification.error(
+          'An error occurred',
+          'An error occurred while clearing the cache. It is likely not all caches were cleared as expected.',
+        );
+      },
+      complete: (): void => {
+        $(Identifiers.toolbarIconSelector, Identifiers.containerSelector).replaceWith($existingIcon);
+      }
     });
   }
 }
index 20b61b1..f5d1a5d 100644 (file)
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","jquery","../Icons","../Notification","../Viewport"],function(e,t,r,c,o,n){"use strict";var a;!function(e){e.containerSelector="#typo3-cms-backend-backend-toolbaritems-clearcachetoolbaritem",e.menuItemSelector="a.toolbar-cache-flush-action",e.toolbarIconSelector=".toolbar-item-icon .t3js-icon"}(a||(a={}));return new class{constructor(){this.initializeEvents=(()=>{r(a.containerSelector).on("click",a.menuItemSelector,e=>{e.preventDefault();const t=r(e.currentTarget).attr("href");t&&this.clearCache(t)})}),n.Topbar.Toolbar.registerEvent(this.initializeEvents)}clearCache(e){r(a.containerSelector).removeClass("open");const t=r(a.toolbarIconSelector,a.containerSelector),n=t.clone();c.getIcon("spinner-circle-light",c.sizes.small).done(e=>{t.replaceWith(e)}),r.ajax({url:e,type:"post",cache:!1,complete:(e,t)=>{r(a.toolbarIconSelector,a.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.")}})}}});
\ No newline at end of file
+define(["require","exports","jquery","../Icons","../Notification","../Viewport"],function(e,c,r,t,o,n){"use strict";var a;!function(e){e.containerSelector="#typo3-cms-backend-backend-toolbaritems-clearcachetoolbaritem",e.menuItemSelector="a.toolbar-cache-flush-action",e.toolbarIconSelector=".toolbar-item-icon .t3js-icon"}(a||(a={}));return new class{constructor(){this.initializeEvents=(()=>{r(a.containerSelector).on("click",a.menuItemSelector,e=>{e.preventDefault();const c=r(e.currentTarget).attr("href");c&&this.clearCache(c)})}),n.Topbar.Toolbar.registerEvent(this.initializeEvents)}clearCache(e){r(a.containerSelector).removeClass("open");const c=r(a.toolbarIconSelector,a.containerSelector),n=c.clone();t.getIcon("spinner-circle-light",t.sizes.small).done(e=>{c.replaceWith(e)}),r.ajax({url:e,type:"post",cache:!1,success:e=>{!0===e.success?o.success(e.title,e.message):!1===e.success&&o.error(e.title,e.message)},error:()=>{o.error("An error occurred","An error occurred while clearing the cache. It is likely not all caches were cleared as expected.")},complete:()=>{r(a.toolbarIconSelector,a.containerSelector).replaceWith(n)}})}}});
\ No newline at end of file