Added feature #7122: IRRE - Implement TYPO3AJAX handler for Inline Relational Record...
authorOliver Hader <oliver.hader@typo3.org>
Mon, 14 Jan 2008 23:18:36 +0000 (23:18 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 14 Jan 2008 23:18:36 +0000 (23:18 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2886 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_tceforms.php
t3lib/class.t3lib_tceforms_inline.php
t3lib/config_default.php
t3lib/jsfunc.inline.js
typo3/alt_doc_ajax.php

index 769e5f3..c5de4c9 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-01-15  Oliver Hader  <oh@inpublica.de>
+
+       * (feature) Added feature #7122: IRRE - Implement TYPO3AJAX handler for Inline Relational Record Editing
+
 2008-01-14  Stanislas Rolland  <stanislas.rolland@fructifor.ca>
 
        * Fixed bug #7138: RTE is not rendered in Tabs
index 32494b5..4cdb898 100755 (executable)
@@ -359,7 +359,10 @@ class t3lib_TCEforms       {
                        'inline' => array('appearance', 'foreign_label', 'foreign_selector', 'foreign_unique', 'maxitems', 'minitems', 'size', 'autoSizeMax', 'symmetric_label'),
                );
 
-               $this->inline = t3lib_div::makeInstance('t3lib_TCEforms_inline');
+                       // Create instance of t3lib_TCEforms_inline only if this a non-IRRE-AJAX call: 
+               if (!isset($GLOBALS['ajaxID']) || strpos($GLOBALS['ajaxID'], 't3lib_TCEforms_inline::')!==0) {
+                       $this->inline = t3lib_div::makeInstance('t3lib_TCEforms_inline');
+               }
 
                        // Prepare user defined objects (if any) for hooks which extend this function:
                $this->hookObjectsMainFields = array();
index 75574dd..ff9c6e3 100755 (executable)
@@ -832,11 +832,98 @@ class t3lib_TCEforms_inline {
 
 
        /**
+        * General processor for AJAX requests concerning IRRE. 
+        * (called by typo3/ajax.php)
+        * 
+        * @param       array           $params: additional parameters (not used here)
+        * @param       TYPO3AJAX       &$ajaxObj: the TYPO3AJAX object of this request
+        * @return      void
+        */
+       public function processAjaxRequest($params, &$ajaxObj) {
+               $ajaxArguments = t3lib_div::_GP('ajax');
+               $ajaxIdParts = explode('::', $GLOBALS['ajaxID'], 2);
+
+               if (isset($ajaxArguments) && is_array($ajaxArguments) && count($ajaxArguments)) {
+                       $ajaxMethod = $ajaxIdParts[1];
+                       switch ($ajaxMethod) {
+                               case 'createNewRecord':
+                                       $this->processAjaxRequestConstruct($ajaxArguments);
+                                       $ajaxObj->setContentFormat('jsonbody');
+                                       $ajaxObj->setContent(
+                                               call_user_func_array(array(&$this, $ajaxMethod), $ajaxArguments)
+                                       );
+                                       break;
+                               case 'setExpandedCollapsedState':
+                                       $ajaxObj->setContentFormat('jsonbody');
+                                       call_user_func_array(array(&$this, $ajaxMethod), $ajaxArguments);
+                                       break;
+                       }
+               }
+       }
+
+
+       /**
+        * Construct runtime environment for Inline Relational Record Editing.
+        * - creates an anoymous SC_alt_doc in $GLOBALS['SOBE']
+        * - creates a t3lib_TCEforms in $GLOBALS['SOBE']->tceforms
+        * - sets ourself as reference to $GLOBALS['SOBE']->tceforms->inline
+        * - sets $GLOBALS['SOBE']->tceforms->RTEcounter to the current situation on client-side
+        * 
+        * @param       array           &$ajaxArguments: The arguments to be processed by the AJAX request
+        * @return      void
+        */
+       protected function processAjaxRequestConstruct(&$ajaxArguments) {
+               require_once(PATH_typo3.'template.php');
+               require_once(PATH_t3lib.'class.t3lib_tceforms.php');
+               require_once(PATH_t3lib.'class.t3lib_clipboard.php');
+
+               global $SOBE, $BE_USER;
+
+                       // Create a new anonymous object:
+               $SOBE = new stdClass();
+               $SOBE->MOD_MENU = array(
+                       'showPalettes' => '',
+                       'showDescriptions' => '',
+                       'disableRTE' => ''
+               );
+                       // Setting virtual document name
+               $SOBE->MCONF['name']='xMOD_alt_doc.php';
+                       // CLEANSE SETTINGS
+               $SOBE->MOD_SETTINGS = t3lib_BEfunc::getModuleData(
+                       $SOBE->MOD_MENU,
+                       t3lib_div::_GP('SET'),
+                       $SOBE->MCONF['name']
+               );
+                       // Create an instance of the document template object
+               $SOBE->doc = t3lib_div::makeInstance('template');
+               $SOBE->doc->backPath = $GLOBALS['BACK_PATH'];
+               $SOBE->doc->docType = 'xhtml_trans';
+                       // Initialize TCEforms (rendering the forms)
+               $SOBE->tceforms = t3lib_div::makeInstance('t3lib_TCEforms');
+               $SOBE->tceforms->inline =& $this;
+               $SOBE->tceforms->RTEcounter = intval(array_shift($ajaxArguments));
+               $SOBE->tceforms->initDefaultBEMode();
+               $SOBE->tceforms->palettesCollapsed = !$SOBE->MOD_SETTINGS['showPalettes'];
+               $SOBE->tceforms->disableRTE = $SOBE->MOD_SETTINGS['disableRTE'];
+               $SOBE->tceforms->enableClickMenu = TRUE;
+               $SOBE->tceforms->enableTabMenu = TRUE;
+                       // Clipboard is initialized:
+               $SOBE->tceforms->clipObj = t3lib_div::makeInstance('t3lib_clipboard');          // Start clipboard
+               $SOBE->tceforms->clipObj->initializeClipboard();        // Initialize - reads the clipboard content from the user session
+                       // Setting external variables:
+               if ($BE_USER->uc['edit_showFieldHelp']!='text' && $SOBE->MOD_SETTINGS['showDescriptions']) {
+                       $SOBE->tceforms->edit_showFieldHelp = 'text';
+               }
+       }
+
+
+       /**
         * Initialize environment for AJAX calls
         *
         * @param       string          $method: Name of the method to be called
         * @param       array           $arguments: Arguments to be delivered to the method
         * @return      void
+        * @deprecated  since TYPO3 4.2.0-alpha3
         */
        function initForAJAX($method, &$arguments) {
                        // Set t3lib_TCEforms::$RTEcounter to the given value:
@@ -852,7 +939,7 @@ class t3lib_TCEforms_inline {
         *
         * @param       string          $domObjectId: The calling object in hierarchy, that requested a new record.
         * @param       string          $foreignUid: If set, the new record should be inserted after that one.
-        * @return      string          A JSON string
+        * @return      array           An array to be used for JSON
         */
        function createNewRecord($domObjectId, $foreignUid = 0) {
                $this->isAjaxCall = true;
@@ -900,7 +987,7 @@ class t3lib_TCEforms_inline {
                                        "alert('Access denied');",
                                )
                        );
-                       return t3lib_div::array2json($jsonArray);
+                       return $jsonArray;
                }
 
                        // Encode TCEforms AJAX response with utf-8:
@@ -946,8 +1033,8 @@ class t3lib_TCEforms_inline {
                        // Remove the current level also from the dynNestedStack of TCEforms:
                $this->fObj->popFromDynNestedStack();
 
-                       // return the JSON string
-               return t3lib_div::array2json($jsonArray);
+                       // Return the JSON array:
+               return $jsonArray;
        }
 
 
index 7e5aaee..1158e79 100755 (executable)
@@ -174,6 +174,8 @@ $TYPO3_CONF_VARS = Array(
                'AJAX' => array(                                // array of key-value pairs for a unified use of AJAX calls in the TYPO3 backend. Keys are the unique ajaxIDs where the value will be resolved to call a method in an object. See ajax.php and the classes/class.typo3ajax.php for more information.
                        'SC_alt_db_navframe::expandCollapse'   => 'typo3/alt_db_navframe.php:SC_alt_db_navframe->ajaxExpandCollapse',
                        'SC_alt_file_navframe::expandCollapse' => 'typo3/alt_file_navframe.php:SC_alt_file_navframe->ajaxExpandCollapse',
+                       't3lib_TCEforms_inline::createNewRecord'                => 't3lib/class.t3lib_tceforms_inline.php:t3lib_TCEforms_inline->processAjaxRequest',
+                       't3lib_TCEforms_inline::setExpandedCollapsedState'      => 't3lib/class.t3lib_tceforms_inline.php:t3lib_TCEforms_inline->processAjaxRequest',
                ),
        ),
        'FE' => Array(                  // Configuration for the TypoScript frontend (FE). Nothing here relates to the administration backend!
index 31637b1..252ee61 100755 (executable)
@@ -121,10 +121,10 @@ var inline = {
        makeAjaxCall: function(method, params, lock) {
                var max, url='', urlParams='', options={};
                if (method && params && params.length && this.lockAjaxMethod(method, lock)) {
-                       url = 'alt_doc_ajax.php';
-                       urlParams += '&ajax[0]='+method;
+                       url = 'ajax.php';
+                       urlParams = '&ajaxID=t3lib_TCEforms_inline::'+method;
                        for (var i=0, max=params.length; i<max; i++) {
-                               urlParams += '&ajax['+(i+1)+']='+params[i];
+                               urlParams += '&ajax['+i+']='+params[i];
                        }
                        options = {
                                method:         'post',
index e432031..a62e693 100755 (executable)
@@ -63,7 +63,12 @@ require_once (PATH_t3lib.'class.t3lib_transferdata.php');
 t3lib_BEfunc::lockRecords();
 
 
-
+/**
+ * Deprecated AJAX handler for Inline Relational Record Editing (IRRE).
+ * The TYPO3AJAX interface is used now instead. 
+ *
+ * @deprecated since TYPO3 4.2.0-alpha3
+ */
 class SC_alt_doc_ajax {
        var $content;                           // Content accumulation
        var $retUrl;                            // Return URL script, processed. This contains the script (if any) that we should RETURN TO from the alt_doc.php script IF we press the close button. Thus this variable is normally passed along from the calling script so we can properly return if needed.