[BUGFIX] Properly nest added FlexFormSectionContainer 89/42889/3
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 27 Aug 2015 13:10:28 +0000 (15:10 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 28 Aug 2015 18:06:12 +0000 (20:06 +0200)
Attach new created FlexFormSectionContainer to the right element.
Additionally, event stacking has been resolved.

Resolves: #69361
Releases: master
Change-Id: Iac09051b4dca2cf4393b18892359e14c43dfe8a3
Reviewed-on: http://review.typo3.org/42889
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/backend/Classes/Form/Container/FlexFormContainerContainer.php
typo3/sysext/backend/Classes/Form/Container/FlexFormSectionContainer.php
typo3/sysext/backend/Resources/Public/JavaScript/FormEngineFlexForm.js

index 379ffd9..e3bcb65 100644 (file)
@@ -85,7 +85,7 @@ class FlexFormContainerContainer extends AbstractContainer {
                                'actions-edit-delete',
                                array(
                                        'title' => 'Delete', // @todo: hardcoded title ...
-                                       'class' => 't3-delete'
+                                       'class' => 't3-js-delete'
                                )
                        );
                        $moveAndDeleteContent[] = '</div>';
index 8b52bdc..1f7ff74 100644 (file)
@@ -120,7 +120,7 @@ class FlexFormSectionContainer extends AbstractContainer {
 
                        $onClickInsert = array();
                        $onClickInsert[] = 'var ' . $uniqueId . ' = "' . 'idx"+(new Date()).getTime();';
-                       $onClickInsert[] = 'TYPO3.jQuery(' . json_encode($flexFormContainerContainerTemplateResult['html']) . '.' . $identifierPrefixJs . ').insertAfter(TYPO3.jQuery("#' . $flexFormFieldIdentifierPrefix . '"));';
+                       $onClickInsert[] = 'TYPO3.jQuery("#' . $flexFormFieldIdentifierPrefix . '").append(TYPO3.jQuery(' . json_encode($flexFormContainerContainerTemplateResult['html']) . '.' . $identifierPrefixJs . '));';
                        $onClickInsert[] = 'TYPO3.jQuery("#' . $flexFormFieldIdentifierPrefix . '").t3FormEngineFlexFormElement();';
                        $onClickInsert[] = 'eval(unescape("' . rawurlencode(implode(';', $flexFormContainerContainerTemplateResult['additionalJavaScriptPost'])) . '").' . $identifierPrefixJs . ');';
                        $onClickInsert[] = 'TBE_EDITOR.addActionChecks("submit", unescape("' . rawurlencode(implode(';', $flexFormContainerContainerTemplateResult['additionalJavaScriptSubmit'])) . '").' . $identifierPrefixJs . ');';
index 5bd56c2..02caa23 100644 (file)
@@ -35,7 +35,7 @@ define('TYPO3/CMS/Backend/FormEngineFlexForm', ['jquery', 'TYPO3/CMS/Backend/For
 
                        // remove any existing backups
                        var old_me = me.$el.data('TYPO3.FormEngine.FlexFormElement');
-                       if (old_me !== undefined) {
+                       if (typeof old_me !== 'undefined') {
                                me.$el.removeData('TYPO3.FormEngine.FlexFormElement');
                        }
 
@@ -64,11 +64,13 @@ define('TYPO3/CMS/Backend/FormEngineFlexForm', ['jquery', 'TYPO3/CMS/Backend/For
                        return me;
                };
 
-               // init all events related to the flexform
+               /**
+                * init all events related to the flexform. As this method is called multiple times,
+                * some handlers need to be off'ed first to prevent event stacking.
+                */
                me.initializeEvents = function() {
-
                        // Toggling all sections on/off by clicking all toggle buttons of each section
-                       me.$el.prev(opts.flexFormToggleAllSectionsSelector).on('click', function() {
+                       me.$el.prev(opts.flexFormToggleAllSectionsSelector).off('click').on('click', function() {
                                me.$el.find(opts.sectionToggleButtonSelector).trigger('click');
                        });
 
@@ -78,7 +80,7 @@ define('TYPO3/CMS/Backend/FormEngineFlexForm', ['jquery', 'TYPO3/CMS/Backend/For
                                me.createSortable();
 
                                // allow delete of a single section
-                               me.$el.on('click', opts.deleteIconSelector, function(evt) {
+                               me.$el.off('click').on('click', opts.deleteIconSelector, function(evt) {
                                        evt.preventDefault();
 
                                        // @todo: make this text localizable
@@ -105,7 +107,7 @@ define('TYPO3/CMS/Backend/FormEngineFlexForm', ['jquery', 'TYPO3/CMS/Backend/For
 
        // setting some default values
        TYPO3.FormEngine.FlexFormElement.defaults = {
-               'deleteIconSelector': '.t3-delete',
+               'deleteIconSelector': '.t3-js-delete',
                'sectionSelector': '.t3-flex-section',
                'sectionContentSelector': '.t3-flex-section-content',
                'sectionHeaderSelector': '.t3-flex-section-header',
@@ -114,7 +116,7 @@ define('TYPO3/CMS/Backend/FormEngineFlexForm', ['jquery', 'TYPO3/CMS/Backend/For
                'sectionToggleInputFieldSelector': '.t3-flex-control-toggle',
                'sectionToggleIconOpenSelector': '.t3-flex-control-toggle-icon-open',
                'sectionToggleIconCloseSelector': '.t3-flex-control-toggle-icon-close',
-               'sectionToggleButtonSelector': '.t3-flex-control-toggle-button',
+               'sectionToggleButtonSelector': 'a.t3-flex-control-toggle-button',
                'flexFormToggleAllSectionsSelector': '.t3-form-field-toggle-flexsection',
                'sectionDeletedClass': 't3-flex-section-deleted',
                'allowRestructure': 0,  // whether the form can be modified