[BUGFIX] Field Wizards use FormEngine JS functions for has-change checks 61/52961/10
authorRalf Hettinger <ralf.hettinger@brain-appeal.com>
Mon, 29 May 2017 16:52:42 +0000 (18:52 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Tue, 14 Aug 2018 11:32:09 +0000 (13:32 +0200)
AddRecord, ListModule and TableWizard fieldControl wizard buttons now use
FormEngine JavaScript function to prevent elderly, incomplete (buggy)
has-change checks as implemented in TBE_EDITOR.isFormChanged.

Resolves: #81360
Releases: master
Change-Id: Ie633e04d7e9c01af2abda39b032c262502d888c8
Reviewed-on: https://review.typo3.org/52961
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/backend/Classes/Controller/EditDocumentController.php
typo3/sysext/backend/Classes/Controller/PageLayoutController.php
typo3/sysext/backend/Classes/Form/FieldControl/AddRecord.php
typo3/sysext/backend/Classes/Form/FieldControl/ListModule.php
typo3/sysext/backend/Classes/Form/FieldControl/TableWizard.php
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine.js

index 1548dbc..58eee95 100644 (file)
@@ -942,13 +942,6 @@ class EditDocumentController
         $this->moduleTemplate->addJavaScriptCode(
             'jumpToUrl',
             '
-            function jumpToUrl(URL,formEl) {
-                if (!TBE_EDITOR.isFormChanged()) {
-                    window.location.href = URL;
-                } else if (formEl && formEl.type=="checkbox") {
-                    formEl.checked = formEl.checked ? 0 : 1;
-                }
-            }
             // Info view:
             function launchView(table,uid) {
                 console.warn(\'Calling launchView() has been deprecated in v9 and will be removed in v10.0\');
index ffdefd3..6c39e62 100644 (file)
@@ -708,21 +708,6 @@ class PageLayoutController
 
             $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
 
-            // override the default jumpToUrl
-            $this->moduleTemplate->addJavaScriptCode('jumpToUrl', '
-                function jumpToUrl(URL,formEl) {
-                    if (document.editform && TBE_EDITOR.isFormChanged)  {   // Check if the function exists... (works in all browsers?)
-                        if (!TBE_EDITOR.isFormChanged()) {
-                            window.location.href = URL;
-                        } else if (formEl) {
-                            if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
-                        }
-                    } else {
-                        window.location.href = URL;
-                    }
-                }
-            ');
-
             /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
             $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
 
index 9dc55e0..69b0a93 100644 (file)
@@ -98,7 +98,7 @@ class AddRecord extends AbstractNode
 
         $onClick = [];
         $onClick[] = 'this.blur();';
-        $onClick[] = 'return !TBE_EDITOR.isFormChanged();';
+        $onClick[] = 'return TYPO3.FormEngine.preventFollowLinkIfNotSaved(this.getAttribute(\'href\'));';
         /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
         $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
         return [
index 57fc1e2..d1b5fad 100644 (file)
@@ -84,9 +84,10 @@ class ListModule extends AbstractNode
 
         $onClick = [];
         $onClick[] = 'this.blur();';
-        $onClick[] = 'return !TBE_EDITOR.isFormChanged();';
+        $onClick[] = 'return TYPO3.FormEngine.preventFollowLinkIfNotSaved(this.getAttribute(\'href\'));';
         /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
         $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
+
         return [
             'iconIdentifier' => 'actions-system-list-open',
             'title' => $title,
index f73dc96..e593b2e 100644 (file)
@@ -68,7 +68,7 @@ class TableWizard extends AbstractNode
 
         $onClick = [];
         $onClick[] = 'this.blur();';
-        $onClick[] = 'return !TBE_EDITOR.isFormChanged();';
+        $onClick[] = 'return TYPO3.FormEngine.preventFollowLinkIfNotSaved(this.getAttribute(\'href\'));';
         /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
         $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
         return [
index 11b53cf..ba26644 100644 (file)
@@ -1118,9 +1118,22 @@ define(['jquery',
    * @param {boolean} response
    */
   FormEngine.preventExitIfNotSavedCallback = function(response) {
-    if (response) {
-      FormEngine.closeDocument();
-    }
+    FormEngine.closeDocument();
+  };
+
+  /**
+   * Show modal to confirm following a clicked link to confirm leaving the document without saving
+   *
+   * @param {String} href
+   * @returns {Boolean}
+   */
+  FormEngine.preventFollowLinkIfNotSaved = function(href) {
+    FormEngine.preventExitIfNotSaved(
+      function () {
+        window.location.href = href;
+      }
+    );
+    return false;
   };
 
   /**
@@ -1156,7 +1169,6 @@ define(['jquery',
       $modal.on('button.clicked', function(e) {
         if (e.target.name === 'no') {
           Modal.dismiss();
-          callback.call(null, false);
         } else if (e.target.name === 'yes') {
           Modal.dismiss();
           callback.call(null, true);