Fixed bug #5556: IRRE - RTE in child elements overwrites field in parent element
authorOliver Hader <oliver.hader@typo3.org>
Mon, 16 Jul 2007 13:09:38 +0000 (13:09 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 16 Jul 2007 13:09:38 +0000 (13:09 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/branches/TYPO3_4-1@2422 709f56b5-9817-0410-a4d7-c38de5d9e867

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

index 2104602..1599056 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2007-07-16  Oliver Hader  <oh@inpublica.de>
+
+       * Fixed bug #5556: IRRE - RTE in child elements overwrites field in parent element
 
 2007-07-16  Martin Kutschker  <martin.t.kutschker@blackbox.net>
 
index 5c0984d..57a27d7 100755 (executable)
@@ -784,6 +784,21 @@ class t3lib_TCEforms_inline {
 
 
        /**
+        * 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
+        */
+       function initForAJAX($method, &$arguments) {
+                       // Set t3lib_TCEforms::$RTEcounter to the given value:
+               if ($method == 'createNewRecord') {
+                       $this->fObj->RTEcounter = intval(array_shift($arguments));
+               }
+       }
+
+
+       /**
         * Handle AJAX calls to show a new inline-record of the given table.
         * Normally this method is never called from inside TYPO3. Always from outside by AJAX.
         *
index 8dc37af..ada489a 100755 (executable)
@@ -32,6 +32,7 @@
 var inline = {
        prependFormFieldNames: 'data',
        noTitleString: '[No title]',
+       lockedAjaxMethod: {},
        data: {},
 
        addToDataArray: function(object) { for (var i in object) { this.data[i] = $H(this.data[i]).merge(object[i]); } },
@@ -97,38 +98,61 @@ var inline = {
        },
 
        createNewRecord: function(objectId,prevRecordUid) {
-               if (this.isBelowMax(objectId)) this.makeAjaxCall('createNewRecord', objectId+(prevRecordUid ? '['+prevRecordUid+']' : ''));
-               else alert('There are no more relations possible at this moment!');
+               if (this.isBelowMax(objectId)) {
+                       if (prevRecordUid) {
+                               objectId += '['+prevRecordUid+']';
+                       }
+                       this.makeAjaxCall('createNewRecord', [this.getNumberOfRTE(), objectId], true);
+               } else {
+                       alert('There are no more relations possible at this moment!');
+               }
                return false;
        },
 
        setExpandedCollapsedState: function(objectId, expand, collapse) {
-               this.makeAjaxCall('setExpandedCollapsedState', objectId, expand, collapse);
+               this.makeAjaxCall('setExpandedCollapsedState', [objectId, expand, collapse]);
        },
 
-       makeAjaxCall: function() {
-               if (arguments.length > 1) {
-                       var params = '';
-                       for (var i=0; i<arguments.length; i++) params += '&ajax['+i+']='+arguments[i];
-
-                       var url = 'alt_doc_ajax.php';
-                       var options = {
+       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;
+                       for (var i=0, max=params.length; i<max; i++) {
+                               urlParams += '&ajax['+(i+1)+']='+params[i];
+                       }
+                       options = {
                                method:         'post',
-                               parameters:     params,
-                               onSuccess:      inline.processAjaxResponse,
-                               onFailure:      inline.showAjaxFailure
+                               parameters:     urlParams,
+                               onSuccess:      function(xhr) { inline.processAjaxResponse(method, xhr); },
+                               onFailure:      function(xhr) { inline.showAjaxFailure(method, xhr); }
                        };
 
                        new Ajax.Request(url, options);
                }
        },
 
-       processAjaxResponse: function(xhr) {
+       lockAjaxMethod: function(method, lock) {
+               if (!lock || !inline.lockedAjaxMethod[method]) {
+                       inline.lockedAjaxMethod[method] = true;
+                       return true;
+               } else {
+                       return false;
+               }
+       },
+
+       unlockAjaxMethod: function(method) {
+               inline.lockedAjaxMethod[method] = false;
+       },
+
+       processAjaxResponse: function(method, xhr) {
+               inline.unlockAjaxMethod(method);
                var json = eval('('+xhr.responseText+')');
                for (var i in json.scriptCall) eval(json.scriptCall[i]);
        },
 
-       showAjaxFailure: function(xhr) {
+       showAjaxFailure: function(method, xhr) {
+               inline.unlockAjaxMethod(method);
                alert('Error: '+xhr.status+"\n"+xhr.statusText);
        },
 
@@ -140,7 +164,7 @@ var inline = {
                        if (!this.data.unique || !this.data.unique[objectId]) {
                                selector.options[selector.selectedIndex].selected = false;
                        }
-                       this.makeAjaxCall('createNewRecord', objectId, selectedValue);
+                       this.makeAjaxCall('createNewRecord', [this.getNumberOfRTE(), objectId, selectedValue], true);
                }
                return false;
        },
@@ -149,7 +173,7 @@ var inline = {
        importElement: function(objectId, table, uid, type) {
                window.setTimeout(
                        function() {
-                               inline.makeAjaxCall('createNewRecord', objectId, uid);
+                               inline.makeAjaxCall('createNewRecord', [this.getNumberOfRTE(), objectId, uid], true);
                        },
                        10
                );
@@ -173,7 +197,7 @@ var inline = {
                                // for select: only the uid is stored
                        if (unique['type'] == 'select') {
                                if (values.indexOf(uid) != -1) return true;
-                               
+
                                // for group/db: table and uid is stored in a assoc array
                        } else if (unique.type == 'groupdb') {
                                for (var i=values.length-1; i>=0; i--) {
@@ -293,7 +317,7 @@ var inline = {
                        var checked = new Array();
                        var order = Sortable.sequence(element);
                        var records = formObj[0].value.split(',');
-                       
+
                                // check if ordered uid is really part of the records
                                // virtually deleted items might still be there but ordering shouldn't saved at all on them
                        for (var i=0; i<order.length; i++) {
@@ -445,7 +469,7 @@ var inline = {
                if (unique.type == 'select') {
                        if (fieldObj && fieldObj.length) {
                                delete(this.data.unique[objectPrefix].used[recordUid])
-                               
+
                                if (unique.selector == 'select') {
                                        if (!isNaN(fieldObj[0].value)) {
                                                var selector = $(objectPrefix+'_selector');
@@ -703,7 +727,15 @@ var inline = {
                } else {
                        return nested;
                }
-       }
+       },
+
+       getNumberOfRTE: function() {
+               var number = 0;
+               if (typeof RTEarea != 'undefined' && RTEarea.length > 0) {
+                       number = RTEarea.length-1;
+               }
+               return number;
+       }
 }
 
 Object.extend(Array.prototype, {
index 9e10972..f67020f 100755 (executable)
@@ -131,8 +131,12 @@ class SC_alt_doc_ajax {
                        $method = array_shift($this->ajax);
 
                                // Security check
-                       if(!in_array($method, array('createNewRecord', 'setExpandedCollapsedState'))) return false;
+                       if (!in_array($method, array('createNewRecord', 'setExpandedCollapsedState'))) {
+                               return false;
+                       }
 
+                               // Perform the requested action:
+                       $this->tceforms->inline->initForAJAX($method, $this->ajax);
                        $this->content = call_user_func_array(
                                array(&$this->tceforms->inline, $method),
                                $this->ajax