07fbd83c8919b794c2fefab1e430e95094069397
[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 ul").tabs("div.category");
7
8 $('#resetSearch').live('click', function (e) {
9 datatable.fnFilter('');
10 });
11
12 $('.onClickMaskExtensionManager').click(function() {
13 $('.typo3-extension-manager').mask();
14 });
15
16 resetSearchField();
17 });
18
19 function getUrlVars() {
20 var vars = [], hash;
21 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
22 for(var i = 0; i < hashes.length; i++) {
23 hash = hashes[i].split('=');
24 vars.push(hash[0]);
25 vars[hash[0]] = hash[1];
26 }
27 return vars;
28 }
29
30 function manageExtensionListing() {
31 datatable = $('#typo3-extension-list').dataTable({
32 "bPaginate": false,
33 "bJQueryUI":true,
34 "bLengthChange":false,
35 'iDisplayLength':15,
36 "bStateSave":true,
37 "fnDrawCallback": bindActions
38 });
39
40 var getVars = getUrlVars();
41
42 // restore filter
43 if(datatable.length && getVars['search']) {
44 datatable.fnFilter(getVars['search']);
45 }
46 }
47
48 function bindActions() {
49 $('.removeExtension').not('.transformed').each(function() {
50 $(this).data('href', $(this).attr('href'));
51 $(this).attr('href', '#');
52 $(this).addClass('transformed');
53 $(this).click(function() {
54 if ($(this).hasClass('isLoadedWarning')) {
55 TYPO3.Dialog.QuestionDialog({
56 title: TYPO3.l10n.localize('extensionList.removalConfirmation.title'),
57 msg: TYPO3.l10n.localize('extensionList.removalConfirmation.message'),
58 url: $(this).data('href'),
59 fn: function(button, dummy, dialog) {
60 if (button == 'yes') {
61 confirmDeletionAndDelete(dialog.url);
62 }
63 }
64 });
65 } else {
66 confirmDeletionAndDelete($(this).data('href'));
67 }
68 });
69 });
70
71 $('.t3-icon-system-extension-update').parent().each(function() {
72 $(this).data('href', $(this).attr('href'));
73 $(this).attr('href', '#');
74 $(this).addClass('transformed');
75 $(this).click(function() {
76 $('.typo3-extension-manager').mask();
77 $.ajax({
78 url: $(this).data('href'),
79 dataType: 'json',
80 success: updateExtension
81 });
82 });
83 });
84
85 }
86
87 function updateExtension(data) {
88 var message = '<h1>' + TYPO3.l10n.localize('extensionList.updateConfirmation.title') + '</h1>';
89 message += '<h2>' + TYPO3.l10n.localize('extensionList.updateConfirmation.message') + '</h2>';
90 $.each(data.updateComments, function(version, comment) {
91 message += '<h3>' + version + '</h3>';
92 message += '<div>' + comment + '</div>';
93 });
94
95 TYPO3.Dialog.QuestionDialog({
96 title: TYPO3.l10n.localize('extensionList.updateConfirmation.questionVersionComments'),
97 msg: message,
98 width: 600,
99 url: data.url,
100 fn: function(button, dummy, dialog) {
101 if (button == 'yes') {
102 $.ajax({
103 url: dialog.url,
104 dataType: 'json',
105 success: function(data) {
106 $('.typo3-extension-manager').unmask();
107 TYPO3.Flashmessage.display(TYPO3.Severity.information, TYPO3.l10n.localize('extensionList.updateFlashMessage.title'),
108 TYPO3.l10n.localize('extensionList.updateFlashMessage.message').replace(/\{0\}/g, data.extension), 15);
109 }
110 });
111 } else {
112 $('.typo3-extension-manager').unmask();
113 }
114 }
115 });
116 }
117
118 function confirmDeletionAndDelete(url) {
119 TYPO3.Dialog.QuestionDialog({
120 title: TYPO3.l10n.localize('extensionList.removalConfirmation.title'),
121 msg: TYPO3.l10n.localize('extensionList.removalConfirmation.question'),
122 url: url,
123 fn: function(button, dummy, dialog) {
124 if (button == 'yes') {
125 $('.typo3-extension-manager').mask();
126 $.ajax({
127 url: dialog.url,
128 dataType: 'json',
129 success: removeExtension
130 });
131 }
132 }
133 });
134 }
135
136 function removeExtension(data) {
137 $('.typo3-extension-manager').unmask();
138 if (data.success) {
139 datatable.fnDeleteRow(datatable.fnGetPosition(document.getElementById(data.extension)));
140 } else {
141 TYPO3.Flashmessage.display(TYPO3.Severity.error, TYPO3.l10n.localize('extensionList.removalConfirmation.title'), data.message, 15);
142 }
143 }
144
145 function resetSearchField() {
146 $('.dataTables_wrapper').find('.dataTables_filter').append($('<span />', {
147 'class':'t3-icon t3-icon-actions t3-icon-actions-input t3-icon-input-clear t3-tceforms-input-clearer',
148 'id':'resetSearch',
149 'style':'display:none'
150 }));
151 $('#typo3-extension-list_filter').mouseout(function() {
152 $(this).find('#resetSearch').css('display', 'none');
153 });
154 $('#typo3-extension-list_filter').mouseover(function() {
155 if ($(this).find('input').val()) {
156 $(this).find('#resetSearch').css('display', 'inline-block');
157 }
158 });
159 }
160 }(jQuery));