7c7bc554f9fbdcaf176d8b33fdef530e31b92519
[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 });
16
17 $('#terVersionTable').dataTable({
18 "bJQueryUI":true,
19 "bLengthChange":false,
20 'iDisplayLength':15,
21 "bStateSave":false,
22 "bInfo":false,
23 "bPaginate":false,
24 "bFilter":false,
25 "fnDrawCallback":bindDownload,
26 'aoColumns': [
27 { 'bSortable': false },
28 null,
29 { 'sType': 'version' },
30 null,
31 null,
32 null
33 ]
34 });
35
36 $('#terSearchTable').dataTable({
37 "bPaginate": false,
38 "bJQueryUI":true,
39 "bLengthChange": false,
40 'iDisplayLength': 15,
41 "bStateSave": false,
42 "bFilter": false,
43 "oLanguage": {
44 "sSearch": "Filter results:"
45 },
46 "bSort": false,
47 "fnDrawCallback": bindDownload
48 });
49
50 bindDownload();
51 bindSearchFieldResetter();
52 });
53
54 function bindDownload() {
55 var installButtons = $('.downloadFromTer form.download input[type=submit]');
56 installButtons.off('click');
57 installButtons.on('click', function(event) {
58 event.preventDefault();
59 var url = $(event.currentTarget.form).attr('href');
60 downloadPath = $(event.currentTarget.form).find('input.downloadPath:checked').val();
61 $.ajax({
62 url: url,
63 dataType: 'json',
64 success: getDependencies
65 });
66 });
67 }
68
69 function getDependencies(data) {
70 if (data.hasDependencies) {
71 TYPO3.Dialog.QuestionDialog({
72 title: data.title,
73 msg: data.message,
74 url: data.url + '&tx_extensionmanager_tools_extensionmanagerextensionmanager[downloadPath]=' + downloadPath,
75 fn: getResolveDependenciesAndInstallResult
76 });
77 } else {
78 if(data.hasErrors) {
79 TYPO3.Flashmessage.display(TYPO3.Severity.error, data.title, data.message, 10);
80 } else {
81 var button = 'yes';
82 var dialog = [];
83 var dummy = '';
84 dialog['url'] = data.url + '&tx_extensionmanager_tools_extensionmanagerextensionmanager[downloadPath]=' + downloadPath;
85 getResolveDependenciesAndInstallResult(button, dummy, dialog);
86 }
87 }
88 return false;
89 }
90
91 function getResolveDependenciesAndInstallResult(button, dummy, dialog) {
92 if (button == 'yes') {
93 var newUrl = dialog.url;
94 $.ajax({
95 url: newUrl,
96 dataType: 'json',
97 success: function (data) {
98 $('.typo3-extension-manager').unmask();
99 if (data.errorMessage.length) {
100 TYPO3.Flashmessage.display(TYPO3.Severity.error, TYPO3.l10n.localize('extensionList.dependenciesResolveDownloadError.title'), data.errorMessage, 5);
101 } else {
102 var successMessage = TYPO3.l10n.localize('extensionList.dependenciesResolveDownloadSuccess.message').replace(/\{0\}/g, data.extension) + ' <br />';
103 successMessage += '<br /><h3>' + TYPO3.l10n.localize('extensionList.dependenciesResolveDownloadSuccess.header') + ':</h3>';
104 $.each(data.result, function(index, value) {
105 successMessage += TYPO3.l10n.localize('extensionList.dependenciesResolveDownloadSuccess.item') + ' ' + index + ':<br /><ul>';
106 $.each(value, function(extkey, extdata) {
107 successMessage += '<li>' + extkey + '</li>';
108 });
109 successMessage += '</ul>';
110 });
111 TYPO3.Flashmessage.display(TYPO3.Severity.information, TYPO3.l10n.localize('extensionList.dependenciesResolveFlashMessage.title').replace(/\{0\}/g, data.extension), successMessage, 15);
112 }
113 }
114 });
115 } else {
116 $('.typo3-extension-manager').unmask();
117 }
118 }
119
120 function bindSearchFieldResetter() {
121
122 var $searchFields = $('.typo3-extensionmanager-searchTerForm input[type="text"]');
123 var searchResultShown = '' !== $searchFields.first().val();
124
125 $searchFields.clearable(
126 {
127 onClear: function() {
128 if (searchResultShown) {
129 $(this).parents('form').first().submit();
130 }
131 }
132 }
133 );
134 }
135 }(jQuery));