[TASK] Drop faulty getIcons() method from "Icons" module
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / Toolbar / ClearCacheMenu.js
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13
14 /**
15 * main functionality for clearing caches via the top bar
16 * reloading the clear cache icon
17 */
18 define(['jquery', 'TYPO3/CMS/Backend/Icons'], function($, Icons) {
19 'use strict';
20
21 var ClearCacheMenu = {
22 options: {
23 containerSelector: '#typo3-cms-backend-backend-toolbaritems-clearcachetoolbaritem',
24 menuItemSelector: '.dropdown-menu a',
25 toolbarIconSelector: '.dropdown-toggle span.icon'
26 }
27 };
28
29 /**
30 * Registers listeners for the icons inside the dropdown to trigger
31 * the clear cache call
32 */
33 ClearCacheMenu.initializeEvents = function() {
34 $(ClearCacheMenu.options.containerSelector).on('click', ClearCacheMenu.options.menuItemSelector, function(evt) {
35 evt.preventDefault();
36 var ajaxUrl = $(this).attr('href');
37 if (ajaxUrl) {
38 ClearCacheMenu.clearCache(ajaxUrl);
39 }
40 });
41 };
42
43 /**
44 * calls TYPO3 to clear a cache, then changes the topbar icon
45 * to a spinner. Once done, restores the original topbar icon
46 *
47 * @param ajaxUrl the URL to load
48 */
49 ClearCacheMenu.clearCache = function(ajaxUrl) {
50 // Close clear cache menu
51 $(ClearCacheMenu.options.containerSelector).removeClass('open');
52
53 var $toolbarItemIcon = $(ClearCacheMenu.options.toolbarIconSelector, ClearCacheMenu.options.containerSelector),
54 $existingIcon = $toolbarItemIcon.clone();
55
56 Icons.getIcon('spinner-circle-light', Icons.sizes.small).done(function(spinner) {
57 $toolbarItemIcon.replaceWith(spinner);
58 });
59
60 $.ajax({
61 url: ajaxUrl,
62 type: 'post',
63 cache: false,
64 success: function() {
65 $(ClearCacheMenu.options.toolbarIconSelector, ClearCacheMenu.options.containerSelector).replaceWith($existingIcon);
66 }
67 });
68 };
69
70 $(ClearCacheMenu.initializeEvents);
71
72 return ClearCacheMenu;
73 });