88324d39535e2dca1301b67a3bc91ddc43c4622b
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Resources / Public / JavaScript / update.js
1 // IIFE for faster access to jQuery and save $ use
2 (function ($) {
3
4 $(document).ready(function() {
5
6 // Register "update from ter" action
7 $('.update-from-ter').each(function() {
8
9 // "this" is the form which updates the extension list from
10 // TER on submit
11 var updateURL = $(this).attr('action');
12 $(this).attr('action', '#');
13
14 $(this).submit(function() {
15 // Force update on click.
16 updateFromTer(updateURL, 1);
17
18 // Prevent normal submit action.
19 return false;
20 });
21
22 // This might give problems when there are more "update"-buttons,
23 // each one would trigger a TER-update.
24 updateFromTer(updateURL, 0);
25 });
26 });
27
28 function updateFromTer(url, forceUpdate) {
29 if (forceUpdate == 1) {
30 url = url + '&tx_extensionmanager_tools_extensionmanagerextensionmanager%5BforceUpdateCheck%5D=1';
31 }
32
33 // Hide triggers for TER update
34 $('.update-from-ter').addClass('is-hidden');
35
36 // Show loaders
37 $('.splash-receivedata').addClass('is-shown');
38 $('#terTable_wrapper').addClass('is-loading');
39 $('#typo3-dblist-pagination').addClass('is-loading');
40
41 $.ajax({
42 url: url,
43 dataType: 'json',
44 cache: false,
45 success: function(data) {
46
47 // Something went wrong, show message
48 if (data.errorMessage.length) {
49 TYPO3.Flashmessage.display(TYPO3.Severity.warning, TYPO3.l10n.localize('extensionList.updateFromTerFlashMessage.title'), data.errorMessage, 10);
50 }
51
52 // Message with latest updates
53 var $lastUpdate = $('.update-from-ter .time-since-last-update');
54 $lastUpdate.text(data.timeSinceLastUpdate);
55 $lastUpdate.attr(
56 'title',
57 TYPO3.l10n.localize('extensionList.updateFromTer.lastUpdate.timeOfLastUpdate') + data.lastUpdateTime
58 );
59
60 if (data.updated) {
61 $.ajax({
62 url: window.location.href + '&tx_extensionmanager_tools_extensionmanagerextensionmanager%5Bformat%5D=json',
63 dataType: 'json',
64 success: function(data) {
65 $('#terTableWrapper').html(
66 data
67 );
68 transformPaginatorToAjax();
69 }
70 });
71 }
72 },
73 error: function(jqXHR, textStatus, errorThrown) {
74 // Create an error message with diagnosis info.
75 var errorMessage = textStatus + '(' + errorThrown + '): ' + jqXHR.responseText;
76
77
78 TYPO3.Flashmessage.display(
79 TYPO3.Severity.warning,
80 TYPO3.l10n.localize('extensionList.updateFromTerFlashMessage.title'),
81 errorMessage,
82 10
83 );
84 },
85 complete: function() {
86
87 // Hide loaders
88 $('.splash-receivedata').removeClass('is-shown');
89 $('#terTable_wrapper').removeClass('is-loading');
90 $('#typo3-dblist-pagination').removeClass('is-loading');
91
92 // Show triggers for TER-update
93 $('.update-from-ter').removeClass('is-hidden');
94 }
95 });
96 }
97
98 function transformPaginatorToAjax() {
99 $('#typo3-dblist-pagination a').each(function() {
100 $(this).data('href', $(this).attr('href'));
101 $(this).attr('href', '#');
102 $(this).click(function() {
103 $('#terTableWrapper').mask();
104 $.ajax({
105 url: $(this).data('href'),
106 dataType: 'json',
107 success: function(data) {
108 $('#terTableWrapper').html(
109 data
110 );
111 $('#terTableWrapper').unmask();
112 transformPaginatorToAjax();
113 }
114 });
115 });
116 });
117 }
118
119 }(jQuery));