[TASK] EXT:filelist: Use new modal confirmation dialog for file delete 69/45369/12
authorMichael Oehlhof <typo3@oehlhof.de>
Sat, 19 Dec 2015 02:50:37 +0000 (03:50 +0100)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Thu, 14 Jan 2016 22:28:26 +0000 (23:28 +0100)
Resolves: #72332
Releases: master, 7.6
Change-Id: I5d58bf432f33917705398322d879942b06840176
Reviewed-on: https://review.typo3.org/45369
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/filelist/Classes/Controller/FileListController.php
typo3/sysext/filelist/Classes/FileFacade.php
typo3/sysext/filelist/Classes/FileList.php
typo3/sysext/filelist/Resources/Private/Templates/FileList/Search.html
typo3/sysext/filelist/Resources/Public/JavaScript/FileDelete.js [new file with mode: 0644]
typo3/sysext/filelist/Resources/Public/JavaScript/FileList.js
typo3/sysext/lang/locallang_alt_doc.xlf

index dad420c..da3d6c9 100644 (file)
@@ -396,6 +396,11 @@ class FileListController extends ActionController
                     return false;
                 }
                 ');
+            $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileDelete');
+            $pageRenderer->addInlineLanguageLabelFile(
+                ExtensionManagementUtility::extPath('lang') . 'locallang_alt_doc.xlf',
+                'buttons'
+            );
 
             // Include DragUploader only if we have write access
             if ($this->folderObject->getStorage()->checkUserActionPermission('add', 'File')
@@ -491,9 +496,17 @@ class FileListController extends ActionController
 
         $this->view->assign('searchWord', $searchWord);
         $this->view->assign('files', $fileFacades);
+        $this->view->assign('veriCode', $this->getBackendUser()->veriCode());
+        $this->view->assign('deleteUrl', BackendUtility::getModuleUrl('tce_file'));
         $this->view->assign('settings', [
             'jsConfirmationDelete' => $this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)
         ]);
+
+        $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileDelete');
+        $pageRenderer->addInlineLanguageLabelFile(
+            ExtensionManagementUtility::extPath('lang') . 'locallang_alt_doc.xlf',
+            'buttons'
+        );
     }
 
     /**
index 744d3d6..fe66ce4 100644 (file)
@@ -143,6 +143,14 @@ class FileFacade
     /**
      * @return string
      */
+    public function getIdentifier()
+    {
+        return $this->resource->getStorage()->getUid() . ':' . $this->resource->getIdentifier();
+    }
+
+    /**
+     * @return string
+     */
     public function getLastModified()
     {
         return BackendUtility::date($this->resource->getModificationTime());
index 81794f9..6a1d560 100644 (file)
@@ -928,14 +928,22 @@ class FileList extends AbstractRecordList
             }
 
             if ($this->getBackendUser()->jsConfirmation(JsConfirmation::DELETE)) {
-                $confirmationCheck = 'confirm(' . GeneralUtility::quoteJSvalue(sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText) . ')';
+                $confirmationCheck = '1';
             } else {
-                $confirmationCheck = '1 == 1';
+                $confirmationCheck = '0';
             }
 
-            $removeOnClick = 'if (' . $confirmationCheck . ') { top.content.list_frame.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_file') . '&file[delete][0][data]=' . rawurlencode($fileOrFolderObject->getCombinedIdentifier()) . '&vC=' . $this->getBackendUser()->veriCode() . '&redirect=') . '+top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);};';
-
-            $cells['delete'] = '<a href="#" class="btn btn-default" onclick="' . htmlspecialchars($removeOnClick) . '"  title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.delete') . '">' . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
+            $deleteUrl = BackendUtility::getModuleUrl('tce_file');
+            $confirmationMessage = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), $fileOrFolderObject->getName()) . $referenceCountText;
+            $title = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.delete');
+            $cells['delete'] = '<a href="#" class="btn btn-default t3js-filelist-delete" data-content="' . htmlspecialchars($confirmationMessage)
+                . '" data-check="' . $confirmationCheck
+                . '" data-delete-url="' . htmlspecialchars($deleteUrl)
+                . '" data-title="' . htmlspecialchars($title)
+                . '" data-identifier="' . htmlspecialchars($fileOrFolderObject->getCombinedIdentifier())
+                . '" data-veri-code="' . $this->getBackendUser()->veriCode()
+                . '" title="' . htmlspecialchars($title) . '">'
+                . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
         } else {
             $cells['delete'] = $this->spaceIcon;
         }
index f48a0e7..b5aa5ff 100644 (file)
                                                                </f:if>
                                                                <f:if condition="{file.isDeletable}">
                                                                        <f:then>
-                                                                               <a href="#" class="btn btn-default filelist-file-delete"
+                                                                               <a href="#" class="btn btn-default t3js-filelist-delete"
                                                                                        title="{f:translate( htmlEscape:'true', key:'LLL:EXT:lang/locallang_core.xlf:cm.delete' )}"
