diff --git a/typo3/sysext/filelist/Classes/Controller/FileListController.php b/typo3/sysext/filelist/Classes/Controller/FileListController.php index dad420cf0be53c6d9b87f92462689ded00949bff..da3d6c9519be8fb62c05b921b7b0332673778796 100644 --- a/typo3/sysext/filelist/Classes/Controller/FileListController.php +++ b/typo3/sysext/filelist/Classes/Controller/FileListController.php @@ -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' + ); } /** diff --git a/typo3/sysext/filelist/Classes/FileFacade.php b/typo3/sysext/filelist/Classes/FileFacade.php index 744d3d689ebbaf5fc84c90981e4614dabbe049cb..fe66ce4bb51f4e269d26588d4831418bc7562838 100644 --- a/typo3/sysext/filelist/Classes/FileFacade.php +++ b/typo3/sysext/filelist/Classes/FileFacade.php @@ -140,6 +140,14 @@ class FileFacade return strtoupper($this->resource->getExtension()); } + /** + * @return string + */ + public function getIdentifier() + { + return $this->resource->getStorage()->getUid() . ':' . $this->resource->getIdentifier(); + } + /** * @return string */ diff --git a/typo3/sysext/filelist/Classes/FileList.php b/typo3/sysext/filelist/Classes/FileList.php index 81794f98c387fb208d21bb7bb1ec32bee39333b3..6a1d5609cc828bf720b7a645d1430830e88cd101 100644 --- a/typo3/sysext/filelist/Classes/FileList.php +++ b/typo3/sysext/filelist/Classes/FileList.php @@ -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; } diff --git a/typo3/sysext/filelist/Resources/Private/Templates/FileList/Search.html b/typo3/sysext/filelist/Resources/Private/Templates/FileList/Search.html index f48a0e7fd6d90cb062f58894d7faa49bab2bd9c7..b5aa5ff248b2790b49d2368272de06d0ba932ee8 100644 --- a/typo3/sysext/filelist/Resources/Private/Templates/FileList/Search.html +++ b/typo3/sysext/filelist/Resources/Private/Templates/FileList/Search.html @@ -130,10 +130,15 @@ </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 index 0000000000000000000000000000000000000000..b336c17b1c4c711c8bcd60f556cc15e499259625 --- /dev/null +++ b/typo3/sysext/filelist/Resources/Public/JavaScript/FileDelete.js @@ -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; + } + }); + +}); diff --git a/typo3/sysext/filelist/Resources/Public/JavaScript/FileList.js b/typo3/sysext/filelist/Resources/Public/JavaScript/FileList.js index cce41d81edb2ab086521dad94972ca19b695bb16..9bbc831f621befe6dcba57ba46cafd90586c4011 100644 --- a/typo3/sysext/filelist/Resources/Public/JavaScript/FileList.js +++ b/typo3/sysext/filelist/Resources/Public/JavaScript/FileList.js @@ -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(); diff --git a/typo3/sysext/lang/locallang_alt_doc.xlf b/typo3/sysext/lang/locallang_alt_doc.xlf index 5f7c567ccf951888e8b404887677d104aeba36a3..16a3df292bfbb64ee29b5c50183ac41467782d40 100644 --- a/typo3/sysext/lang/locallang_alt_doc.xlf +++ b/typo3/sysext/lang/locallang_alt_doc.xlf @@ -54,6 +54,12 @@ <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>