[TASK] Fluidification of TaskCenter 02/50002/3
authorMichael Oehlhof <typo3@oehlhof.de>
Wed, 21 Sep 2016 14:42:49 +0000 (16:42 +0200)
committerJan Helke <typo3@helke.de>
Thu, 6 Oct 2016 16:19:14 +0000 (18:19 +0200)
Resolves: #78020
Releases: master
Change-Id: Ibb70677e09a39fe73532e1af8cd6266b0d2b9a1e
Reviewed-on: https://review.typo3.org/50002
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Sommer <markussom@posteo.de>
Tested-by: Markus Sommer <markussom@posteo.de>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/taskcenter/Classes/Controller/TaskModuleController.php
typo3/sysext/taskcenter/Resources/Private/Partials/Description.html [new file with mode: 0644]
typo3/sysext/taskcenter/Resources/Private/Partials/UrlInIframe.html [new file with mode: 0644]
typo3/sysext/taskcenter/Resources/Private/Templates/InformationContent.html [new file with mode: 0644]
typo3/sysext/taskcenter/Resources/Private/Templates/ListMenu.html [new file with mode: 0644]
typo3/sysext/taskcenter/Resources/Private/Templates/ModuleContent.html [new file with mode: 0644]

index da4e5c5..fe9a32e 100644 (file)
@@ -19,10 +19,10 @@ use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Backend\Module\BaseScriptClass;
 use TYPO3\CMS\Backend\Template\ModuleTemplate;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
