[FEATURE] Confirm modal on closing an editform with unsaved changes 34/38134/4
authorFrank Nägler <typo3@naegler.net>
Tue, 24 Mar 2015 21:09:49 +0000 (22:09 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 26 Mar 2015 12:47:54 +0000 (13:47 +0100)
A new functionality is introduced that asks the editor to confirm
closing an editform with unsaved changes.

Resolves: #65996
Releases: master
Change-Id: I8b606ec0635690ab2b05624412887b6d2fa7c9c5
Reviewed-on: http://review.typo3.org/38134
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Daniel Sattler <sattler@b13.de>
Tested-by: Daniel Sattler <sattler@b13.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Classes/Controller/EditDocumentController.php
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine.js
typo3/sysext/core/Documentation/Changelog/master/Feature-65996-AddConfirmationOnCloseEditformWithUnsavedChanges.rst [new file with mode: 0644]
typo3/sysext/lang/locallang_alt_doc.xlf
typo3/sysext/t3skin/Resources/Private/Styles/TYPO3/_element_modal.less
typo3/sysext/t3skin/Resources/Public/Css/visual/t3skin.css

index ec0751d..210ffbb 100644 (file)
@@ -648,6 +648,7 @@ class EditDocumentController {
                $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->MCONF['name']);
                // Create an instance of the document template object
                $this->doc = $GLOBALS['TBE_TEMPLATE'];
+               $this->doc->getPageRenderer()->addInlineLanguageLabelFile('EXT:lang/locallang_alt_doc.xml');
                $this->doc->backPath = $GLOBALS['BACK_PATH'];
                $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/alt_doc.html');
                $this->doc->form = '<form action="' . htmlspecialchars($this->R_URI) . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '" name="editform" onsubmit="document.editform._scrollPosition.value=(document.documentElement.scrollTop || document.body.scrollTop); return TBE_EDITOR.checkSubmit(1);">';
@@ -1008,7 +1009,7 @@ class EditDocumentController {
                        }
                }
                // CLOSE button:
-               $buttons['close'] = '<a href="#" onclick="document.editform.closeDoc.value=1; document.editform.submit(); return false;" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-close') . '</a>';
+               $buttons['close'] = '<a href="#" class="t3js-editform-close" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-close') . '</a>';
                // DELETE + UNDO buttons:
                if (!$this->errorC && !$GLOBALS['TCA'][$this->firstEl['table']]['ctrl']['readOnly'] && count($this->elementsData) == 1) {
                        if ($this->firstEl['cmd'] != 'new' && MathUtility::canBeInterpretedAsInteger($this->firstEl['uid'])) {
index b9e4c80..217fd61 100644 (file)
@@ -662,6 +662,47 @@ define('TYPO3/CMS/Backend/FormEngine', ['jquery'], function ($) {
                        DateTimePicker.initialize();
                });
                FormEngine.convertTextareasResizable();
+               $(document).on('click', '.t3js-editform-close', function(e) {
+                       e.preventDefault();
+                       FormEngine.preventExitIfNotSaved();
+               });
+       };
+
+       /**
+        * Show modal to confirm closing the document without saving
+        */
+       FormEngine.preventExitIfNotSaved = function() {
+               if ($('.has-change').length > 0) {
+                       var title = TYPO3.lang['label.confirm.close_without_save.title'] || 'Do you want to quit without saving?';
+                       var content = TYPO3.lang['label.confirm.close_without_save.content'] || 'You have currently unsaved changes. Are you sure that you want to discard all changes?';
+                       top.TYPO3.Modal.confirm(title, content, top.TYPO3.Severity.warning, [
+                               {
+                                       text: TYPO3.lang['buttons.confirm.close_without_save.no'] || 'No, I will continue editing',
+                                       active: true,
+                                       trigger: function() {
+                                               top.TYPO3.Modal.dismiss();
+                                       }
+                               },
+                               {
+                                       text: TYPO3.lang['buttons.confirm.close_without_save.yes'] || 'Yes, discard my changes',
+                                       btnClass: 'btn-warning',
+                                       trigger: function() {
+                                               top.TYPO3.Modal.dismiss();
+                                               FormEngine.closeDocument();
+                                       }
+                               }
+                       ]);
+               } else {
+                       FormEngine.closeDocument()
+               }
+       };
+
+       /**
+        * Close current open document
+        */
+       FormEngine.closeDocument = function() {
+               document.editform.closeDoc.value=1;
+               document.editform.submit();
        };
 
        /**
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-65996-AddConfirmationOnCloseEditformWithUnsavedChanges.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-65996-AddConfirmationOnCloseEditformWithUnsavedChanges.rst
new file mode 100644 (file)
index 0000000..e72b045
--- /dev/null
@@ -0,0 +1,15 @@
+==================================================================================
+Feature: #65996 - Show confirm message on closing an editform with unsaved changes
+==================================================================================
+
+Description
+===========
+
+A new functionality is introduced that asks the editor to confirm closing an editform with unsaved changes.
+
+
+Impact
+======
+
+On click the close icon of an editform with unsaved changes, a confirmation modal will be shown.
+
index 4795785..05fb830 100644 (file)
                        <trans-unit id="noDocuments_listmodule" xml:space="preserve">
                                <source>the Web&gt;List module</source>
                        </trans-unit>
+                       <trans-unit id="buttons.confirm.close_without_save.yes" xml:space="preserve">
+                               <source>Yes, discard my changes</source>
+                       </trans-unit>
+                       <trans-unit id="buttons.confirm.close_without_save.no" xml:space="preserve">
+                               <source>No, I will continue editing</source>
+                       </trans-unit>
+                       <trans-unit id="label.confirm.close_without_save.title" xml:space="preserve">
+                               <source>Do you want to quit without saving?</source>
+                       </trans-unit>
+                       <trans-unit id="label.confirm.close_without_save.content" xml:space="preserve">
+                               <source>You have currently unsaved changes. Are you sure that you want to discard all changes?</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>
index 2d2b9fb..59a1ba7 100644 (file)
@@ -78,6 +78,7 @@
 }
 .modal-footer .btn {
        margin-right: 0;
+       min-width: 100px;
 }
 .modal-content {
        .transition(margin-top .1s ease-in);
index 0ca852a..3991225 100644 (file)
@@ -8333,6 +8333,7 @@ td .alert:last-child {
 }
 .modal-footer .btn {
   margin-right: 0;
+  min-width: 100px;
 }
 .modal-content {
   -webkit-transition: margin-top 0.1s ease-in;