[TASK] File-List should allow quick access to translations 52/24752/4
authorSteffen Ritter <info@rs-websystems.de>
Sat, 12 Oct 2013 09:17:41 +0000 (11:17 +0200)
committerXavier Perseguers <xavier@typo3.org>
Tue, 15 Oct 2013 14:08:14 +0000 (16:08 +0200)
File-Metadata has been configured to be translatable.
In List-Module we are used to also see the translated
records. To help editors this possibility is introduced
to the file list to.

Based on the fact that for a file all listed properties
would be the same than in every language, a different
implementation has been used.

The icons and the formatting is prelimary and subject
to be changed by the usability team.

Resolves: #52817
Releases: 6.2
Change-Id: I0016b8c9fe543d3bab3e77dc37ae7bb67acc97b0
Reviewed-on: https://review.typo3.org/24752
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
Reviewed-by: Wouter Wolters
Reviewed-by: Fabien Udriot
Tested-by: Fabien Udriot
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
typo3/sysext/backend/Resources/Public/JavaScript/FileListLocalisation.js [new file with mode: 0644]
typo3/sysext/filelist/Classes/Controller/FileListController.php
typo3/sysext/filelist/Classes/FileList.php

diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/FileListLocalisation.js b/typo3/sysext/backend/Resources/Public/JavaScript/FileListLocalisation.js
new file mode 100644 (file)
index 0000000..286f878
--- /dev/null
@@ -0,0 +1,31 @@
+/***************************************************************
+ *
+ *  Copyright notice
+ *
+ *  (c) 2013 Steffen Ritter <steffen.ritter@typo3.org>
+ *  All rights reserved
+ *
+ *  Released under GNU/GPL2+ (see license file in the main directory)
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *  This copyright notice MUST APPEAR in all copies of this script
+ *
+ ***************************************************************/
+/**
+ * JavaScript RequireJS module called "TYPO3/CMS/Backend/FileListLocalisation"
+ *
+ */
+define('TYPO3/CMS/Backend/FileListLocalisation', ['jquery'], function($) {
+
+
+       $('a.filelist-translationToggler').click(function(event) {
+               var id = $(this).attr('data-fileid');
+               $('tr[data-fileid="' + id + '"]').toggle();
+       });
+       $('tr.localisationData').hide();
+
+       return null;
+});
\ No newline at end of file
index 7963a9e..862c54d 100644 (file)
@@ -219,6 +219,7 @@ class FileListController {
                $this->doc->getPageRenderer()->loadPrototype();
                $this->doc->getPageRenderer()->loadJQuery();
                $this->doc->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/DragUploader');
+               $this->doc->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/FileListLocalisation');
                $this->doc->getPageRenderer()->addInlineLanguagelabelFile(
                        \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('lang') . 'locallang_core.xlf',
                        'file_upload'
index 1cfc2dd..91a5349 100644 (file)
@@ -575,13 +575,14 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
         */
        public function formatFileList(array $files) {
                $out = '';
+               // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
+               $systemLanguages = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider')->getSystemLanguages();
                foreach ($files as $fileObject) {
                        list($flag, $code) = $this->fwd_rwd_nav();
                        $out .= $code;
                        if ($flag) {
                                // Initialization
                                $this->counter++;
-                               $fileInfo = $fileObject->getStorage()->getFileInfo($fileObject);
                                $this->totalbytes += $fileObject->getSize();
                                $ext = $fileObject->getExtension();
                                $fileName = trim($fileObject->getName());
@@ -604,7 +605,7 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                                                        $theData[$field] = strtoupper($ext);
                                                        break;
                                                case 'tstamp':
-                                                       $theData[$field] = BackendUtility::date($fileInfo['mtime']);
+                                                       $theData[$field] = BackendUtility::date($fileObject->getProperty('modification_date'));
                                                        break;
                                                case '_CLIPBOARD_':
                                                        $temp = '';
@@ -612,6 +613,10 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                                                                $temp .= $this->makeEdit($fileObject);
                                                        }
                                                        $temp .= $this->makeClip($fileObject);
+                                                       if (count($systemLanguages) > 2) {
+                                                               $temp .= '<a class="filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' .
+                                                                       IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay') . '</a>';
+                                                       }
                                                        $theData[$field] = $temp;
                                                        break;
                                                case '_REF_':
@@ -633,11 +638,49 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                                                        }
                                                        break;
                                                default:
-                                                       // @todo: fix the access on the array
-                                                       $theData[$field] = htmlspecialchars(GeneralUtility::fixed_lgd_cs($theFile[$field], $this->fixedL));
+                                                       $theData[$field] = '';
+                                                       if ($fileObject->hasProperty($field)) {
+                                                               $theData[$field] = htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getProperty($field), $this->fixedL));
+                                                       }
                                        }
                                }
                                $out .= $this->addelement(1, $theIcon, $theData, ' class="file_list_normal"');
+
+                               $metaDataRecord = $fileObject->_getMetaData();
+                               $translations = $this->getTranslationsForMetaData($metaDataRecord);
+                               if (count($systemLanguages) > 2) {
+                                       $code = IconUtility::getSpriteIcon('empty-empty');
+                                       foreach ($systemLanguages as $language) {
+                                               $languageId = $language['uid'];
+                                               if ($languageId == -1 || $languageId == 0) {
+                                                       continue;
+                                               }
+                                               $flagIcon = $language['flagIcon'];
+                                               if (array_key_exists($languageId, $translations)) {
+
+                                                       $theIcon = IconUtility::getSpriteIcon(
+                                                               'actions-document-open',
+                                                               array('title' => $fileName),
+                                                               array($flagIcon . '-overlay' => array()));
+                                                       $data = array(
+                                                               'sys_file_metadata' => array($translations[$languageId]['uid'] => 'edit')
+                                                       );
+                                                       $editOnClick = BackendUtility::editOnClick(GeneralUtility::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
+                                                       $code .= sprintf('<a href="#" onclick="%s">%s</a>', htmlspecialchars($editOnClick), $theIcon);
+
+                                               } else {
+                                                       $href = $GLOBALS['SOBE']->doc->issueCommand(
+                                                               '&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId,
+                                                               $this->backPath . 'alt_doc.php?justLocalized=' . rawurlencode(('sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId)) .
+                                                               '&returnUrl=' . rawurlencode($this->listURL()) . BackendUtility::getUrlToken('editRecord')
+                                                       );
+                                                       $theIcon = IconUtility::getSpriteIcon($flagIcon);
+
+                                                       $code .= sprintf('<a href="%s">%s</a>', htmlspecialchars($href), $theIcon);
+                                               }
+                                       }
+                                       $out .= '<tr class="file_list_normal localisationData" data-fileid="' . $fileObject->getUid() . '"><td></td><td colspan="' . count($this->fieldArray) . '">' . $code . '</td></tr>';
+                               }
                        }
                        $this->eCounter++;
                }
@@ -645,6 +688,23 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
        }
 
        /**
+        * Fetch the translations for a sys_file_metadata record
+        *
+        * @param $metaDataRecord
+        * @return array keys are the sys_language uids, values are the $rows
+        */
+       protected function getTranslationsForMetaData($metaDataRecord) {
+               $where = $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'] . '=' . intval($metaDataRecord['uid']) .
+                       ' AND ' . $GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'] . '>0';
+               $translationRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_file_metadata', $where);
+               $translations = array();
+               foreach ($translationRecords as $record) {
+                       $translations[$record[$GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField']]] = $record;
+               }
+               return $translations;
+       }
+
+       /**
         * Returns TRUE if $ext is an image-extension according to $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
         *
         * @param string $ext File extension