12b071d69497954d56f07b351bf2bef1cd8611f6
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Resources / Public / JavaScript / Modules / ClearTypo3tempFiles.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 * Module: TYPO3/CMS/Install/ClearTypo3tempFiles
16 */
17 define([
18 'jquery',
19 'TYPO3/CMS/Install/Router',
20 'TYPO3/CMS/Install/FlashMessage',
21 'TYPO3/CMS/Install/ProgressBar',
22 'TYPO3/CMS/Install/InfoBox',
23 'TYPO3/CMS/Install/Severity',
24 'TYPO3/CMS/Backend/Notification'
25 ], function($, Router, FlashMessage, ProgressBar, InfoBox, Severity, Notification) {
26 'use strict';
27
28 return {
29 selectorModalBody: '.t3js-modal-body',
30 selectorModuleContent: '.t3js-module-content',
31 selectorDeleteTrigger: '.t3js-clearTypo3temp-delete',
32 selectorOutputContainer: '.t3js-clearTypo3temp-output',
33 selectorStatContainer: '.t3js-clearTypo3temp-stat-container',
34 selectorStatsTrigger: '.t3js-clearTypo3temp-stats',
35 selectorStatTemplate: '.t3js-clearTypo3temp-stat-template',
36 selectorStatDescription: '.t3js-clearTypo3temp-stat-description',
37 selectorStatNumberOfFiles: '.t3js-clearTypo3temp-stat-numberOfFiles',
38 selectorStatDirectory: '.t3js-clearTypo3temp-stat-directory',
39 selectorStatName: '.t3js-clearTypo3temp-stat-name',
40 selectorStatLastRuler: '.t3js-clearTypo3temp-stat-lastRuler',
41 currentModal: {},
42
43 initialize: function(currentModal) {
44 var self = this;
45 this.currentModal = currentModal;
46 self.getStats();
47
48 currentModal.on('click', this.selectorStatsTrigger, function(e) {
49 e.preventDefault();
50 $(self.selectorOutputContainer).empty();
51 self.getStats();
52 });
53 currentModal.on('click', this.selectorDeleteTrigger, function(e) {
54 var folder = $(this).data('folder');
55 e.preventDefault();
56 self.delete(folder);
57 });
58 },
59
60 getStats: function() {
61 var self = this;
62 var modalContent = this.currentModal.find(self.selectorModalBody);
63 $.ajax({
64 url: Router.getUrl('clearTypo3tempFilesStats'),
65 cache: false,
66 success: function(data) {
67 if (data.success === true) {
68 modalContent.empty().append(data.html);
69 if (Array.isArray(data.stats) && data.stats.length > 0) {
70 data.stats.forEach(function(element) {
71 if (element.numberOfFiles > 0) {
72 var aStat = modalContent.find(self.selectorStatTemplate).clone();
73 aStat.find(self.selectorStatNumberOfFiles).text(element.numberOfFiles);
74 aStat.find(self.selectorStatDirectory).text(element.directory);
75 aStat.find(self.selectorDeleteTrigger).attr('data-folder', element.directory);
76 modalContent.find(self.selectorStatContainer).append(aStat.html());
77 }
78 });
79 }
80 } else {
81 Notification.error('Something went wrong');
82 }
83 },
84 error: function(xhr) {
85 Router.handleAjaxError(xhr);
86 }
87 });
88 },
89
90 delete: function(folder) {
91 var self = this;
92 var executeToken = self.currentModal.find(this.selectorModuleContent).data('clear-typo3temp-delete-token');
93 $.ajax({
94 method: 'POST',
95 url: Router.getUrl(),
96 context: this,
97 data: {
98 'install': {
99 'action': 'clearTypo3tempFiles',
100 'token': executeToken,
101 'folder': folder
102 }
103 },
104 cache: false,
105 success: function(data) {
106 if (data.success === true && Array.isArray(data.status)) {
107 data.status.forEach(function(element) {
108 Notification.success(element.message);
109 });
110 this.getStats();
111 } else {
112 Notification.error('Something went wrong');
113 }
114 },
115 error: function(xhr) {
116 Router.handleAjaxError(xhr);
117 }
118 });
119 }
120 };
121 });