9958541d75002b5e831da151f829deebeaeb134d
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Resources / Public / JavaScript / main.js
1 // IIFE for faster access to $ and save $ use
2 (function ($) {
3
4 $(document).ready(function() {
5 manageExtensionListing();
6 $("#typo3-extension-configuration-forms").tabs();
7
8 $('.onClickMaskExtensionManager').click(function() {
9 $('.typo3-extension-manager').mask();
10 });
11
12 $('.dataTables_wrapper .dataTables_filter input').clearable({
13 onClear: function() {
14 datatable.fnFilter('');
15 }
16 });
17
18 $('.expandable').expander({
19 expandEffect: 'slideDown',
20 collapseEffect: 'slideUp',
21 beforeExpand: function() {
22 $(this).parent().css('z-index', 199);
23 },
24 afterCollapse: function() {
25 $(this).parent().css('z-index', 1);
26 }
27 });
28
29 $('.t3-button-action-installdistribution').click(function(){
30 $('.typo3-extension-manager').mask();
31 });
32
33 });
34
35 function getUrlVars() {
36 var vars = [], hash;
37 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
38 for(var i = 0; i < hashes.length; i++) {
39 hash = hashes[i].split('=');
40 vars.push(hash[0]);
41 vars[hash[0]] = hash[1];
42 }
43 return vars;
44 }
45
46 function manageExtensionListing() {
47 datatable = $('#typo3-extension-list').dataTable({
48 "bPaginate": false,
49 "bJQueryUI":true,
50 "bLengthChange":false,
51 'iDisplayLength':15,
52 "oLanguage": {"sSearch": TYPO3.l10n.localize('extensionList.search')},
53 "bStateSave":true,
54 "fnDrawCallback": bindActions,
55 "fnCookieCallback": function (sNameFile, oData, sExpires, sPath) {
56 // append mod.php to cookiePath to avoid sending cookie-data to images etc. without reason
57 return sNameFile + "=" + encodeURIComponent($.fn.dataTableExt.oApi._fnJsonString(oData)) + "; expires=" + sExpires +"; path=" + sPath + "mod.php";
58 },
59 'aoColumns': [
60 null,
61 null,
62 null,
63 null,
64 { 'sType': 'version' },
65 { 'bSortable': false },
66 null
67 ]
68 });
69
70 var getVars = getUrlVars();
71
72 // restore filter
73 if(datatable.length && getVars['search']) {
74 datatable.fnFilter(getVars['search']);
75 }
76 }
77
78 $.fn.dataTableExt.oSort['version-asc'] = function(a, b) {
79 var result = compare(a,b);
80 result = result * -1;
81 return result;
82 };
83
84 $.fn.dataTableExt.oSort['version-desc'] = function(a, b) {
85 var result = compare(a,b);
86 return result;
87 };
88
89 function compare(a, b) {
90 if (a === b) {
91 return 0;
92 }
93
94 var a_components = a.split(".");
95 var b_components = b.split(".");
96
97 var len = Math.min(a_components.length, b_components.length);
98
99 // loop while the components are equal
100 for (var i = 0; i < len; i++) {
101 // A bigger than B
102 if (parseInt(a_components[i]) > parseInt(b_components[i])) {
103 return 1;
104 }
105
106 // B bigger than A
107 if (parseInt(a_components[i]) < parseInt(b_components[i])) {
108 return -1;
109 }
110 }
111
112 // If one's a prefix of the other, the longer one is greater.
113 if (a_components.length > b_components.length) {
114 return 1;
115 }
116
117 if (a_components.length < b_components.length) {
118 return -1;
119 }
120 // Otherwise they are the same.
121 return 0;
122 }
123
124 function bindActions() {
125 $('.removeExtension').not('.transformed').each(function() {
126 $(this).data('href', $(this).attr('href'));
127 $(this).attr('href', '#');
128 $(this).addClass('transformed');
129 $(this).click(function() {
130 TYPO3.Dialog.QuestionDialog({
131 title: TYPO3.l10n.localize('extensionList.removalConfirmation.title'),
132 msg: TYPO3.l10n.localize('extensionList.removalConfirmation.question'),
133 url: $(this).data('href'),
134 fn: function(button, dummy, dialog) {
135 if (button == 'yes') {
136 $('.typo3-extension-manager').mask();
137 $.ajax({
138 url: dialog.url,
139 success: function() {
140 location.reload();
141 },
142 error: function() {
143 $('.typo3-extension-manager').unmask();
144 }
145 });
146 }
147 }
148 });
149 });
150 });
151
152 $('.t3-icon-system-extension-update').parent().each(function() {
153 $(this).data('href', $(this).attr('href'));
154 $(this).attr('href', '#');
155 $(this).addClass('transformed');
156 $(this).click(function() {
157 $('.typo3-extension-manager').mask();
158 $.ajax({
159 url: $(this).data('href'),
160 dataType: 'json',
161 success: updateExtension
162 });
163 });
164 });
165 }
166
167 function updateExtension(data) {
168 var message = '<h1>' + TYPO3.l10n.localize('extensionList.updateConfirmation.title') + '</h1>';
169 message += '<h2>' + TYPO3.l10n.localize('extensionList.updateConfirmation.message') + '</h2>';
170 $.each(data.updateComments, function(version, comment) {
171 message += '<h3>' + version + '</h3>';
172 message += '<div>' + comment + '</div>';
173 });
174
175 TYPO3.Dialog.QuestionDialog({
176 title: TYPO3.l10n.localize('extensionList.updateConfirmation.questionVersionComments'),
177 msg: message,
178 width: 600,
179 url: data.url,
180 fn: function(button, dummy, dialog) {
181 if (button == 'yes') {
182 $.ajax({
183 url: dialog.url,
184 dataType: 'json',
185 success: function(data) {
186 if (data.hasErrors) {
187 top.TYPO3.Flashmessage.display(
188 top.TYPO3.Severity.error,
189 TYPO3.l10n.localize('downloadExtension.updateExtension.error'),
190 data.errorMessage,
191 15
192 );
193 } else {
194 top.TYPO3.Flashmessage.display(
195 top.TYPO3.Severity.info,
196 TYPO3.l10n.localize('extensionList.updateFlashMessage.title'),
197 TYPO3.l10n.localize('extensionList.updateFlashMessage.message').replace(/\{0\}/g, data.extension),
198 15
199 );
200 }
201 $('.typo3-extension-manager').unmask();
202 },
203 error: function(jqXHR, textStatus, errorThrown) {
204 // Create an error message with diagnosis info.
205 var errorMessage = textStatus + '(' + errorThrown + '): ' + jqXHR.responseText;
206
207 top.TYPO3.Flashmessage.display(
208 top.TYPO3.Severity.error,
209 TYPO3.l10n.localize('downloadExtension.updateExtension.error'),
210 errorMessage,
211 15
212 );
213 $('.typo3-extension-manager').unmask();
214 }
215 });
216 } else {
217 $('.typo3-extension-manager').unmask();
218 }
219 }
220 });
221 }
222 }(jQuery));