[TASK] Sort and create page wizard cleanup 26/32626/6
authorWouter Wolters <typo3@wouterwolters.nl>
Sun, 7 Sep 2014 21:25:17 +0000 (23:25 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Mon, 8 Sep 2014 20:21:46 +0000 (22:21 +0200)
* Move ExtJs code to jQuery
* Remove unused method modMenu
* Use boolean values in functions if possible

Resolves: #61451
Releases: 6.3
Change-Id: Ibf00d23112ced8744dc356dcb11c1914deb3a91a
Reviewed-on: http://review.typo3.org/32626
Tested-by: Stefan Froemken <froemken@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/wizard_crpages/Classes/Controller/CreatePagesWizardModuleFunctionController.php
typo3/sysext/wizard_crpages/Resources/Public/JavaScript/WizardCreatePages.js [new file with mode: 0644]
typo3/sysext/wizard_sortpages/Classes/View/SortPagesWizardModuleFunction.php

index a66506c..b92a6e2 100644 (file)
@@ -46,28 +46,9 @@ class CreatePagesWizardModuleFunctionController extends \TYPO3\CMS\Backend\Modul
        protected $pagesTsConfig = array();
 
        /**
-        * Adds menu items... but I think this is not used at all. Looks very much like some testing code. If anyone cares to check it we can remove it some day...
-        *
-        * @return array
-        * @ignore
-        * @todo Define visibility
-        */
-       public function modMenu() {
-               global $LANG;
-               $modMenuAdd = array(
-                       'cr_333' => array(
-                               '0' => 'nul',
-                               '1' => 'et'
-                       )
-               );
-               return $modMenuAdd;
-       }
-
-       /**
         * Main function creating the content for the module.
         *
         * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
-        * @todo Define visibility
         */
        public function main() {
                $GLOBALS['LANG']->includeLLFile('EXT:wizard_crpages/locallang.xlf');
@@ -82,7 +63,7 @@ class CreatePagesWizardModuleFunctionController extends \TYPO3\CMS\Backend\Modul
                $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(8);
                $pRec = BackendUtility::getRecord('pages', $this->pObj->id, 'uid', ' AND ' . $m_perms_clause);
                $sys_pages = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
-               $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', 0);
+               $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', FALSE);
                if (is_array($pRec)) {
                        $data = GeneralUtility::_GP('data');
                        if (is_array($data['pages'])) {
@@ -112,7 +93,7 @@ class CreatePagesWizardModuleFunctionController extends \TYPO3\CMS\Backend\Modul
                                                $previousIdentifier = $identifier;
                                        }
                                }
-                               if (count($data['pages'])) {
+                               if (!empty($data['pages'])) {
                                        reset($data);
                                        $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
                                        $tce->stripslashes_values = 0;
@@ -152,24 +133,15 @@ class CreatePagesWizardModuleFunctionController extends \TYPO3\CMS\Backend\Modul
                                <input type="checkbox" name="hidePages" id="hidePages" value="1" /> <label for="hidePages">' . $GLOBALS['LANG']->getLL('wiz_newPages_hidePages') . '</label><br />
                                <input type="checkbox" name="hidePagesInMenus" id="hidePagesInMenus" value="1" /> <label for="hidePagesInMenus">' . $GLOBALS['LANG']->getLL('wiz_newPages_hidePagesInMenus') . '</label><br /><br />
                                <input type="submit" name="create" value="' . $GLOBALS['LANG']->getLL('wiz_newPages_lCreate') . '" />&nbsp;<input type="reset" value="' . $GLOBALS['LANG']->getLL('wiz_newPages_lReset') . '" /><br />';
-                               // Add ExtJS inline code
-                               $extCode = '
-                                       var tpl = "' . addslashes(str_replace(array(LF, TAB), array('', ''), $this->getFormLine('#'))) . '", i, line, div, bg, label;
-                                       var lineCounter = 9;
-                                       Ext.get("createNewFormFields").on("click", function() {
-                                               div = Ext.get("formFieldContainerBody");
-                                               for (i = 0; i < 5; i++) {
-                                                       label = lineCounter + i + 1;
-                                                       line = String.format(tpl, (lineCounter + i), label);
-                                                       div.insertHtml("beforeEnd", line);
-                                               }
-                                               lineCounter += 5;
-                                       });
-                               ';
+
                                /** @var \TYPO3\CMS\Core\Page\PageRenderer */
                                $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
-                               $pageRenderer->loadExtJS();
-                               $pageRenderer->addExtOnReadyCode($extCode);
+                               $pageRenderer->loadJquery();
+                               $pageRenderer->loadRequireJsModule('TYPO3/CMS/WizardCrpages/WizardCreatePages');
+                               // Add inline code
+                               $inlineJavaScriptCode = 'var tpl = "' . addslashes(str_replace(array(LF, TAB), array('', ''), $this->getFormLine('#'))) . '", i, line, div, bg, label;';
+                               $pageRenderer->addJsInlineCode('wizard_crpages', $inlineJavaScriptCode);
+
                                $pageRenderer->addCssInlineBlock('TYPO3\CMS\WizardCrpages\Controller\CreatePagesWizardModuleFunctionController', '
                                #formFieldContainer {float: left; margin: 0 0 10px 0;}
                                .clearLeft {clear: left;}
@@ -183,7 +155,7 @@ class CreatePagesWizardModuleFunctionController extends \TYPO3\CMS\Backend\Modul
                // CSH
                $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardcrpages', $GLOBALS['BACK_PATH'], '<br />|');
                $out = $this->pObj->doc->header($GLOBALS['LANG']->getLL('wiz_crMany'));
-               $out .= $this->pObj->doc->section('', $theCode, 0, 1);
+               $out .= $this->pObj->doc->section('', $theCode, FALSE, TRUE);
                return $out;
        }
 
@@ -198,7 +170,7 @@ class CreatePagesWizardModuleFunctionController extends \TYPO3\CMS\Backend\Modul
                if (is_numeric($index)) {
                        $label = $index + 1;
                } else {
-                       // used as template for ExtJS
+                       // used as template for JavaScript
                        $index = '{0}';
                        $label = '{1}';
                }
@@ -210,7 +182,7 @@ class CreatePagesWizardModuleFunctionController extends \TYPO3\CMS\Backend\Modul
                $content .= is_object($this->loremIpsumObject) ? '<a href="#" onclick="' . htmlspecialchars($this->loremIpsumObject->getHeaderTitleJS(('document.forms[0][\'data[pages][NEW' . $index . '][title]\'].value'), 'title')) . '">' . $this->loremIpsumObject->getIcon('', $this->pObj->doc->backPath) . '</a>' : '';
                // type selector
                $content .= '<span>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.type') . '</span>';
-               $content .= '<select onchange="this.style.backgroundImage=this.options[this.selectedIndex].style.backgroundImage;if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex=1;}" ';
+               $content .= '<select id="type-select"';
                $content .= 'class="select icon-select" name="data[pages][NEW' . $index . '][doktype]" style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); padding: 1px 1px 1px 24px;">';
                // dokType
                $types = $GLOBALS['PAGES_TYPES'];
diff --git a/typo3/sysext/wizard_crpages/Resources/Public/JavaScript/WizardCreatePages.js b/typo3/sysext/wizard_crpages/Resources/Public/JavaScript/WizardCreatePages.js
new file mode 100644 (file)
index 0000000..446cb21
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * 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!
+ */
+
+define('TYPO3/CMS/WizardCrpages/WizardCreatePages', ['jquery'], function($) {
+
+       var WizardCreatePages = {};
+
+       var lineCounter = 9;
+
+       WizardCreatePages.createNewFormFields = function() {
+               for (i = 0; i < 5; i++) {
+                       var label = lineCounter + i + 1;
+                       var line = String.format(tpl, (lineCounter + i), label);
+                       $(line).appendTo('#formFieldContainerBody');
+               }
+               lineCounter += 5;
+       };
+
+       WizardCreatePages.actOnTypeSelectChange = function(element) {
+               var selectedElement = element.find(':selected');
+               element.css('background-image', selectedElement.css('background-image'));
+       };
+
+       /**
+        * Register listeners
+        */
+       WizardCreatePages.initializeEvents = function() {
+               $('#createNewFormFields').on('click', function() {
+                       WizardCreatePages.createNewFormFields();
+               });
+
+               $('#type-select').change(function() {
+                       WizardCreatePages.actOnTypeSelectChange($(this));
+               });
+       };
+
+       return function() {
+               $(document).ready(function() {
+                       WizardCreatePages.initializeEvents();
+               });
+
+               TYPO3.WizardCreatePages = WizardCreatePages;
+               return WizardCreatePages;
+       }();
+});
\ No newline at end of file
index 8c1db8f..133532e 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\WizardSortpages\View;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Creates the "Sort pages" wizard
@@ -24,23 +25,9 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
 class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
 
        /**
-        * Adds menu items... but I think this is not used at all. Looks very much like some testing code. If anyone cares to check it we can remove it some day...
-        *
-        * @return array
-        * @ignore
-        * @todo Define visibility
-        */
-       public function modMenu() {
-               global $LANG;
-               $modMenuAdd = array();
-               return $modMenuAdd;
-       }
-
-       /**
         * Main function creating the content for the module.
         *
         * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
-        * @todo Define visibility
         */
        public function main() {
                $GLOBALS['LANG']->includeLLFile('EXT:wizard_sortpages/locallang.xlf');
@@ -48,18 +35,18 @@ class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFu
                if ($GLOBALS['BE_USER']->workspace === 0) {
                        $theCode = '';
                        // Check if user has modify permissions to
-                       $sys_pages = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
-                       $sortByField = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('sortByField');
+                       $sys_pages = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
+                       $sortByField = GeneralUtility::_GP('sortByField');
                        if ($sortByField) {
                                $menuItems = array();
-                               if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('title,subtitle,crdate,tstamp', $sortByField)) {
+                               if (GeneralUtility::inList('title,subtitle,crdate,tstamp', $sortByField)) {
                                        $menuItems = $sys_pages->getMenu($this->pObj->id, 'uid,pid,title', $sortByField, '', FALSE);
-                               } elseif ($sortByField == 'REV') {
+                               } elseif ($sortByField === 'REV') {
                                        $menuItems = $sys_pages->getMenu($this->pObj->id, 'uid,pid,title', 'sorting', '', FALSE);
                                        $menuItems = array_reverse($menuItems);
                                }
-                               if (count($menuItems)) {
-                                       $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
+                               if (!empty($menuItems)) {
+                                       $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
                                        $tce->stripslashes_values = 0;
                                        $menuItems = array_reverse($menuItems);
                                        $cmd = array();
@@ -73,11 +60,11 @@ class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFu
                        }
                        $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', FALSE);
 
-                       if (count($menuItems)) {
+                       if (!empty($menuItems)) {
                                $lines = array();
                                $lines[] = '<thead><tr>';
                                $lines[] = '<th>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_title'), 'title') . '</th>';
-                               $lines[] = '<th> ' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_subtitle'), 'subtitle') . '</th>';
+                               $lines[] = '<th>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_subtitle'), 'subtitle') . '</th>';
                                $lines[] = '<th>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tChange'), 'tstamp') . '</th>';
                                $lines[] = '<th>' . $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_tCreate'), 'crdate') . '</th>';
                                $lines[] = '</tr></thead>';
@@ -86,8 +73,8 @@ class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFu
                                        $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(2);
                                        // edit permissions for that page!
                                        $pRec = BackendUtility::getRecord('pages', $rec['uid'], 'uid', ' AND ' . $m_perms_clause);
-                                       $lines[] = '<tr class="db_list_normal"><td nowrap="nowrap">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $rec) . (!is_array($pRec) ? $GLOBALS['TBE_TEMPLATE']->rfw('<strong>' . $GLOBALS['LANG']->getLL('wiz_W', TRUE) . '</strong> ') : '') . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</td>
-                                       <td nowrap="nowrap">' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($rec['subtitle'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</td>
+                                       $lines[] = '<tr class="db_list_normal"><td nowrap="nowrap">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $rec) . (!is_array($pRec) ? $GLOBALS['TBE_TEMPLATE']->rfw('<strong>' . $GLOBALS['LANG']->getLL('wiz_W', TRUE) . '</strong> ') : '') . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</td>
+                                       <td nowrap="nowrap">' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['subtitle'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</td>
                                        <td nowrap="nowrap">' . BackendUtility::datetime($rec['tstamp']) . '</td>
                                        <td nowrap="nowrap">' . BackendUtility::datetime($rec['crdate']) . '</td>
                                        </tr>';
@@ -105,14 +92,14 @@ class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFu
                                $lines[] = $this->wiz_linkOrder($GLOBALS['LANG']->getLL('wiz_changeOrder_REVERSE'), 'REV');
                                $theCode .= '<h4>' . $GLOBALS['LANG']->getLL('wiz_changeOrder') . '</h4>' . implode('<br />', $lines);
                        } else {
-                               $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('no_subpages'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE);
+                               $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('no_subpages'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE);
                                $theCode .= $flashMessage->render();
                        }
                        // CSH:
                        $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardsortpages', $GLOBALS['BACK_PATH'], '<br />|');
-                       $out .= $this->pObj->doc->section('', $theCode, 0, 1);
+                       $out .= $this->pObj->doc->section('', $theCode, FALSE, TRUE);
                } else {
-                       $out .= $this->pObj->doc->section('', 'Sorry, this function is not available in the current draft workspace!', 0, 1, 1);
+                       $out .= $this->pObj->doc->section('', 'Sorry, this function is not available in the current draft workspace!', FALSE, TRUE, 1);
                }
                return $out;
        }
@@ -123,9 +110,8 @@ class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFu
         * @param string $title Title of the link
         * @param string $order Field to sort by
         * @return string HTML string
-        * @todo Define visibility
         */
-       public function wiz_linkOrder($title, $order) {
+       protected function wiz_linkOrder($title, $order) {
                return '<a class="t3-link" href="' . htmlspecialchars(
                        BackendUtility::getModuleUrl('web_func',
                                array(
@@ -133,7 +119,7 @@ class SortPagesWizardModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFu
                                        'sortByField' => $order
                                )
                        )
-               ) . '" onclick="return confirm(' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($GLOBALS['LANG']->getLL('wiz_changeOrder_msg1')) . ')">' . htmlspecialchars($title) . '</a>';
+               ) . '" onclick="return confirm(' . GeneralUtility::quoteJSvalue($GLOBALS['LANG']->getLL('wiz_changeOrder_msg1')) . ')">' . htmlspecialchars($title) . '</a>';
        }
 
 }
\ No newline at end of file