7ee39010724f67faddbf55f3babb23c73e857c1d
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Resources / Public / JavaScript / ter.js
1 // IIFE for faster access to $ and save $ use
2 (function ($) {
3
4 $(document).ready(function() {
5 $('#terTable').dataTable({
6 "bJQueryUI":true,
7 "bLengthChange": false,
8 'iDisplayLength': 15,
9 "bStateSave": false,
10 "bInfo": false,
11 "bPaginate": false,
12 "bFilter": false,
13 "bSort": false,
14 "fnDrawCallback": bindDownload,
15 "fnCookieCallback": function (sNameFile, oData, sExpires, sPath) {
16 // append mod.php to cookiePath to avoid sending cookie-data to images etc. without reason
17 return sNameFile + "=" + encodeURIComponent($.fn.dataTableExt.oApi._fnJsonString(oData)) + "; expires=" + sExpires +"; path=" + sPath + "mod.php";
18 }
19 });
20
21 $('#terVersionTable').dataTable({
22 "bJQueryUI":true,
23 "bLengthChange":false,
24 'iDisplayLength':15,
25 "bStateSave":false,
26 "bInfo":false,
27 "bPaginate":false,
28 "bFilter":false,
29 "fnDrawCallback":bindDownload,
30 "fnCookieCallback": function (sNameFile, oData, sExpires, sPath) {
31 // append mod.php to cookiePath to avoid sending cookie-data to images etc. without reason
32 return sNameFile + "=" + encodeURIComponent($.fn.dataTableExt.oApi._fnJsonString(oData)) + "; expires=" + sExpires +"; path=" + sPath + "mod.php";
33 },
34 "aaSorting": [
35 [2, 'asc']
36 ],
37 'aoColumns': [
38 { 'bSortable': false },
39 null,
40 { 'sType': 'version' },
41 null,
42 null,
43 null
44 ]
45 });
46
47 $('#terSearchTable').dataTable({
48 "bPaginate": false,
49 "bJQueryUI":true,
50 "bLengthChange": false,
51 'iDisplayLength': 15,
52 "bStateSave": false,
53 "bFilter": false,
54 "oLanguage": {
55 "sSearch": "Filter results:"
56 },
57 "bSort": false,
58 "fnDrawCallback": bindDownload,
59 "fnCookieCallback": function (sNameFile, oData, sExpires, sPath) {
60 // append mod.php to cookiePath to avoid sending cookie-data to images etc. without reason
61 return sNameFile + "=" + encodeURIComponent($.fn.dataTableExt.oApi._fnJsonString(oData)) + "; expires=" + sExpires +"; path=" + sPath + "mod.php";
62 }
63 });
64
65 bindDownload();
66 bindSearchFieldResetter();
67 });
68
69 function bindDownload() {
70 var installButtons = $('.downloadFromTer form.download input[type=submit]');
71 installButtons.off('click');
72 installButtons.on('click', function(event) {
73 event.preventDefault();
74 $('.typo3-extension-manager').mask();
75 var url = $(event.currentTarget.form).attr('href');
76 downloadPath = $(event.currentTarget.form).find('input.downloadPath:checked').val();
77 $.ajax({
78 url: url,
79 dataType: 'json',
80 success: getDependencies
81 });
82 });
83 }
84
85 function getDependencies(data) {
86 if (data.hasDependencies) {
87 TYPO3.Dialog.QuestionDialog({
88 title: data.title,
89 msg: data.message,
90 url: data.url + '&tx_extensionmanager_tools_extensionmanagerextensionmanager[downloadPath]=' + downloadPath,
91 fn: getResolveDependenciesAndInstallResult
92 });
93 } else {
94 if(data.hasErrors) {
95 $('.typo3-extension-manager').unmask();
96 TYPO3.Flashmessage.display(TYPO3.Severity.error, data.title, data.message, 15);
97 } else {
98 var button = 'yes';
99 var dialog = [];
100 var dummy = '';
101 dialog['url'] = data.url + '&tx_extensionmanager_tools_extensionmanagerextensionmanager[downloadPath]=' + downloadPath;
102 getResolveDependenciesAndInstallResult(button, dummy, dialog);
103 }
104 }
105 return false;
106 }
107
108 function getResolveDependenciesAndInstallResult(button, dummy, dialog) {
109 if (button == 'yes') {
110 var newUrl = dialog.url;
111 $.ajax({
112 url: newUrl,
113 dataType: 'json',
114 success: function (data) {
115 $('.typo3-extension-manager').unmask();
116 if (data.errorCount > 0) {
117 TYPO3.Dialog.QuestionDialog({
118 title: data.errorTitle,
119 msg: data.errorMessage,
120 url: data.skipDependencyUri,
121 fn: function (button, dummy, dialog) {
122 if (button == 'yes') {
123 $('.typo3-extension-manager').mask();
124 getResolveDependenciesAndInstallResult('yes', dummy, dialog);
125 }
126 }
127 });
128 } else {
129 var successMessage = TYPO3.l10n.localize('extensionList.dependenciesResolveDownloadSuccess.message').replace(/\{0\}/g, data.extension) + ' <br />';
130 successMessage += '<br /><h3>' + TYPO3.l10n.localize('extensionList.dependenciesResolveDownloadSuccess.header') + ':</h3>';
131 $.each(data.result, function(index, value) {
132 successMessage += TYPO3.l10n.localize('extensionList.dependenciesResolveDownloadSuccess.item') + ' ' + index + ':<br /><ul>';
133 $.each(value, function(extkey, extdata) {
134 successMessage += '<li>' + extkey + '</li>';
135 });
136 successMessage += '</ul>';
137 });
138 TYPO3.Flashmessage.display(TYPO3.Severity.information, TYPO3.l10n.localize('extensionList.dependenciesResolveFlashMessage.title').replace(/\{0\}/g, data.extension), successMessage, 15);
139 }
140 }
141 });
142 } else {
143 $('.typo3-extension-manager').unmask();
144 }
145 }
146
147 function bindSearchFieldResetter() {
148
149 var $searchFields = $('.typo3-extensionmanager-searchTerForm input[type="text"]');
150 var searchResultShown = '' !== $searchFields.first().val();
151
152 $searchFields.clearable(
153 {
154 onClear: function() {
155 if (searchResultShown) {
156 $(this).parents('form').first().submit();
157 }
158 }
159 }
160 );
161 }
162 }(jQuery));