/* * This file is part of the TYPO3 CMS project. * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 * of the License, or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. * * The TYPO3 project - inspiring people to share! */ import $ from 'jquery'; import {AjaxResponse} from 'TYPO3/CMS/Core/Ajax/AjaxResponse'; import {SeverityEnum} from './Enum/Severity'; import AjaxRequest = require('TYPO3/CMS/Core/Ajax/AjaxRequest'); import Icons = require('./Icons'); import Wizard = require('./Wizard'); type LanguageRecord = { uid: number; title: string; flagIcon: string; }; type SummaryColumns = { columns: { [key: number]: string }; columnList: Array; }; type SummaryColPosRecord = { uid: number; title: string; icon: string; }; type SummaryRecord = { columns: SummaryColumns; records: Array>; }; class Localization { private triggerButton: string = '.t3js-localize'; private localizationMode: string = null; private sourceLanguage: number = null; private records: Array = []; constructor() { $((): void => { this.initialize(); }); } private initialize(): void { const me = this; Icons.getIcon('actions-localize', Icons.sizes.large).then((localizeIconMarkup: string): void => { Icons.getIcon('actions-edit-copy', Icons.sizes.large).then((copyIconMarkup: string): void => { $(me.triggerButton).removeClass('disabled'); $(document).on('click', me.triggerButton, (e: JQueryEventObject): void => { e.preventDefault(); const $triggerButton = $(e.currentTarget); const actions: Array = []; let slideStep1: string = ''; if ($triggerButton.data('allowTranslate')) { actions.push( '
' + '
' + '' + '
' + '
' + '

' + TYPO3.lang['localize.educate.translate'] + '

' + '
' + '
', ); } if ($triggerButton.data('allowCopy')) { actions.push( '
' + '
' + '' + '
' + '
' + '

' + TYPO3.lang['localize.educate.copy'] + '

' + '
' + '
', ); } if ($triggerButton.data('allowTranslate') === 0 && $triggerButton.data('allowCopy') === 0) { actions.push( '
' + '
' + '
' + '
' + '
' + '' + '
' + '
' + '

' + TYPO3.lang['localize.educate.noTranslate'] + '

' + '
' + '
' + '
' + '
' + '
', ); } slideStep1 += '
' + actions.join('
') + '
'; Wizard.addSlide( 'localize-choose-action', TYPO3.lang['localize.wizard.header_page'] .replace('{0}', $triggerButton.data('page')) .replace('{1}', $triggerButton.data('languageName')), slideStep1, SeverityEnum.info, ); Wizard.addSlide( 'localize-choose-language', TYPO3.lang['localize.view.chooseLanguage'], '', SeverityEnum.info, ($slide: JQuery): void => { Icons.getIcon('spinner-circle-dark', Icons.sizes.large).then((markup: string): void => { $slide.html('
' + markup + '
'); this.loadAvailableLanguages( parseInt($triggerButton.data('pageId'), 10), parseInt($triggerButton.data('languageId'), 10), ).then(async (response: AjaxResponse): Promise => { const result: Array = await response.resolve(); if (result.length === 1) { // We only have one result, auto select the record and continue this.sourceLanguage = result[0].uid; Wizard.unlockNextStep().trigger('click'); return; } Wizard.getComponent().on('click', '.t3js-language-option', (optionEvt: JQueryEventObject): void => { const $me = $(optionEvt.currentTarget); const $radio = $me.find('input[type="radio"]'); this.sourceLanguage = $radio.val(); console.log('Localization.ts@132', this.sourceLanguage); Wizard.unlockNextStep(); }); const $languageButtons = $('
', {class: 'row', 'data-bs-toggle': 'buttons'}); for (const languageObject of result) { $languageButtons.append( $('
', {class: 'col-sm-4'}).append( $('