Fixed bug #14618: Bug: Add debug feature to Ext Direct (Thanks to Fabien Udriot)
authorSteffen Kamper <info@sk-typo3.de>
Wed, 9 Jun 2010 14:10:22 +0000 (14:10 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Wed, 9 Jun 2010 14:10:22 +0000 (14:10 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@7847 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/extjs/class.t3lib_extjs_extdirectapi.php
typo3/backend.php
typo3/sysext/lang/locallang_core.xml

index 958d5a6..a86b201 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2010-06-08  Steffen Kamper  <info@sk-typo3.de>
 
+       * Fixed bug #14618: Bug: Add debug feature to Ext Direct (Thanks to Fabien Udriot)
        * Follow-up to bug #8305: SQL debug output is not shown in the Backend
        * Added test case t3lib_utility_clientTest.php
        * Fixed bug #14458: getBrowserInfo fails with IE UA Strings
index c94d789..74bc053 100644 (file)
@@ -64,24 +64,34 @@ class t3lib_extjs_ExtDirectApi {
        public function getAPI($ajaxParams, TYPO3AJAX $ajaxObj) {
                $filterNamespace = t3lib_div::_GET('namespace');
 
-               // look up into the cache
+                       // Check GET-parameter no_cache and extCache setting
+               $extCache = isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache']) && (
+                       $GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache'] === 0 ||
+                       $GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache'] === '0'
+               );
+               $noCache = t3lib_div::_GET('no_cache') ? TRUE : $extCache;
+
+                       // look up into the cache
                $cacheIdentifier = 'ExtDirectApi';
                $cacheHash = md5($cacheIdentifier . $filterNamespace . serialize($this->settings));
-               $cacheContent = t3lib_pageSelect::getHash($cacheHash);
+                       // with no_cache always generate the javascript content
+               $cacheContent = $noCache ? '' : t3lib_pageSelect::getHash($cacheHash);
 
-               // generate the javascript content if it wasn't found inside the cache and cache it!
+                       // generate the javascript content if it wasn't found inside the cache and cache it!
                if (!$cacheContent) {
                        $javascriptNamespaces = $this->generateAPI($filterNamespace);
-                       t3lib_pageSelect::storeHash(
-                               $cacheHash,
-                               serialize($javascriptNamespaces),
-                               $cacheIdentifier
-                       );
+                       if (!empty($javascriptNamespaces)) {
+                               t3lib_pageSelect::storeHash(
+                                       $cacheHash,
+                                       serialize($javascriptNamespaces),
+                                       $cacheIdentifier
+                               );
+                       }
                } else {
                        $javascriptNamespaces = unserialize($cacheContent);
                }
 
-               // return the generated javascript API configuration
+                       // return the generated javascript API configuration
                if (count($javascriptNamespaces)) {
                        $setup = '
                                if (typeof Ext.app.ExtDirectAPI !== "object") {
@@ -103,6 +113,36 @@ class t3lib_extjs_ExtDirectApi {
                        $ajaxObj->setJavascriptCallbackWrap(
                                $setup . 'Ext.app.ExtDirectAPI = Object.extend(Ext.app.ExtDirectAPI, |);'
                        );
+               } else {
+                       if ($filterNamespace) {
+                                       // namespace error
+                               $errorMessage = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:ExtDirect.namespaceError'),
+                                                               __CLASS__, $filterNamespace
+                               );
+                       }
+                       else {
+                                       // no namespace given
+                               $errorMessage = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:ExtDirect.noNamespace'),
+                                                               __CLASS__
+                               );
+                       }
+                               // make js multiline message
+                       $msg = t3lib_div::trimExplode(LF, str_replace('"', '\"', $errorMessage), TRUE);
+                       $errorMessage = '';
+                       foreach ($msg as $line) {
+                               $errorMessage .= '"' . $line . '" + ' . LF;
+                       }
+                       $errorMessage = substr(trim($errorMessage), 0, -1);
+                               //generate the javascript
+                       $ajaxObj->setContentFormat('javascript');
+                       $ajaxObj->setJavascriptCallbackWrap('
+                               errorMessage = ' . $errorMessage . ';
+                               if (typeof console === "object") {
+                                       console.log(errorMessage);
+                               } else {
+                                       alert(errorMessage);
+                               }
+                       ');
                }
        }
 
@@ -142,7 +182,7 @@ class t3lib_extjs_ExtDirectApi {
                                        $numberOfParameters = $reflectionMethod->getNumberOfParameters();
                                        $docHeader = $reflectionMethod->getDocComment();
                                        $formHandler = (strpos($docHeader, '@formHandler') !== FALSE);
-                                       
+
                                        $javascriptNamespaces[$javascriptNamespace]['actions'][$javascriptObjectName][] = array(
                                                'name' => $methodName,
                                                'len' => $numberOfParameters,
index c6bbcb0..c68ce34 100644 (file)
@@ -247,8 +247,20 @@ class TYPO3backend {
                foreach ($this->jsFiles as $jsFile) {
                        $this->pageRenderer->addJsFile($jsFile);
                }
-                       // we mustn't compress this file
-               $this->pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Backend', NULL, FALSE);
+
+                       // Those lines can be removed once we have at least one official ExtDirect router within the backend.
+               $hasExtDirectRouter = FALSE;
+               if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ExtDirect'] as $key => $value) {
+                               if (strpos($key, 'TYPO3.Backend') !== FALSE) {
+                                       $hasExtDirectRouter = TRUE;
+                                       break;
+                               }
+                       }
+               }
+               if ($hasExtDirectRouter) {
+                       $this->pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Backend', NULL, FALSE);
+               }
 
                $this->generateJavascript();
                $this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js);
index 6f04444..eaa814c 100755 (executable)
@@ -272,6 +272,13 @@ Would you like to save now in order to refresh the display?</label>
                        <label index="donateWindow.button_donate">Donate now</label>
                        <label index="donateWindow.button_disable">Never show again</label>
                        <label index="donateWindow.button_postpone">Remind me later</label>
+                       <label index="ExtDirect.namespaceError">Ext Direct error in &quot;%s&quot; with namespace: &quot;%s&quot;\n
+Try to clear the TYPO3 cache and / or use paramater no_cache=1 as parameter in URL typo3/ajax.php\n\n
+Check also the following points:\n
+- configuration in ext_localconf.php: registration key should be like &quot;TYPO3.MyExtension.Sample&quot;\n
+- URL typo3/ajax.php: namespace parameter should be like: &quot;TYPO3.MyExtension&quot;\n
+- javascript: method\'s name should be like: &quot;TYPO3.MyExtension.Sample.myMethod&quot;\n</label>
+                       <label index="ExtDirect.noNamespace">Ext Direct error in &quot;%s&quot;: no namespace has been found.</label>
                </languageKey>
        </data>
 </T3locallang>