Fixed bug #6651: IRRE - Button for creating new records disappeared on nested child...
authorOliver Hader <oliver.hader@typo3.org>
Wed, 26 Dec 2007 16:15:27 +0000 (16:15 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Wed, 26 Dec 2007 16:15:27 +0000 (16:15 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2858 709f56b5-9817-0410-a4d7-c38de5d9e867

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

index d85c790..cc81005 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-12-26  Oliver Hader  <oh@inpublica.de>
+
+       * (minor) Fixed bug #6651: IRRE - Button for creating new records disappeared on nested child records if a parent record reached the maxitems value
+
 2007-12-21  Oliver Hader  <oh@inpublica.de>
 
        * (minor) Fixed bug #6007: IRRE - Child records with image fields are not shown in m:n disposal
index bf869f5..932b449 100755 (executable)
@@ -190,7 +190,10 @@ class t3lib_TCEforms_inline {
 
                        // Tell the browser what we have (using JSON later):
                $top = $this->getStructureLevel(0);
-               $this->inlineData['config'][$nameObject] = array('table' => $foreign_table);
+               $this->inlineData['config'][$nameObject] = array(
+                       'table' => $foreign_table,
+                       'md5' => md5($nameObject),
+               );
                $this->inlineData['config'][$nameObject.'['.$foreign_table.']'] = array(
                        'min' => $minitems,
                        'max' => $maxitems,
@@ -492,7 +495,8 @@ class t3lib_TCEforms_inline {
                $isOnSymmetricSide = t3lib_loadDBGroup::isOnSymmetricSide($parentUid, $config, $rec);
                $enableManualSorting = $tcaTableCtrl['sortby'] || $config['MM'] || (!$isOnSymmetricSide && $config['foreign_sortby']) || ($isOnSymmetricSide && $config['symmetric_sortby']) ? true : false;
 
-               $nameObjectFt = $this->inlineNames['object'].'['.$foreign_table.']';
+               $nameObject = $this->inlineNames['object'];
+               $nameObjectFt = $nameObject.'['.$foreign_table.']';
                $nameObjectFtId = $nameObjectFt.'['.$rec['uid'].']';
 
                $calcPerms = $GLOBALS['BE_USER']->calcPerms(
@@ -523,10 +527,11 @@ class t3lib_TCEforms_inline {
                                        ($isPagesTable && ($calcPerms&8))               // For pages, must have permission to create new pages here.
                                        )       {
                                        $onClick = "return inline.createNewRecord('".$nameObjectFt."','".$rec['uid']."')";
+                                       $class = ' class="inlineNewButton '.$this->inlineData['config'][$nameObject]['md5'].'"';
                                        if ($config['inline']['inlineNewButtonStyle']) {
                                                $style = ' style="'.$config['inline']['inlineNewButtonStyle'].'"';
                                        }
-                                       $cells[]='<a href="#" onclick="'.htmlspecialchars($onClick).'" class="inlineNewButton"'.$style.'>'.
+                                       $cells[]='<a href="#" onclick="'.htmlspecialchars($onClick).'"'.$class.$style.'>'.
                                                        '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/new_'.($isPagesTable?'page':'el').'.gif','width="'.($isPagesTable?13:11).'" height="12"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_list.xml:new'.($isPagesTable?'Page':'Record'),1).'" alt="" />'.
                                                        '</a>';
                                }
@@ -778,17 +783,23 @@ class t3lib_TCEforms_inline {
         * @return      string          The HTML code for the new record link
         */
        function getNewRecordLink($objectPrefix, $conf = array()) {
-               if ($conf['inline']['inlineNewButtonStyle']) $style = ' style="'.$conf['inline']['inlineNewButtonStyle'].'"';
+               $nameObject = $this->inlineNames['object'];
+               $class = ' class="inlineNewButton '.$this->inlineData['config'][$nameObject]['md5'].'"';
+
+               if ($conf['inline']['inlineNewButtonStyle']) {
+                       $style = ' style="'.$conf['inline']['inlineNewButtonStyle'].'"';
+               }
 
                $onClick = "return inline.createNewRecord('$objectPrefix')";
                $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.createnew',1);
 
-               if ($conf['appearance']['newRecordLinkAddTitle'])
+               if ($conf['appearance']['newRecordLinkAddTitle']) {
                        $tableTitle .= ' '.$GLOBALS['LANG']->sL($GLOBALS['TCA'][$conf['foreign_table']]['ctrl']['title'],1);
+               }
 
                $out = '
                                <div class="typo3-newRecordLink">
-                                       <a href="#" onClick="'.$onClick.'" class="inlineNewButton"'.$style.' title="'.$title.$tableTitle.'">'.
+                                       <a href="#" onClick="'.$onClick.'"'.$class.$style.' title="'.$title.$tableTitle.'">'.
                                        '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/new_el.gif','width="11" height="12"').' alt="'.$title.$tableTitle.'" />'.
                                        $title.t3lib_div::fixed_lgd_cs($tableTitle, $this->fObj->titleLen).
                                        '</a>
index cf4f97c..4c6942f 100755 (executable)
@@ -374,13 +374,15 @@ var inline = {
                        if (!records[i].length) continue;
 
                        headerObj = $(objectPrefix+'['+records[i]+']_header');
-                       sortingObj[0] = headerObj.getElementsByClassName('sortingUp');
-                       sortingObj[1] = headerObj.getElementsByClassName('sortingDown');
+                       sortingObj[0] = Element.getElementsByClassName(headerObj, 'sortingUp');
+                       sortingObj[1] = Element.getElementsByClassName(headerObj, 'sortingDown');
 
-                       if (sortingObj[0].length)
-                               sortingObj[0][0].style.visibility = i == 0 ? 'hidden' : 'visible';
-                       if (sortingObj[1].length)
-                               sortingObj[1][0].style.visibility = i == records.length-1 ? 'hidden' : 'visible';
+                       if (sortingObj[0].length) {
+                               sortingObj[0][0].style.visibility = (i == 0 ? 'hidden' : 'visible');
+                       }
+                       if (sortingObj[1].length) {
+                               sortingObj[1][0].style.visibility = (i == records.length-1 ? 'hidden' : 'visible');
+                       }
                }
        },
 
@@ -416,7 +418,9 @@ var inline = {
 
                        // if we reached the maximum off possible records after this action, hide the new buttons
                if (!this.isBelowMax(objectPrefix)) {
-                       this.hideElementsWithClassName('inlineNewButton',  this.parseFormElementName('full', objectPrefix, 0 , 1));
+                       var objectParent = this.parseFormElementName('full', objectPrefix, 0 , 1);
+                       var md5 = this.getObjectMD5(objectParent);
+                       this.hideElementsWithClassName('.inlineNewButton'+(md5 ? '.'+md5 : ''), objectParent);
                }
 
                if (TBE_EDITOR) TBE_EDITOR.fieldChanged_fName(objectName, formObj);
@@ -530,18 +534,9 @@ var inline = {
                        // revert the unique settings if available
                this.revertUnique(objectPrefix, elName, recordUid);
 
-                       // if the record is new and was never saved before, just remove it from DOM
-               if (this.isNewRecord(objectId)) {
-                       new Effect.Fade(objectId+'_div', { afterFinish: function() { Element.remove(objectId+'_div'); } });
-                       // if the record already exists in storage, mark it to be deleted on clicking the save button
-               } else {
-                       document.getElementsByName('cmd'+shortName+'[delete]')[0].disabled = false;
-                       new Effect.Fade(objectId+'_div');
-               }
-
                        // Remove from TBE_EDITOR (required fields, required range, etc.):
                if (TBE_EDITOR && TBE_EDITOR.removeElement) {
-                       inlineRecords = document.getElementsByClassName('inlineRecord', objectId+'_div');
+                       inlineRecords = Element.getElementsByClassName(objectId+'_div', 'inlineRecord');
                                // Remove nested child records from TBE_EDITOR required/range checks:
                        for (i=inlineRecords.length-1; i>=0; i--) {
                                if (inlineRecords[i].value.length) {
@@ -556,6 +551,15 @@ var inline = {
                        TBE_EDITOR.removeElement(this.prependFormFieldNames+shortName);
                }
 
+                       // If the record is new and was never saved before, just remove it from DOM:
+               if (this.isNewRecord(objectId)) {
+                       new Effect.Fade(objectId+'_div', { afterFinish: function() { Element.remove(objectId+'_div'); } });
+                       // If the record already exists in storage, mark it to be deleted on clicking the save button:
+               } else {
+                       document.getElementsByName('cmd'+shortName+'[delete]')[0].disabled = false;
+                       new Effect.Fade(objectId+'_div');
+               }
+
                var recordCount = this.memorizeRemoveRecord(
                        this.prependFormFieldNames+this.parseFormElementName('parts', objectId, 3, 2),
                        recordUid
@@ -567,9 +571,11 @@ var inline = {
                this.redrawSortingButtons(objectPrefix);
 
                        // if the NEW-button was hidden and now we can add again new children, show the button
-               if (!beforeDeleteIsBelowMax && this.isBelowMax(objectPrefix))
-                       this.showElementsWithClassName('inlineNewButton', this.parseFormElementName('full', objectPrefix, 0 , 1));
-
+               if (!beforeDeleteIsBelowMax && this.isBelowMax(objectPrefix)) {
+                       var objectParent = this.parseFormElementName('full', objectPrefix, 0 , 1);
+                       var md5 = this.getObjectMD5(objectParent);
+                       this.showElementsWithClassName('.inlineNewButton'+(md5 ? '.'+md5 : ''), objectParent);
+               }
                return false;
        },
 
@@ -692,21 +698,20 @@ var inline = {
                selectObj.add(readdOption, document.all ? index : selectObj.options[index]);
        },
 
-       hideElementsWithClassName: function(className, parentElement) {
-               this.setVisibilityOfElementsWithClassName('hide', className, parentElement);
+       hideElementsWithClassName: function(selector, parentElement) {
+               this.setVisibilityOfElementsWithClassName('hide', selector, parentElement);
        },
 
-       showElementsWithClassName: function(className, parentElement) {
-               this.setVisibilityOfElementsWithClassName('show', className, parentElement);
+       showElementsWithClassName: function(selector, parentElement) {
+               this.setVisibilityOfElementsWithClassName('show', selector, parentElement);
        },
 
-       setVisibilityOfElementsWithClassName: function(action, className, parentElement) {
-               var domObjects = document.getElementsByClassName(className, parentElement);
-               for (var i=0; i<domObjects.length; i++) {
-                       if (action == 'hide')
-                               new Effect.Fade(domObjects[i]);
-                       else if (action = 'show')
-                               new Effect.Appear(domObjects[i]);
+       setVisibilityOfElementsWithClassName: function(action, selector, parentElement) {
+               var domObjects = Selector.findChildElements($(parentElement), [selector]);
+               if (action == 'hide') { 
+                       $A(domObjects).each(function(domObject) { new Effect.Fade(domObject); });
+               } else if (action == 'show') {
+                       $A(domObjects).each(function(domObject) { new Effect.Appear(domObject); });
                }
        },
 
@@ -741,6 +746,14 @@ var inline = {
                        number = RTEarea.length-1;
                }
                return number;
+       },
+
+       getObjectMD5: function(objectPrefix) {
+               var md5 = false;
+               if (this.data.config && this.data.config[objectPrefix] && this.data.config[objectPrefix].md5) {
+                       md5 = this.data.config[objectPrefix].md5;
+               }
+               return md5
        }
 }