Commit eaec5662 authored by Damjan's avatar Damjan

[FEATURE] Security question on cancel of file editing.

parent 7c0a6639
<?php
namespace SGalinski\Lfeditor\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the AY project. The AY 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;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* View helper to render language labels to
* json array to be used in js applications.
*
* Renders to AY.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 = [];
foreach ($labels as $key) {
$value = LocalizationUtility::translate($key, $extensionName);
$languageArray[$key] = ($htmlEscape ? htmlentities($value) : $value);
}
return '
<script type="text/javascript">
var AY = AY || {};
AY.lang = AY.lang || {};
AY.lang.' . $extensionName . ' = AY.lang.' . $extensionName . ' || {};
var languageLabels = ' . json_encode($languageArray) . ';
for (label in languageLabels) {
AY.lang.' . $extensionName . '[label] = languageLabels[label];
}
</script>
';
}
}
?>
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" target-language="da" datatype="plaintext" original="messages" date="2015-02-16T18:59:15Z">
<file source-language="en" target-language="da" datatype="plaintext" original="messages" date="2015-02-17T12:41:07Z">
<header>
<description>FileRef: EXT:lfeditor/Resources/Private/Language/locallang.xml&lt;br /&gt;&lt;br /&gt;Special Thanks:&lt;br /&gt;Peter Klein --&gt; danish translation&lt;br /&gt;Tapio Markula --&gt; finnish translation</description>
<type>module</type>
......
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2015-02-16T18:59:15Z">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2015-02-17T12:41:07Z">
<header>
<description>FileRef: EXT:lfeditor/Resources/Private/Language/locallang.xml&lt;br /&gt;&lt;br /&gt;Special Thanks:&lt;br /&gt;Peter Klein --&gt; danish translation&lt;br /&gt;Tapio Markula --&gt; finnish translation</description>
<type>module</type>
......@@ -397,6 +397,10 @@
<source>XML</source>
<target>XML</target>
</trans-unit>
<trans-unit id="function.langfile.confirmCancel" approved="yes" xml:space="preserve">
<source>All unsaved changes will be lost. Are you sure that you wish to cancel?</source>
<target>Alle nicht gespeicherten Änderungen gehen verloren. Bist du dir sicher, dass du abbrechen möchtest?</target>
</trans-unit>
<trans-unit id="function.langfile.edit" approved="yes" xml:space="preserve">
<source>Edit file</source>
<target>Sprachdatei editieren</target>
......
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" target-language="fi" datatype="plaintext" original="messages" date="2015-02-16T18:59:15Z">
<file source-language="en" target-language="fi" datatype="plaintext" original="messages" date="2015-02-17T12:41:07Z">
<header>
<description>FileRef: EXT:lfeditor/Resources/Private/Language/locallang.xml&lt;br /&gt;&lt;br /&gt;Special Thanks:&lt;br /&gt;Peter Klein --&gt; danish translation&lt;br /&gt;Tapio Markula --&gt; finnish translation</description>
<type>module</type>
......
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="messages" date="2015-02-16T18:59:15Z">
<file source-language="en" datatype="plaintext" original="messages" date="2015-02-17T12:41:07Z">
<header>
<description>FileRef: EXT:lfeditor/Resources/Private/Language/locallang.xml&lt;br /&gt;&lt;br /&gt;Special Thanks:&lt;br /&gt;Peter Klein --&gt; danish translation&lt;br /&gt;Tapio Markula --&gt; finnish translation</description>
<type>module</type>
......@@ -300,6 +300,9 @@
<trans-unit id="function.general.transform.xml" xml:space="preserve">
<source>XML</source>
</trans-unit>
<trans-unit id="function.langfile.confirmCancel" xml:space="preserve">
<source>All unsaved changes will be lost. Are you sure that you wish to cancel?</source>
</trans-unit>
<trans-unit id="function.langfile.edit" xml:space="preserve">
<source>Edit file</source>
</trans-unit>
......
......@@ -5,6 +5,7 @@
<f:if condition="{tinyMCESelected} != 'TRUE'">
<lfe:addJavaScriptFile javaScriptFile="{f:uri.resource(path: 'Scripts/textareaResize.js')}" />
</f:if>
<lfe:inlineLanguageLabels labels="function.langfile.confirmCancel" />
<lfe:addCssFile cssFile="{f:uri.resource(path: 'StyleSheets/Lfeditor.css')}" />
......
......@@ -39,7 +39,7 @@
<f:form.submit value="{f:translate(key:'button.session.next')}" onclick="submitLanguageFileEdit(2)" />
</f:if>
<f:form.submit value="{f:translate(key:'button.save')}" onclick="submitLanguageFileEdit(3)" />
<f:form.submit value="{f:translate(key:'button.cancel')}" onclick="submitLanguageFileEdit(-1)" />
<f:form.submit value="{f:translate(key:'button.cancel')}" onclick="return confirmCancelFileEdit()" />
</div>
<f:for each="{constValues}" key="constKey" as="constValue" iteration="iterator">
......@@ -108,7 +108,7 @@
<f:form.submit value="{f:translate(key:'button.session.next')}" onclick="submitLanguageFileEdit(2)" />
</f:if>
<f:form.submit value="{f:translate(key:'button.save')}" onclick="submitLanguageFileEdit(3)" />
<f:form.submit value="{f:translate(key:'button.cancel')}" onclick="submitLanguageFileEdit(-1)" />
<f:form.submit value="{f:translate(key:'button.cancel')}" onclick="return confirmCancelFileEdit()" />
</div>
</f:form>
</f:if>
......
......@@ -24,5 +24,4 @@
function submitForm(formName) {
document.getElementById(formName).submit();
}
}
\ No newline at end of file
......@@ -41,6 +41,20 @@ function submitLanguageFileEdit(buttonType) {
document.forms.contentForm.elements['tx_lfeditor_user_lfeditorlfeditor[buttonType]'].value = buttonType;
}
/**
* Renders confirmation dialog for cancel button.
*
* @returns {boolean}
*/
function confirmCancelFileEdit() {
var warningText = AY.lang.Lfeditor['function.langfile.confirmCancel'];
if (window.confirm(warningText)) {
submitLanguageFileEdit(-1);
return true;
}
return false;
}
/** args -- fieldID(id), picID(id), bottom(boolean) */
function openCloseTreeEntry(prefix, args) {
var length = arguments.length;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment