[TASK] Use ajax.php for clickmenu 63/33763/3
authorBenjamin Mack <benni@typo3.org>
Mon, 3 Nov 2014 20:37:58 +0000 (21:37 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 3 Nov 2014 21:36:49 +0000 (22:36 +0100)
The clickmenu still used its own alt_clickmenu.php
entry point until now which is not needed anymore
with ajax.php.

Further steps (out of scope for this patch)
are: use JSON instead of proprietary XML
and jQuery instead of prototype.

Releases: master
Resolves: #62666
Change-Id: Iae4a9623c59a8c985d15dbc9be0c0544ce6abf8e
Reviewed-on: http://review.typo3.org/33763
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/backend/Classes/Controller/ClickMenuController.php
typo3/sysext/backend/Classes/Template/DocumentTemplate.php
typo3/sysext/backend/Resources/Public/JavaScript/clickmenu.js
typo3/sysext/core/Configuration/DefaultConfiguration.php

index 750c8cf..e2ba443 100644 (file)
@@ -87,10 +87,9 @@ class ClickMenuController {
                $this->extClassArray = $GLOBALS['TBE_MODULES_EXT']['xMOD_alt_clickmenu']['extendCMclasses'];
 
                // Initialize template object
-               if (!$this->ajax) {
-                       $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
-                       $this->doc->backPath = $GLOBALS['BACK_PATH'];
-               }
+               $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
+               $this->doc->backPath = $GLOBALS['BACK_PATH'];
+
                // Setting mode for display and background image in the top frame
 
                // Setting clickmenu timeout
@@ -149,7 +148,6 @@ class ClickMenuController {
         * @return void
         */
        public function main() {
-               $this->ajax = GeneralUtility::_GP('ajax') ? TRUE : FALSE;
                // Initialize Clipboard object:
                $clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
                $clipObj->initializeClipboard();
@@ -167,10 +165,6 @@ class ClickMenuController {
                $clickMenu->clipObj = $clipObj;
                $clickMenu->extClassArray = $this->extClassArray;
                $clickMenu->backPath = $this->backPath;
-               // Start page
-               if (!$this->ajax) {
-                       $this->content .= $this->doc->startPage('Context Sensitive Menu');
-               }
                // Set content of the clickmenu with the incoming var, "item"
                $this->content .= $clickMenu->init();
        }
@@ -181,14 +175,43 @@ class ClickMenuController {
         * @return void
         */
        public function printContent() {
-               if (!$this->ajax) {
-                       $this->content .= $this->doc->endPage();
-                       $this->content = $this->doc->insertStylesAndJS($this->content);
-                       echo $this->content;
-               } else {
-                       header('Content-Type: text/xml');
-                       echo '<?xml version="1.0"?>' . LF . '<t3ajax>' . $this->content . '</t3ajax>';
-               }
+               header('Content-Type: text/xml');
+               echo '<?xml version="1.0"?>' . LF . '<t3ajax>' . $this->content . '</t3ajax>';
+       }
+
+       /**
+        * this is an intermediate clickmenu handler
+        *
+        * @param array $parameters
+        * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler
+        */
+       public function printContentForAjaxRequest($parameters, \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxRequestHandler) {
+
+               $this->init();
+               $clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
+               $clipObj->initializeClipboard();
+               // This locks the clipboard to the Normal for this request.
+               $clipObj->lockToNormal();
+               // Update clipboard if some actions are sent.
+               $CB = GeneralUtility::_GET('CB');
+               $clipObj->setCmd($CB);
+               $clipObj->cleanCurrent();
+               // Saves
+               $clipObj->endClipboard();
+               // Create clickmenu object
+               $clickMenu = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\ClickMenu\\ClickMenu');
+               // Set internal vars in clickmenu object:
+               $clickMenu->clipObj = $clipObj;
+               $clickMenu->extClassArray = $this->extClassArray;
+               $clickMenu->backPath = $this->backPath;
+
+               // Set content of the clickmenu with the incoming var, "item"
+               $this->content = $clickMenu->init();
+
+               // send the data
+               $content = '<?xml version="1.0"?><t3ajax>' . $this->content . '</t3ajax>';
+               $ajaxRequestHandler->addContent('ClickMenu', $content);
+               $ajaxRequestHandler->setContentFormat('xml');
        }
 
 }
index 40b70e3..2dcc4dd 100644 (file)
@@ -1445,9 +1445,7 @@ function jumpToUrl(URL) {
        public function getContextMenuCode() {
                $this->pageRenderer->loadPrototype();
                $this->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/clickmenu.js');
-               $this->JScodeArray['clickmenu'] = '
-                       Clickmenu.clickURL = "' . $this->backPath . 'alt_clickmenu.php";
-                       Clickmenu.ajax     = true;';
+               $this->pageRenderer->addInlineSetting('ClickMenu', 'ajaxURL', BackendUtility::getAjaxUrl('ContextMenu::load', array(), $this->backPath));
        }
 
        /**
index f374095..f189f52 100644 (file)
@@ -21,8 +21,7 @@
  * AJAX result in a layer next to the mouse cursor
  */
 var Clickmenu = {
-       clickURL: 'alt_clickmenu.php',
-       ajax: true, // \TYPO3\CMS\Backend\Template\DocumentTemplate::isCMLayers
+       clickURL: TYPO3.settings.ClickMenu.ajaxURL,
        mousePos: { X: null, Y: null },
        delayClickMenuHide: false,
 
@@ -55,31 +54,29 @@ var Clickmenu = {
         * @return      nothing
         */
        callURL: function(params) {
-               if (this.ajax && Ajax.getTransport()) { // run with AJAX
-                       params += '&ajax=1';
-                       var call = new Ajax.Request(this.clickURL, {
-                               method: 'get',
-                               parameters: params,
-                               onComplete: function(xhr) {
-                                       var response = xhr.responseXML;
-
-                                       if (!response.getElementsByTagName('data')[0]) {
-                                               var res = params.match(/&reloadListFrame=(0|1|2)(&|$)/);
-                                               var reloadListFrame = parseInt(res[1], 0);
-                                               if (reloadListFrame) {
-                                                       var doc = reloadListFrame != 2 ? top.content.list_frame : top.content;
-                                                       doc.location.reload(true);
-                                               }
-                                               return;
+               params += '&ajax=1';
+               var call = new Ajax.Request(this.clickURL, {
+                       method: 'get',
+                       parameters: params,
+                       onComplete: function(xhr) {
+                               var response = xhr.responseXML;
+
+                               if (!response.getElementsByTagName('data')[0]) {
+                                       var res = params.match(/&reloadListFrame=(0|1|2)(&|$)/);
+                                       var reloadListFrame = parseInt(res[1], 0);
+                                       if (reloadListFrame) {
+                                               var doc = reloadListFrame != 2 ? top.content.list_frame : top.content;
+                                               doc.location.reload(true);
                                        }
-                                       var menu  = response.getElementsByTagName('data')[0].getElementsByTagName('clickmenu')[0];
-                                       var data  = menu.getElementsByTagName('htmltable')[0].firstChild.data;
-                                       var level = menu.getElementsByTagName('cmlevel')[0].firstChild.data;
-                                       this.populateData(data, level);
+                                       return;
+                               }
+                               var menu  = response.getElementsByTagName('data')[0].getElementsByTagName('clickmenu')[0];
+                               var data  = menu.getElementsByTagName('htmltable')[0].firstChild.data;
+                               var level = menu.getElementsByTagName('cmlevel')[0].firstChild.data;
+                               this.populateData(data, level);
 
-                               }.bind(this)
-                       });
-               }
+                       }.bind(this)
+               });
        },
 
 
@@ -236,9 +233,6 @@ function showClickmenu_raw(url) {
                Clickmenu.callURL(url);
        }
 }
-function showClickmenu_noajax(url) {
-       Clickmenu.ajax = false; showClickmenu_raw(url);
-}
 function setLayerObj(tableData, cmLevel) {
        Clickmenu.populateData(tableData, cmLevel);
 }
index 2e76f91..540cb4b 100644 (file)
@@ -698,6 +698,10 @@ return array(
                                'callbackMethod' => 'TYPO3\\CMS\\Backend\\Template\\DocumentTemplate->renderFlashMessages',
                                'csrfTokenCheck' => TRUE
                        ),
+                       'ContextMenu::load' => array(
+                               'callbackMethod' => 'TYPO3\\CMS\\Backend\\Controller\\ClickMenuController->printContentForAjaxRequest',
+                               'csrfTokenCheck' => TRUE
+                       ),
                ),
                'HTTP' => array(
                        'Response' => array(