Skip to content
Snippets Groups Projects
Commit 9e14e924 authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Adding Viewhelper for lang labels in javascript. Fixed js bug

parent 9c503527
No related branches found
No related tags found
No related merge requests found
<?php
namespace SGalinski\SgMail\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the SG project. The SG project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* View helper to render language labels to
* json array to be used in js applications.
*
* Renders to SG.lang.'extension name' object
*
* Example:
* {namespace rs=SGalinski\RsEvents\ViewHelpers}
* <rs:inlineLanguageLabels labels="label01,label02" />
*/
class InlineLanguageLabelsViewHelper extends AbstractViewHelper {
/**
* Renders the required javascript to make the language labels available
*
* @param string $labels Comma separated list of label keys to include
* @param boolean $htmlEscape
* @return string
*/
public function render($labels = '', $htmlEscape = FALSE) {
$extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
$labels = GeneralUtility::trimExplode(',', $labels, TRUE);
$languageArray = array();
foreach ($labels as $key) {
$value = LocalizationUtility::translate($key, $extensionName);
$languageArray[$key] = ($htmlEscape ? htmlentities($value) : $value);
}
return '
<script type="text/javascript">
var SG = SG || {};
SG.lang = SG.lang || {};
SG.lang.' . $extensionName . ' = SG.lang.' . $extensionName . ' || {};
var languageLabels = ' . json_encode($languageArray) . ';
for (label in languageLabels) {
SG.lang.' . $extensionName . '[label] = languageLabels[label];
}
</script>
';
}
}
?>
\ No newline at end of file
......@@ -29,6 +29,10 @@
<source>Text</source>
<target>Text</target>
</trans-unit>
<trans-unit id="backend.delete_template" approved="yes">
<source>Do you really want to reset this Template ?</source>
<target>Möchten Sie wirklich den Ursprungszustand wiederherstellen ?</target>
</trans-unit>
<trans-unit id="backend.description" approved="yes">
<source>Description</source>
<target>Beschreibung</target>
......
......@@ -24,6 +24,9 @@
<trans-unit id="backend.content">
<source>Text</source>
</trans-unit>
<trans-unit id="backend.delete_template">
<source>Do you really want to reset this Template ?</source>
</trans-unit>
<trans-unit id="backend.description">
<source>Description</source>
</trans-unit>
......
{namespace sgm=SGalinski\SgMail\ViewHelpers}
<f:be.container enableClickMenu="FALSE" loadExtJs="FALSE" includeCssFiles="{0: '{f:uri.resource(path: \'StyleSheets/backend.css\')}'}">
<sgm:addJavaScriptFile javaScriptFile="{f:uri.resource(path: 'Scripts/Template.js')}" />
<sgm:addJavaScriptFile javaScriptFile="{f:uri.resource(path: 'Scripts/Backend.js')}" />
<sgm:inlineLanguageLabels labels="backend.delete_template" />
<div class="module" data-module-id="" data-module-name="">
<div class="module-docheader t3js-module-docheader">
<div class="module-docheader-bar module-docheader-bar-navigation t3js-module-docheader-bar t3js-module-docheader-bar-navigation">
......
(function($) {
$('.reset-btn').on('click', function(_event) {
function resetTemplateListener(_event) {
_event.preventDefault();
if (window.confirm('Reset ?')) {
var confirm = SG.lang.SgMail['backend.delete_template'];
if (window.confirm(confirm)) {
window.location = $(_event.currentTarget).attr('href');
}
}
$(document).ready(function() {
$('.reset-btn').on('click', resetTemplateListener);
});
})
(TYPO3.jQuery);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment