[BUGFIX] Disable "Create new translation headers" when no selection is made 34/56734/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 19 Apr 2018 12:02:28 +0000 (14:02 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 19 Apr 2018 12:23:36 +0000 (14:23 +0200)
The "Create new translation headers" is now disabled if no page to be
translated is selected to avoid errors in the target action. A small
TypeScript is added that unlocks the aforementioned button if at least
one checkbox was selected.

Resolves: #76676
Releases: master, 8.7
Change-Id: I163ed7322066d81597547dd2b2774434a086f082
Reviewed-on: https://review.typo3.org/56734
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Build/tsconfig.json
typo3/sysext/frontend/Classes/Controller/TranslationStatusController.php
typo3/sysext/frontend/Resources/Private/TypeScript/TranslationStatus.ts [new file with mode: 0644]
typo3/sysext/frontend/Resources/Public/JavaScript/TranslationStatus.js [new file with mode: 0644]

index 0c73a40..3a3cccf 100644 (file)
         "../typo3/sysext/backend/Resources/Private/TypeScript/ColorPicker.ts",
         "../typo3/sysext/backend/Resources/Private/TypeScript/FormEngineReview.ts",
         "../typo3/sysext/backend/Resources/Private/TypeScript/ImageManipulation.ts",
-        "../typo3/sysext/backend/Resources/Private/TypeScript/RenameFile.ts"
+        "../typo3/sysext/backend/Resources/Private/TypeScript/RenameFile.ts",
+        "../typo3/sysext/frontend/Resources/Private/TypeScript/TranslationStatus.ts"
     ]
 }
index 409de2a..57ef69c 100644 (file)
@@ -86,6 +86,8 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
     {
         $theOutput = '<h1>' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:frontend/Resources/Private/Language/locallang_webinfo.xlf:lang_title')) . '</h1>';
         if ($this->pObj->id) {
+            $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Frontend/TranslationStatus');
+
             // Depth selector:
             $theOutput .= '<div class="form-inline form-inline-spaced">';
             $h_func = BackendUtility::getDropdownMenu($this->pObj->id, 'SET[depth]', $this->pObj->MOD_SETTINGS['depth'], $this->pObj->MOD_MENU['depth']);
@@ -248,15 +250,15 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
                         } else {
                             $status = GeneralUtility::hideIfNotTranslated($data['row']['l18n_cfg']) || GeneralUtility::hideIfDefaultLanguage($data['row']['l18n_cfg']) ? 'danger' : '';
                             $info = '<div class="btn-group"><label class="btn btn-default btn-checkbox">';
-                            $info .= '<input type="checkbox" name="newOL[' . $langRow['uid'] . '][' . $data['row']['uid'] . ']" value="1" />';
+                            $info .= '<input type="checkbox" data-lang="' . (int)$langRow['uid'] . '" name="newOL[' . $langRow['uid'] . '][' . $data['row']['uid'] . ']" value="1" />';
                             $info .= '<span class="t3-icon fa"></span></label></div>';
-                            $newOL_js[$langRow['uid']] .= '
-                                                               +(document.webinfoForm['
+                            $newOL_js[$langRow['uid']] .=
+                                '+(document.webinfoForm['
                                 . GeneralUtility::quoteJSvalue('newOL[' . $langRow['uid'] . '][' . $data['row']['uid'] . ']')
                                 . '].checked ? '
                                 . GeneralUtility::quoteJSvalue('&edit[pages_language_overlay][' . $data['row']['uid'] . ']=new')
-                                . ' : \'\')
-                                                       ';
+                                . ' : \'\')'
+                            ;
                         }
                         $tCells[] = '<td class="' . $status . ' col-border-left">&nbsp;</td>';
                         $tCells[] = '<td class="' . $status . '">&nbsp;</td>';
@@ -324,7 +326,7 @@ class TranslationStatusController extends \TYPO3\CMS\Backend\Module\AbstractFunc
                     $onClickArray[] = '\'' . $newOL_js[$langRow['uid']] . ' + \'&' . $lastElement;
                     $onClick = implode('?', $onClickArray);
                 }
-                $newButton = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($onClick)
+                $newButton = '<a href="#" class="btn btn-default disabled t3js-language-new-' . (int)$langRow['uid'] . '" onclick="' . htmlspecialchars($onClick)
                     . '" title="' . $lang->sL(
                         'LLL:EXT:frontend/Resources/Private/Language/locallang_webinfo.xlf:lang_getlangsta_createNewTranslationHeaders'
                     ) . '">' . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render() . '</a>';
diff --git a/typo3/sysext/frontend/Resources/Private/TypeScript/TranslationStatus.ts b/typo3/sysext/frontend/Resources/Private/TypeScript/TranslationStatus.ts
new file mode 100644 (file)
index 0000000..b760323
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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 * as $ from 'jquery';
+
+/**
+ * Module: TYPO3/CMS/Frontend/TranslationStatus
+ */
+class TranslationStatus {
+  constructor() {
+    this.registerEvents();
+  }
+
+  private registerEvents(): void {
+    $('input[type="checkbox"][data-lang]').on('change', this.toggleNewButton);
+  }
+
+  /**
+   * @param {JQueryEventObject} e
+   */
+  private toggleNewButton(e: JQueryEventObject): void {
+    const $me: JQuery = $(e.currentTarget);
+    const languageId: number = parseInt($me.data('lang'), 10);
+    const $newButton: JQuery = $('.t3js-language-new-' + languageId);
+    const $selected: JQuery = $('input[type="checkbox"][data-lang="' + languageId + '"]:checked');
+    $newButton.toggleClass('disabled', $selected.length === 0);
+  }
+}
+
+export = new TranslationStatus();
diff --git a/typo3/sysext/frontend/Resources/Public/JavaScript/TranslationStatus.js b/typo3/sysext/frontend/Resources/Public/JavaScript/TranslationStatus.js
new file mode 100644 (file)
index 0000000..fd1de8d
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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!
+ */
+define(["require", "exports", "jquery"], function (require, exports, $) {
+    "use strict";
+    /**
+     * Module: TYPO3/CMS/Frontend/TranslationStatus
+     */
+    var TranslationStatus = (function () {
+        function TranslationStatus() {
+            this.registerEvents();
+        }
+        TranslationStatus.prototype.registerEvents = function () {
+            $('input[type="checkbox"][data-lang]').on('change', this.toggleNewButton);
+        };
+        /**
+         * @param {JQueryEventObject} e
+         */
+        TranslationStatus.prototype.toggleNewButton = function (e) {
+            var $me = $(e.currentTarget);
+            var languageId = parseInt($me.data('lang'), 10);
+            var $newButton = $('.t3js-language-new-' + languageId);
+            var $selected = $('input[type="checkbox"][data-lang="' + languageId + '"]:checked');
+            $newButton.toggleClass('disabled', $selected.length === 0);
+        };
+        return TranslationStatus;
+    }());
+    return new TranslationStatus();
+});