6791aba261caf45d140bce850401c48a3abf2a9e
37 aTargets
: ['notSortable']
39 "fnCookieCallback": function (sNameFile
, oData
, sExpires
, sPath
) {
40 // append mod.php to cookiePath to avoid sending cookie-data to images etc. without reason
41 return sNameFile
+ "=" + encodeURIComponent($.fn
.dataTableExt
.oApi
._fnJsonString(oData
)) + "; expires=" + sExpires
+"; path=" + sPath
+ "mod.php";
56 * Initialize the language module
60 initialize: function() {
61 // Initialize dataTable for selection and translation list
62 languageModule
.tableSetup
.sScrollY
= languageModule
.calculateTableHeight();
63 jQuery('.selectionList, .translationList').dataTable(languageModule
.tableSetup
);
65 // Prevent "jumping" style of the tables while generating
66 jQuery('.languageSelectionListContainer').css('visibility', 'visible');
67 jQuery('.translationUpdateListContainer').css('visibility', 'visible');
69 // Enable event handlers
70 languageModule
.toggleEventHandlers('on');
72 // Resize tables on window resize
73 jQuery(window
).resize(function() {
74 jQuery('div.dataTables_scrollBody').css('height', languageModule
.calculateTableHeight());
79 * Execute AJAX call for given cell of the translation matrix
81 * @param mixed cell The cell to process
84 processCell: function(cell
) {
86 var $cell
= jQuery(cell
);
87 languageModule
.toggleEventHandlers('off');
88 languageModule
.errorCount
= 0;
89 $cell
.html(jQuery('#stateIconChecking').html());
92 languageModule
.executeAjaxCall($cell
.data('updateurl'), function(response
, error
) {
94 if (error
=== undefined || error
=== null) {
95 var locale
= $cell
.data('locale');
96 if (!response
.locales
[locale
].error
) {
97 state
= parseInt(response
.locales
[locale
].state
);
99 } else if (error
=== 'abort') {
100 languageModule
.displayInformation('flashmessage.canceled');
101 languageModule
.toggleEventHandlers('on');
104 languageModule
.updateCellState($cell
, state
);
105 languageModule
.displaySuccess('flashmessage.updateComplete');
106 languageModule
.toggleEventHandlers('on');
111 * Execute AJAX calls for given rows of the translation matrix
113 * @param mixed rows Rows to process
116 processRows: function(rows
) {
117 // Intialize processing within first run
119 languageModule
.addElementsToStack(rows
);
120 languageModule
.toggleEventHandlers('off');
121 languageModule
.errorCount
= 0;
124 // Stop processing if stack is empty
125 if (languageModule
.isStackEmpty()) {
126 languageModule
.displaySuccess('flashmessage.updateComplete');
127 languageModule
.toggleEventHandlers('on');
131 // Find row to process
132 var $row
= languageModule
.getElementFromStack();
134 languageModule
.toggleEventHandlers('on');
138 // Find all cells in row
139 var $cells
= $row
.find('.translationListCell');
140 $cells
.html(jQuery('#stateIconChecking').html());
143 languageModule
.executeAjaxCall($row
.data('updateurl'), function(response
, error
) {
144 if (error
!== undefined && error
!== null) {
145 $cells
.html(jQuery('#stateIconError').html());
146 if (error
=== 'abort') {
147 languageModule
.displayInformation('flashmessage.canceled');
148 languageModule
.toggleEventHandlers('on');
152 $cells
.each(function(index
, element
) {
153 var $cell
= jQuery(this);
155 if (error
=== undefined || error
=== null) {
156 var locale
= $cell
.data('locale');
157 if (!response
.locales
[locale
].error
) {
158 state
= parseInt(response
.locales
[locale
].state
);
161 languageModule
.updateCellState($cell
, state
);
164 languageModule
.processRows();
169 * Update the state of a cell of the translation matrix
171 * @param mixed cell The cell to process
172 * @param string state Switch to this state
175 updateCellState: function(cell
, state
) {
176 var $icon
= jQuery('#stateIcon' + state
);
177 if ($icon
=== undefined) {
178 $icon
= jQuery('#stateIconError');
181 .removeClass('languageStateNone')
182 .addClass('languageState' + state
)
189 * @param string url The url to call
190 * @param string callback Callback function
191 * @param boolean ignoreErrors Ignore errors
194 executeAjaxCall: function(url
, callback
, ignoreErrors
) {
195 if (url
=== undefined || callback
=== undefined) {
198 languageModule
.currentRequest
= jQuery
.ajax({
202 success: function(response
) {
205 error: function(response
, status
, error
) {
206 if (ignoreErrors
!== false && error
!== 'abort') {
207 languageModule
.errorCount
++;
208 if (languageModule
.errorCount
>= 3) {
209 languageModule
.displayError('flashmessage.multipleErrors');
210 languageModule
.clearElementStack();
213 languageModule
.displayError(error
);
216 callback(response
, error
);
222 * Bind / unbind event handlers
224 * @param string action The value "on" or "off"
227 toggleEventHandlers: function(action
) {
228 var className
= 'waiting';
230 if (action
=== 'on') {
231 jQuery('.updateItem').on('click', languageModule
.updateTranslations
).removeClass(className
);
232 jQuery('.cancelItem').off().fadeOut(fadeSpeed
);
233 jQuery('.selectionList input, .selectionList label').off().parent().removeClass(className
);
234 jQuery('.selectionList input:checkbox').on('change', languageModule
.submitSelectionForm
);
235 jQuery('.selectionList tr, .selectionList td').removeClass(className
);
236 jQuery('.translationList tr, .translationList td').removeClass(className
);
237 jQuery('.languageStateNone').on('click', function() {
238 languageModule
.updateSingleTranslation(this);
241 jQuery('.updateItem').off().addClass(className
);
242 jQuery('.cancelItem').on('click', languageModule
.cancelProcess
).fadeIn(fadeSpeed
);
243 jQuery('.selectionList input:checkbox').off();
244 jQuery('.selectionList input, .selectionList label').on('click', function(event
) {
245 event
.preventDefault();
246 }).parent().addClass(className
);
247 jQuery('.selectionList tr, .selectionList td').addClass(className
);
248 jQuery('.translationList tr, .translationList td').addClass(className
);
249 jQuery('.languageStateNone').off();
254 * Display error flash message
256 * @param string label The label to show
259 displayError: function(label
) {
260 if (typeof label
!== 'string' || label
=== '') {
263 top
.TYPO3
.Flashmessage
.display(
264 top
.TYPO3
.Severity
.error
,
265 TYPO3
.l10n
.localize('flashmessage.error'),
266 TYPO3
.l10n
.localize(label
),
272 * Display information flash message
274 * @param string label The label to show
277 displayInformation: function(label
) {
278 if (typeof label
!== 'string' || label
=== '') {
281 top
.TYPO3
.Flashmessage
.display(
282 top
.TYPO3
.Severity
.info
,
283 TYPO3
.l10n
.localize('flashmessage.information'),
284 TYPO3
.l10n
.localize(label
),
290 * Display success flash message
292 * @param string label The label to show
295 displaySuccess: function(label
) {
296 if (typeof label
!== 'string' || label
=== '') {
299 top
.TYPO3
.Flashmessage
.display(
300 top
.TYPO3
.Severity
.ok
,
301 TYPO3
.l10n
.localize('flashmessage.success'),
302 TYPO3
.l10n
.localize(label
),
308 * Calculate the height of data tables
312 calculateTableHeight: function() {
313 var documentHeight
= parseInt(jQuery(document
).height());
314 var tableTop
= parseInt(jQuery('.selectionList').offset().top
);
315 var result
= documentHeight
- tableTop
- 50;
316 return (result
> 96 ? result
: 96);
320 * Submit language selection form
324 submitSelectionForm: function() {
325 jQuery('form[name="languageSelectionForm"]').submit();
329 * Update translations
333 updateTranslations: function() {
334 languageModule
.processRows('.translationListRow');
338 * Update translation for a single element
340 * @param mixed element The element to process
343 updateSingleTranslation: function(element
) {
344 languageModule
.processCell(element
);
348 * Cancel current process
352 cancelProcess: function() {
353 languageModule
.clearElementStack();
354 if (languageModule
.currentRequest
) {
355 languageModule
.currentRequest
.abort();
362 * @param string elements Element identificator
365 addElementsToStack: function(elements
) {
366 jQuery(elements
).each(function(i
, element
) {
367 languageModule
.elementStack
.push(element
);
372 * Get and remove first element from stack
374 * @return object The element
376 getElementFromStack: function() {
377 var element
= languageModule
.elementStack
.shift();
378 if (element
!== undefined) {
379 return jQuery(element
);
385 * Clear element stack
389 clearElementStack: function() {
390 languageModule
.elementStack
= [];
394 * Check if stack contains elements
396 * @return boolean False if empty
398 isStackEmpty: function() {
399 return languageModule
.elementStack
.length
? false : true;
406 * Initialize when DOM is ready
408 jQuery(document
).ready(function($) {
409 languageModule
.initialize();