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