c6c0f884a4f3b59b79ef80fce55d79a35414dbc4
[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
40 $.ajax({
41 url: url,
42 dataType: 'json',
43 cache: false,
44 success: function(data) {
45
46 // Something went wrong, show message
47 if (data.errorMessage.length) {
48 TYPO3.Flashmessage.display(TYPO3.Severity.warning, TYPO3.l10n.localize('extensionList.updateFromTerFlashMessage.title'), data.errorMessage, 10);
49 }
50
51 // Message with latest updates
52 var $lastUpdate = $('.update-from-ter .time-since-last-update');
53 $lastUpdate.text(data.timeSinceLastUpdate);
54 $lastUpdate.attr(
55 'title',
56 TYPO3.l10n.localize('extensionList.updateFromTer.lastUpdate.timeOfLastUpdate') + data.lastUpdateTime
57 );
58
59 if (data.updated) {
60 $.ajax({
61 url: window.location.href + '&tx_extensionmanager_tools_extensionmanagerextensionmanager%5Bformat%5D=json',
62 dataType: 'json',
63 success: function(data) {
64 $('#terTableWrapper').html(
65 data
66 );
67 transformPaginatorToAjax();
68 }
69 });
70 }
71 },
72 error: function(jqXHR, textStatus, errorThrown) {
73 // Create an error message with diagnosis info.
74 var errorMessage = textStatus + '(' + errorThrown + '): ' + jqXHR.responseText;
75
76
77 TYPO3.Flashmessage.display(
78 TYPO3.Severity.warning,
79 TYPO3.l10n.localize('extensionList.updateFromTerFlashMessage.title'),
80 errorMessage,
81 10
82 );
83 },
84 complete: function() {
85
86 // Hide loaders
87 $('.splash-receivedata').removeClass('is-shown');
88 $('#terTable_wrapper').removeClass('is-loading');
89
90 // Show triggers for TER-update
91 $('.update-from-ter').removeClass('is-hidden');
92 }
93 });
94 }
95
96 function transformPaginatorToAjax() {
97 $('#typo3-dblist-pagination a').each(function() {
98 $(this).data('href', $(this).attr('href'));
99 $(this).attr('href', '#');
100 $(this).click(function() {
101 $('#terTableWrapper').mask();
102 $.ajax({
103 url: $(this).data('href'),
104 dataType: 'json',
105 success: function(data) {
106 $('#terTableWrapper').html(
107 data
108 );
109 $('#terTableWrapper').unmask();
110 transformPaginatorToAjax();
111 }
112 });
113 });
114 });
115 }
116
117 }(jQuery));