-                                                                                       data-url="{fl:uri.deleteFile( file:file.resource, returnUrl:'{f:uri.action( action:\'search\', arguments:{ searchWord:\'{searchWord->f:format.htmlentities()}\' } )}' )}"
-                                                                                       data-confirmation-dialogue="{f:if( condition:settings.jsConfirmationDelete, then:'confirm({f:translate( htmlEscape:\'true\', key:\'LLL:EXT:lang/locallang_core.xlf:mess.delete\', arguments: {0:file.name} )})', else:'1 == 1' )}"
+                                                                                       data-identifier="{file.identifier}"
+                                                                                       data-veri-code="{veriCode}"
+                                                                                       data-title="{f:translate( htmlEscape:'true', key:'LLL:EXT:lang/locallang_core.xlf:cm.delete' )}"
+                                                                                       data-content="{f:translate( htmlEscape:'true', key:'LLL:EXT:lang/locallang_core.xlf:mess.delete', arguments: {0:file.name} )}"
+                                                                                       data-check="{f:if(condition:settings.jsConfirmationDelete, then:'1', else:'0')}"
+                                                                                       data-delete-url="{deleteUrl}"
+                                                                                       data-redirect-url="{f:uri.action( action:'search', arguments:{ searchWord:'{searchWord->f:format.htmlentities()}' } )}"
                                                                                >
                                                                                        <core:icon identifier="actions-edit-delete" />
                                                                                </a>
diff --git a/typo3/sysext/filelist/Resources/Public/JavaScript/FileDelete.js b/typo3/sysext/filelist/Resources/Public/JavaScript/FileDelete.js
new file mode 100644 (file)
index 0000000..b336c17
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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!
+ */
+
+/**
+ * Module: TYPO3/CMS/Filelist/FileDelete
+ * JavaScript for file delete
+ */
+define(['jquery', 'TYPO3/CMS/Backend/Modal'], function ($, Modal) {
+
+       $(document).on('click', '.t3js-filelist-delete', function(e) {
+               e.preventDefault();
+               var $anchorElement = $(this);
+               var redirectUrl = $anchorElement.data('redirectUrl');
+               if (redirectUrl) {
+                       redirectUrl = top.rawurlencode(redirectUrl);
+               } else {
+                       redirectUrl = top.rawurlencode(top.content.list_frame.document.location.pathname+top.content.list_frame.document.location.search);
+               }
+               var identifier = $anchorElement.data('identifier');
+               var veriCode = $anchorElement.data('veriCode');
+               var deleteUrl = $anchorElement.data('deleteUrl') + '&file[delete][0][data]=' + encodeURIComponent(identifier) + '&vC=' + encodeURIComponent(veriCode);
+               if ($anchorElement.data('check')) {
+                       var $modal = Modal.confirm($anchorElement.data('title'), $anchorElement.data('content'), top.TYPO3.Severity.warning, [
+                               {
+                                       text: TYPO3.lang['buttons.confirm.delete_file.no'] || 'Cancel',
+                                       active: true,
+                                       btnClass: 'btn-default',
+                                       name: 'no'
+                               },
+                               {
+                                       text: TYPO3.lang['buttons.confirm.delete_file.yes'] || 'Yes, delete this file',
+                                       btnClass: 'btn-warning',
+                                       name: 'yes'
+                               }
+                       ]);
+                       $modal.on('button.clicked', function(e) {
+                               if (e.target.name === 'no') {
+                                       Modal.dismiss();
+                               } else if (e.target.name === 'yes') {
+                                       Modal.dismiss();
+                                       top.content.list_frame.location.href = deleteUrl + '&redirect=' + redirectUrl;
+                               }
+                       });
+               } else {
+                       top.content.list_frame.location.href = deleteUrl + '&redirect=' + redirectUrl;
+               }
+       });
+
+});
index cce41d8..9bbc831 100644 (file)
@@ -59,17 +59,6 @@ define(['jquery'], function($) {
                openFileInfoPopup(identifier);
        });
 
-       $('a.btn.filelist-file-delete').click(function(event) {
-               event.preventDefault();
-
-               var url = $(this).attr('data-url');
-               var confirmationDialogue = $(this).attr('data-confirmation-dialogue');
-
-               if (confirmationDialogue) {
-                       top.content.list_frame.location.href=url;
-               }
-       });
-
        $('a.filelist-file-references').click(function(event) {
                event.preventDefault();
 
index 5f7c567..16a3df2 100644 (file)
                        <trans-unit id="label.confirm.close_without_save.content">
                                <source>You have currently unsaved changes. Are you sure that you want to discard all changes?</source>
                        </trans-unit>
+                       <trans-unit id="buttons.confirm.delete_file.no">
+                               <source>Cancel</source>
+                       </trans-unit>
+                       <trans-unit id="buttons.confirm.delete_file.yes">
+                               <source>Yes, delete this file</source>
+                       </trans-unit>
                        <trans-unit id="buttons.confirm.delete_record.no">
                                <source>Cancel</source>
                        </trans-unit>