-use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
+use TYPO3\CMS\Fluid\View\StandaloneView;
 use TYPO3\CMS\Taskcenter\TaskInterface;
 
 /**
@@ -226,21 +226,18 @@ class TaskModuleController extends BaseScriptClass
             $defaultFlashMessageQueue->enqueue($flashMessage);
         }
 
-        $content = '<div class="taskcenter">
-                        <div class="row">
-                            <div class="col-sm-4 col-md-3">
-                                <div class="taskcenter-menu">
-                                    ' . $this->indexAction() . '
-                                </div>
-                            </div>
-                            <div class="col-sm-8 col-md-9">
-                                <div class="taskcenter-content taskcenter-content-' . strtolower(str_replace('\\', '-', htmlspecialchars(($extKey . '-' . $taskClass)))) . '">
-                                    ' . $actionContent . '
-                                </div>
-                            </div>
-                        </div>
-                    </div>';
-        $this->content .= $content;
+        $assigns = [];
+        $assigns['reports'] = $this->indexAction();
+        $assigns['taskClass'] = strtolower(str_replace('\\', '-', htmlspecialchars(($extKey . '-' . $taskClass))));
+        $assigns['actionContent'] = $actionContent;
+
+        // Rendering of the output via fluid
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
+            'EXT:taskcenter/Resources/Private/Templates/ModuleContent.html'
+        ));
+        $view->assignMultiple($assigns);
+        $this->content .=  $view->render();
     }
 
     /**
@@ -250,12 +247,21 @@ class TaskModuleController extends BaseScriptClass
      */
     protected function renderInformationContent()
     {
-        $content = $this->description($this->getLanguageService()->getLL('mlang_tabs_tab'), $this->getLanguageService()->sL('LLL:EXT:taskcenter/Resources/Private/Language/locallang_mod.xlf:mlang_labels_tabdescr'));
-        $content .= $this->getLanguageService()->getLL('taskcenter-about');
-        if ($this->getBackendUser()->isAdmin()) {
-            $content .= '<br /><br />' . $this->description($this->getLanguageService()->getLL('taskcenter-adminheader'), $this->getLanguageService()->getLL('taskcenter-admin'));
-        }
-        $this->content .= $content;
+        $assigns = [];
+        $assigns['LLPrefix'] = 'LLL:EXT:taskcenter/Resources/Private/Language/locallang.xlf:';
+        $assigns['LLPrefixMod'] = 'LLL:EXT:taskcenter/Resources/Private/Language/locallang_mod.xlf:';
+        $assigns['LLPrefixTask'] = 'LLL:EXT:taskcenter/Resources/Private/Language/locallang_task.xlf:';
+        $assigns['admin'] = $this->getBackendUser()->isAdmin();
+
+        // Rendering of the output via fluid
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:taskcenter/Resources/Private/Templates')]);
+        $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:taskcenter/Resources/Private/Partials')]);
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
+            'EXT:taskcenter/Resources/Private/Templates/InformationContent.html'
+        ));
+        $view->assignMultiple($assigns);
+        $this->content .=  $view->render();
     }
 
     /**
@@ -267,15 +273,17 @@ class TaskModuleController extends BaseScriptClass
      */
     public function description($title, $description = '')
     {
-        $content = '<h1>' . nl2br(htmlspecialchars($title)) . '</h1>';
-        if (!empty($description)) {
-            $content .= '<p>' . nl2br(htmlspecialchars($description)) . '</p>';
-        }
-        return $content;
+        $descriptionView = GeneralUtility::makeInstance(StandaloneView::class);
+        $descriptionView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
+            'EXT:taskcenter/Resources/Private/Partials/Description.html'
+        ));
+        $descriptionView->assign('title', $title);
+        $descriptionView->assign('description', $description);
+        return $descriptionView->render();
     }
 
     /**
-     * Render a list of items as a nicely formated definition list including a
+     * Render a list of items as a nicely formatted definition list including a
      * link, icon, title and description.
      * The keys of a single item are:
      * - title:             Title of the item
@@ -287,15 +295,15 @@ class TaskModuleController extends BaseScriptClass
      *
      * @param array $items List of items to be displayed in the definition list.
      * @param bool $mainMenu Set it to TRUE to render the main menu
-     * @return string Fefinition list
+     * @return string Formatted definition list
      */
     public function renderListMenu($items, $mainMenu = false)
     {
-        $content = ($section = '');
-        $count = 0;
+        $assigns = [];
+        $assigns['mainMenu'] = $mainMenu;
+
         // Change the sorting of items to the user's one
         if ($mainMenu) {
-            $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Taskcenter/Taskcenter');
             $userSorting = unserialize($this->getBackendUser()->uc['taskcenter']['sorting']);
             if (is_array($userSorting)) {
                 $newSorting = [];
@@ -309,67 +317,44 @@ class TaskModuleController extends BaseScriptClass
             }
         }
         if (is_array($items) && !empty($items)) {
-            foreach ($items as $itemKey => $item) {
-                $title = htmlspecialchars($item['title']);
-                $icon = ($additionalClass = ($collapsedStyle = ''));
+            foreach ($items as $itemKey => &$item) {
                 // Check for custom icon
                 if (!empty($item['icon'])) {
                     if (strpos($item['icon'], '<img ') === false) {
                         $iconFile = GeneralUtility::getFileAbsFileName($item['icon']);
                         if (@is_file($iconFile)) {
-                            $icon = '<img src="' . htmlspecialchars(PathUtility::getAbsoluteWebPath($iconFile)) . '" width="16" height="16" title="' . $title . '" alt="' . $title . '" />';
+                            $item['iconFile'] = PathUtility::getAbsoluteWebPath($iconFile);
                         }
-                    } else {
-                        $icon = $item['icon'];
                     }
                 }
-                $description = $item['descriptionHtml'] ?: '<p>' . nl2br(htmlspecialchars($item['description'])) . '</p>';
                 $id = $this->getUniqueKey($item['uid']);
                 $contentId = strtolower(str_replace('\\', '-', $id));
+                $item['uniqueKey'] = $id;
+                $item['contentId'] = $contentId;
                 // Collapsed & expanded menu items
                 if (isset($this->getBackendUser()->uc['taskcenter']['states'][$id]) && $this->getBackendUser()->uc['taskcenter']['states'][$id]) {
-                    $collapsed = true;
-                    $collapseIcon = $this->moduleTemplate->getIconFactory()->getIcon('actions-view-list-expand', Icon::SIZE_SMALL)->render('inline');
+                    $item['ariaExpanded'] = 'true';
+                    $item['collapseIcon'] = 'actions-view-list-expand';
+                    $item['collapsed'] = '';
                 } else {
-                    $collapsed = false;
-                    $collapseIcon = $this->moduleTemplate->getIconFactory()->getIcon('actions-view-list-collapse', Icon::SIZE_SMALL)->render('inline');
+                    $item['ariaExpanded'] = 'false';
+                    $item['collapseIcon'] = 'actions-view-list-collapse';
+                    $item['collapsed'] = 'in';
                 }
                 // Active menu item
                 $panelState = (string)$this->MOD_SETTINGS['function'] == $item['uid'] ? 'panel-active' : 'panel-default';
-                $content .= '<li id="el_' . $id . '">
-                                <div id="' . $contentId . '" data-taskcenter-id="' . $id . '" class="panel ' . $panelState . '">
-                                    <div class="panel-heading">
-                                        <div class="panel-heading-right">
-                                            <a href="#task_content_' . $contentId . '" class="panel-header-collapse t3js-taskcenter-header-collapse" role="button" data-toggle="collapse" data-uid="' . $contentId . '" aria-expanded="' . ($collapsed ? 'false' : 'true') . '">
-                                                ' . $collapseIcon . '
-                                            </a>
-                                        </div>
-                                        <div class="panel-heading-left">
-                                            <a href="' . $item['link'] . '" class="panel-title">
-                                                ' . ($icon ? '<span class="panel-title-icon">' . $icon . '</span>' : '') . '
-                                                <span class="panel-title-name">'
-                                                    . $title . ' '
-                                                    . $this->moduleTemplate->getIconFactory()->getIcon(
-                                                        'actions-view-table-expand',
-                                                        Icon::SIZE_SMALL
-                                                    )->render('inline')
-                                                . '</span>
-                                            </a>
-                                        </div>
-                                    </div>
-                                    <div id="task_content_' . $contentId . '" class="panel-collapse collapse t3js-taskcenter-collapse ' . ($collapsed ? '' : 'in') . '" aria-expanded="true">
-                                        <div class="panel-body">
-                                            ' . $description . '
-                                        </div>
-                                    </div>
-                                </div>
-                                                       </li>';
-                $count++;
+                $item['panelState'] = $panelState;
             }
-            $navigationId = $mainMenu ? 'id="task-list"' : '';
-            $content = '<ul ' . $navigationId . ' class="list-unstyled">' . $content . '</ul>';
         }
-        return $content;
+        $assigns['items'] = $items;
+
+        // Rendering of the output via fluid
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
+            'EXT:taskcenter/Resources/Private/Templates/ListMenu.html'
+        ));
+        $view->assignMultiple($assigns);
+        return $view->render();
     }
 
     /**
@@ -481,7 +466,12 @@ class TaskModuleController extends BaseScriptClass
      */
     public function urlInIframe($url)
     {
-        return '<div class="panel panel-default"><iframe scrolling="auto"  width="100%" src="' . $url . '" name="list_frame" id="list_frame" frameborder="no" style="height: 500px"></iframe></div>';
+        $urlView = GeneralUtility::makeInstance(StandaloneView::class);
+        $urlView->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
+            'EXT:taskcenter/Resources/Private/Partials/UrlInIframe.html'
+        ));
+        $urlView->assign('url', $url);
+        return $urlView->render();
     }
 
     /**
diff --git a/typo3/sysext/taskcenter/Resources/Private/Partials/Description.html b/typo3/sysext/taskcenter/Resources/Private/Partials/Description.html
new file mode 100644 (file)
index 0000000..052a910
--- /dev/null
@@ -0,0 +1,6 @@
+<h1>{title -> f:format.nl2br()}</h1>
+<f:if condition="{description}">
+    <p>
+        {description -> f:format.nl2br()}
+    </p>
+</f:if>
diff --git a/typo3/sysext/taskcenter/Resources/Private/Partials/UrlInIframe.html b/typo3/sysext/taskcenter/Resources/Private/Partials/UrlInIframe.html
new file mode 100644 (file)
index 0000000..1096fc9
--- /dev/null
@@ -0,0 +1,3 @@
+<div class="panel panel-default">
+    <iframe scrolling="auto"  width="100%" src="{url}" name="list_frame" id="list_frame" frameborder="no" style="height: 500px"></iframe>
+</div>
\ No newline at end of file
diff --git a/typo3/sysext/taskcenter/Resources/Private/Templates/InformationContent.html b/typo3/sysext/taskcenter/Resources/Private/Templates/InformationContent.html
new file mode 100644 (file)
index 0000000..0032771
--- /dev/null
@@ -0,0 +1,8 @@
+<f:render partial="Description" arguments="{title: '{f:translate(key: \'{LLPrefix}mlang_tabs_tab\')}', description: '{f:translate(key: \'{LLPrefixMod}mlang_labels_tabdescr\')}'}" />
+<f:format.raw>
+    <f:translate key="{LLPrefixTask}taskcenter-about"/>
+</f:format.raw>
+<f:if condition="{admin}">
+    <br /><br />
+    <f:render partial="Description" arguments="{title: '{f:translate(key: \'{LLPrefixTask}taskcenter-adminheader\')}', description: '{f:translate(key: \'{LLPrefixTask}taskcenter-admin\')}'}" />
+</f:if>
diff --git a/typo3/sysext/taskcenter/Resources/Private/Templates/ListMenu.html b/typo3/sysext/taskcenter/Resources/Private/Templates/ListMenu.html
new file mode 100644 (file)
index 0000000..058a1f4
--- /dev/null
@@ -0,0 +1,64 @@
+{namespace core=TYPO3\CMS\Core\ViewHelpers}
+
+<f:if condition="{mainMenu}">
+    <f:then>
+        <f:be.pageRenderer loadJQuery="false" includeRequireJsModules="{0:'TYPO3/CMS/Taskcenter/Taskcenter'}" />
+        <ul id="task-list" class="list-unstyled">
+    </f:then>
+    <f:else>
+        <ul class="list-unstyled">
+    </f:else>
+</f:if>
+<f:for each="{items}" as="item" key="itemKey">
+    <f:render section="Item" arguments="{item: item, itemKey: itemKey}" />
+</f:for>
+
+</ul>
+
+<f:section name="Item">
+    <li id="el_{item.uniqueKey}">
+        <div id="{item.contentId}" data-taskcenter-id="{item.uniqueKey}" class="panel {item.panelState}">
+            <div class="panel-heading">
+                <div class="panel-heading-right">
+                    <a href="#task_content_{item.contentId}" class="panel-header-collapse t3js-taskcenter-header-collapse" role="button" data-toggle="collapse" data-uid="{item.contentId}" aria-expanded="{item.ariaExpanded}">
+                        <core:icon identifier="{item.collapseIcon}" />
+                    </a>
+                </div>
+                <div class="panel-heading-left">
+                    <a href="{item.link}" class="panel-title">
+                        <f:if condition="{item.icon}">
+                            <span class="panel-title-icon">
+                                <f:if condition="{item.iconFile}">
+                                    <f:then>
+                                        <img src="{item.iconFile}" width="16" height="16" title="{item.title}" alt="{item.title}" />
+                                    </f:then>
+                                    <f:else>
+                                        {item.icon -> f:format.raw()}
+                                    </f:else>
+                                </f:if>
+                            </span>
+                        </f:if>
+                        <span class="panel-title-name">
+                            {item.title}
+                            <core:icon identifier="actions-view-table-expand" />
+                        </span>
+                    </a>
+                </div>
+            </div>
+            <div id="task_content_{item.contentId}" class="panel-collapse collapse t3js-taskcenter-collapse {item.collapsed}" aria-expanded="true">
+                <div class="panel-body">
+                    <f:if condition="{item.descriptionHtml}">
+                        <f:then>
+                            {item.descriptionHtml -> f:format.raw()}
+                        </f:then>
+                        <f:else>
+                            <p>
+                                {item.description -> f:format.nl2br()}
+                            </p>
+                        </f:else>
+                    </f:if>
+                </div>
+            </div>
+        </div>
+    </li>
+</f:section>
\ No newline at end of file
diff --git a/typo3/sysext/taskcenter/Resources/Private/Templates/ModuleContent.html b/typo3/sysext/taskcenter/Resources/Private/Templates/ModuleContent.html
new file mode 100644 (file)
index 0000000..32e055a
--- /dev/null
@@ -0,0 +1,14 @@
+<div class="taskcenter">
+    <div class="row">
+        <div class="col-sm-4 col-md-3">
+            <div class="taskcenter-menu">
+                {reports -> f:format.raw()}
+            </div>
+        </div>
+        <div class="col-sm-8 col-md-9">
+            <div class="taskcenter-content taskcenter-content-{taskClass}">
+                {actionContent -> f:format.raw()}
+            </div>
+        </div>
+    </div>
+</div>
\ No newline at end of file