[TASK] Streamline tbe_editor code 44/49644/4
authorBenni Mack <benni@typo3.org>
Tue, 30 Aug 2016 11:25:50 +0000 (13:25 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Sat, 3 Sep 2016 14:41:20 +0000 (16:41 +0200)
- Use proper JS language functionality,
- Remove unused lines
- Set formname to "editform" by default

Resolves: #77774
Releases: master
Change-Id: I77a4d92d5dbd2946174de6a1f2638f22167f399e
Reviewed-on: https://review.typo3.org/49644
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/backend/Classes/Controller/EditDocumentController.php
typo3/sysext/backend/Classes/Form/Container/FlexFormElementContainer.php
typo3/sysext/backend/Classes/Form/Container/SingleFieldContainer.php
typo3/sysext/backend/Classes/Form/Element/SelectTreeElement.php
typo3/sysext/backend/Classes/Form/FormResultCompiler.php
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine.js
typo3/sysext/backend/Resources/Public/JavaScript/jsfunc.evalfield.js
typo3/sysext/backend/Resources/Public/JavaScript/jsfunc.inline.js
typo3/sysext/backend/Resources/Public/JavaScript/jsfunc.tbe_editor.js

index 2659cb2..51a0847 100644 (file)
@@ -765,11 +765,9 @@ class EditDocumentController extends AbstractModule
         $javascript = '
                        TYPO3.configuration = ' . json_encode($t3Configuration) . ';
                        // Object: TS:
-                       // passwordDummy is used by tbe_editor.js and has to be declared here as
                        // TS object overwrites the object declared in tbe_editor.js
                        function typoSetup() {  //
                                this.uniqueID = "";
-                               this.passwordDummy = "********";
                        }
                        var TS = new typoSetup();
 
index d141f61..5e8d491 100644 (file)
@@ -98,7 +98,7 @@ class FlexFormElementContainer extends AbstractContainer
                     || !empty($GLOBALS['TCA'][$table]['ctrl']['requestUpdate']) && GeneralUtility::inList($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'], $flexFormFieldName)
                 ) {
                     if ($this->getBackendUserAuthentication()->jsConfirmation(JsConfirmation::TYPE_CHANGE)) {
-                        $alertMsgOnChange = 'top.TYPO3.Modal.confirm(TBE_EDITOR.labels.refreshRequired.title, TBE_EDITOR.labels.refreshRequired.content).on("button.clicked", function(e) { if (e.target.name == "ok" && TBE_EDITOR.checkSubmit(-1)) { TBE_EDITOR.submitForm() } top.TYPO3.Modal.dismiss(); });';
+                        $alertMsgOnChange = 'top.TYPO3.Modal.confirm(TYPO3.lang["FormEngine.refreshRequiredTitle"], TYPO3.lang["FormEngine.refreshRequiredContent"]).on("button.clicked", function(e) { if (e.target.name == "ok" && TBE_EDITOR.checkSubmit(-1)) { TBE_EDITOR.submitForm() } top.TYPO3.Modal.dismiss(); });';
                     } else {
                         $alertMsgOnChange = 'if (TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm();}';
                     }
index fb78cba..3ec30ee 100644 (file)
@@ -141,7 +141,7 @@ class SingleFieldContainer extends AbstractContainer
             && GeneralUtility::inList(str_replace(' ', '', $this->data['processedTca']['ctrl']['requestUpdate']), $fieldName)
         ) {
             if ($backendUser->jsConfirmation(JsConfirmation::TYPE_CHANGE)) {
-                $alertMsgOnChange = 'top.TYPO3.Modal.confirm(TBE_EDITOR.labels.refreshRequired.title, TBE_EDITOR.labels.refreshRequired.content).on("button.clicked", function(e) { if (e.target.name == "ok" && TBE_EDITOR.checkSubmit(-1)) { TBE_EDITOR.submitForm() } top.TYPO3.Modal.dismiss(); });';
+                $alertMsgOnChange = 'top.TYPO3.Modal.confirm(TYPO3.lang["FormEngine.refreshRequiredTitle"], TYPO3.lang["FormEngine.refreshRequiredContent"]).on("button.clicked", function(e) { if (e.target.name == "ok" && TBE_EDITOR.checkSubmit(-1)) { TBE_EDITOR.submitForm() } top.TYPO3.Modal.dismiss(); });';
             } else {
                 $alertMsgOnChange = 'if (TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
             }
index a0b9fe8..6c10053 100644 (file)
@@ -134,7 +134,7 @@ class SelectTreeElement extends AbstractFormElement
             && GeneralUtility::inList(str_replace(' ', '', $GLOBALS['TCA'][$table]['ctrl']['requestUpdate']), $field)
         ) {
             if ($this->getBackendUserAuthentication()->jsConfirmation(JsConfirmation::TYPE_CHANGE)) {
-                $onChange = 'top.TYPO3.Modal.confirm(TBE_EDITOR.labels.refreshRequired.title, TBE_EDITOR.labels.refreshRequired.content).on("button.clicked", function(e) { if (e.target.name == "ok" && TBE_EDITOR.checkSubmit(-1)) { TBE_EDITOR.submitForm() } top.TYPO3.Modal.dismiss(); });';
+                $onChange = 'top.TYPO3.Modal.confirm(TYPO3.lang["FormEngine.refreshRequiredTitle"], TYPO3.lang["FormEngine.refreshRequiredContent"]).on("button.clicked", function(e) { if (e.target.name == "ok" && TBE_EDITOR.checkSubmit(-1)) { TBE_EDITOR.submitForm() } top.TYPO3.Modal.dismiss(); });';
             } else {
                 $onChange .= 'if (TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
             }
index 5b68e23..447b7b3 100644 (file)
@@ -20,7 +20,6 @@ use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Lang\LanguageService;
 
 /**
  * This is form engine - Class for creating the backend editing forms.
@@ -193,18 +192,16 @@ class FormResultCompiler
         $pageRenderer = $this->getPageRenderer();
         $pageRenderer->addInlineSetting('FormEngine', 'formName', 'editform');
 
-        return $this->JSbottom('editform');
+        return $this->JSbottom();
     }
 
     /**
      * JavaScript bottom code
      *
-     * @param string $formname The identification of the form on the page.
      * @return string A section with JavaScript - if $update is FALSE, embedded in <script></script>
      */
-    protected function JSbottom($formname = 'forms[0]')
+    protected function JSbottom()
     {
-        $languageService = $this->getLanguageService();
         $pageRenderer = $this->getPageRenderer();
 
         // @todo: this is messy here - "additional hidden fields" should be handled elsewhere
@@ -285,21 +282,20 @@ class FormResultCompiler
         }
         // We want to load jQuery-ui inside our js. Enable this using requirejs.
         $pageRenderer->addJsFile('EXT:backend/Resources/Public/JavaScript/jsfunc.inline.js');
+
+        // todo: change these things in JS
+        $pageRenderer->addInlineLanguageLabelArray([
+            'FormEngine.noRecordTitle'          => 'LLL:EXT:lang/locallang_core.xlf:labels.no_title',
+            'FormEngine.fieldsChanged'          => 'LLL:EXT:lang/locallang_core.xlf:labels.fieldsChanged',
+            'FormEngine.fieldsMissing'          => 'LLL:EXT:lang/locallang_core.xlf:labels.fieldsMissing',
+            'FormEngine.maxItemsAllowed'        => 'LLL:EXT:lang/locallang_core.xlf:labels.maxItemsAllowed',
+            'FormEngine.refreshRequiredTitle'   => 'LLL:EXT:lang/locallang_core.xlf:mess.refreshRequired.title',
+            'FormEngine.refreshRequiredContent' => 'LLL:EXT:lang/locallang_core.xlf:mess.refreshRequired.content',
+            'FormEngine.remainingCharacters'    => 'LLL:EXT:lang/locallang_core.xlf:labels.remainingCharacters',
+        ], true);
+
         $out = '
-               inline.setNoTitleString(' . GeneralUtility::quoteJSvalue(BackendUtility::getNoRecordTitle(true)) . ');
-               TBE_EDITOR.formname = "' . $formname . '";
-               TBE_EDITOR.formnameUENC = "' . rawurlencode($formname) . '";
-               TBE_EDITOR.isPalettedoc = null;
                TBE_EDITOR.doSaveFieldName = "' . ($this->doSaveFieldName ? addslashes($this->doSaveFieldName) : '') . '";
-               TBE_EDITOR.labels.fieldsChanged = ' . GeneralUtility::quoteJSvalue($languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.fieldsChanged')) . ';
-               TBE_EDITOR.labels.fieldsMissing = ' . GeneralUtility::quoteJSvalue($languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.fieldsMissing')) . ';
-               TBE_EDITOR.labels.maxItemsAllowed = ' . GeneralUtility::quoteJSvalue($languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.maxItemsAllowed')) . ';
-               TBE_EDITOR.labels.refresh_login = ' . GeneralUtility::quoteJSvalue($languageService->sL('LLL:EXT:lang/locallang_core.xlf:mess.refresh_login')) . ';
-               TBE_EDITOR.labels.refreshRequired = {};
-               TBE_EDITOR.labels.refreshRequired.title = ' . GeneralUtility::quoteJSvalue($languageService->sL('LLL:EXT:lang/locallang_core.xlf:mess.refreshRequired.title')) . ';
-               TBE_EDITOR.labels.refreshRequired.content = ' . GeneralUtility::quoteJSvalue($languageService->sL('LLL:EXT:lang/locallang_core.xlf:mess.refreshRequired.content')) . ';
-               TBE_EDITOR.labels.remainingCharacters = ' . GeneralUtility::quoteJSvalue($languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.remainingCharacters')) . ';
-               TBE_EDITOR.customEvalFunctions = {};
                ';
 
         // Add JS required for inline fields
@@ -330,14 +326,6 @@ class FormResultCompiler
     }
 
     /**
-     * @return LanguageService
-     */
-    protected function getLanguageService()
-    {
-        return $GLOBALS['LANG'];
-    }
-
-    /**
      * Wrapper for access to the current page renderer object
      *
      * @return \TYPO3\CMS\Core\Page\PageRenderer
index 6ef9fc0..4af7b61 100644 (file)
@@ -711,7 +711,7 @@ define(['jquery',
 
                        // append the counter only at focus to avoid cluttering the DOM
                        $parent.append($('<div />', {'class': 't3js-charcounter'}).append(
-                               $('<span />', {'class': maxlengthProperties.labelClass}).text(TBE_EDITOR.labels.remainingCharacters.replace('{0}', maxlengthProperties.remainingCharacters))
+                               $('<span />', {'class': maxlengthProperties.labelClass}).text(TYPO3.lang['FormEngine.remainingCharacters'].replace('{0}', maxlengthProperties.remainingCharacters))
                        ));
                }).on('blur', function() {
                        var $field = $(this),
@@ -723,7 +723,7 @@ define(['jquery',
                                maxlengthProperties = FormEngine.getCharacterCounterProperties($field);
 
                        // change class and value
-                       $parent.find('.t3js-charcounter span').removeClass().addClass(maxlengthProperties.labelClass).text(TBE_EDITOR.labels.remainingCharacters.replace('{0}', maxlengthProperties.remainingCharacters))
+                       $parent.find('.t3js-charcounter span').removeClass().addClass(maxlengthProperties.labelClass).text(TYPO3.lang['FormEngine.remainingCharacters'].replace('{0}', maxlengthProperties.remainingCharacters))
                });
                $(':password').on('focus', function() {
                        $(this).attr('type', 'text').select();
index 3403a6d..d34384e 100644 (file)
@@ -455,7 +455,7 @@ function evalFunc_output(type,value,FObj) {
                        theString = h+':'+((m<10)?'0':'')+m + ((type=="timesec")?':'+((s<10)?'0':'')+s:'');
                        break;
                case "password":
-                       theString = (value)     ? TS.passwordDummy : "";
+                       theString = (value)     ? "********" : "";
                        break;
                case "int":
                        theString = (FObj.checkbox && value==FObj.checkboxValue)?'':value;
index e863fca..ccfd911 100644 (file)
@@ -23,7 +23,7 @@ var inline = {
        structureSeparator: '-',
        flexFormSeparator: '---',
        flexFormSubstitute: ':',
-       noTitleString: '[No title]',
+       noTitleString: (TYPO3.lang ? TYPO3.lang['FormEngine.noRecordTitle'] : '[No title]'),
        lockedAjaxMethod: {},
        sourcesLoaded: {},
        data: {},
@@ -163,7 +163,7 @@ var inline = {
                        }
                        this.makeAjaxCall('create', [objectId], true, context);
                } else {
-                       var message = TBE_EDITOR.labels.maxItemsAllowed.replace('{0}', this.data.config[objectId].max);
+                       var message = TYPO3.lang['FormEngine.maxItemsAllowed'].replace('{0}', this.data.config[objectId].max);
                        var matches = objectId.match(/^(data-\d+-.*?-\d+-.*?)-(.*?)$/);
                        var title = '';
                        if (matches) {
@@ -497,7 +497,7 @@ var inline = {
                                $insertObject.after(htmlData);
                        }
                } else {
-                       var message = TBE_EDITOR.labels.maxItemsAllowed.replace('{0}', this.data.config[objectPrefix].max);
+                       var message = TYPO3.lang['FormEngine.maxItemsAllowed'].replace('{0}', this.data.config[objectPrefix].max);
                        var title = $insertObject.data('title');
                        top.TYPO3.Notification.error(title, message);
                }
index 48d4dcf..3ca4fa6 100644 (file)
@@ -33,21 +33,14 @@ var TBE_EDITOR = {
        nested: {'field':{}, 'level':{}},
        ignoreElements: [],
        actionChecks: { submit: [] },
+       customEvalFunctions: {},
 
-       formname: '',
-       formnameUENC: '',
+       formname: 'editform',
        isChanged: 0,
 
-       isPalettedoc: null,
        doSaveFieldName: 0,
 
        labels: {},
-       images: {
-               req: new Image(),
-               cm: new Image(),
-               sel: new Image(),
-               clear: new Image()
-       },
 
        clearBeforeSettingFormValueFromBrowseWin: [],
 
@@ -81,46 +74,9 @@ var TBE_EDITOR = {
 
                return result;
        },
-       checkElements: function(type, recentUpdated, record, field) {
+       checkElements: function() {
                return (document.getElementsByClassName('has-error').length == 0);
        },
-       // Check all the input fields on a given level of nesting - if only on is unfilled, the whole level is marked as required:
-       checkNested: function(nestedLevelIdent) {
-               var nestedLevel, isClean;
-               if (nestedLevelIdent && TBE_EDITOR.nested.level && TBE_EDITOR.nested.level[nestedLevelIdent]) {
-                       nestedLevel = TBE_EDITOR.nested.level[nestedLevelIdent];
-                       if (!nestedLevel.clean) {
-                               if (typeof nestedLevel.item === 'object') {
-                                       TYPO3.jQuery.each(nestedLevel.item, function(key, value) {
-                                                       if (isClean || typeof isClean === 'undefined') {
-                                                               isClean = (
-                                                                       TBE_EDITOR.checkElements('required', false, value[0], value[1]) &&
-                                                                       TBE_EDITOR.checkElements('range', false, value[0], value[1])
-                                                               );
-                                                       }
-                                               }
-                                       );
-                                       if (typeof isClean !== 'undefined' && !isClean) {
-                                               return false;
-                                       }
-                               }
-                               if (typeof nestedLevel.sub === 'object') {
-                                       TYPO3.jQuery.each(nestedLevel.sub, function(key, value) {
-                                                       if (isClean || typeof isClean === 'undefined') {
-                                                               isClean = TBE_EDITOR.checkNested(key);
-                                                       }
-                                               }
-                                       );
-                                       if (typeof isClean !== 'undefined' && !isClean) {
-                                               return false;
-                                       }
-                               }
-                                       // Store the result, that this level (the fields on this and the sub levels) are clean:
-                               nestedLevel.clean = true;
-                       }
-               }
-               return true;
-       },
        addActionChecks: function(type, checks) {
                TBE_EDITOR.actionChecks[type].push(checks);
        },
@@ -138,7 +94,6 @@ var TBE_EDITOR = {
        },
        fieldChanged: function(table,uid,field,el) {
                var theField = 'data['+table+']['+uid+']['+field+']';
-               var theRecord = 'data['+table+']['+uid+']';
                TBE_EDITOR.isChanged = 1;
 
                // modify the "field has changed" info by adding a class to the container element (based on palette or main field)
@@ -147,38 +102,16 @@ var TBE_EDITOR = {
                if (!$formField.is($humanReadableField)) {
                        $humanReadableField.triggerHandler('change');
                }
-               var $paletteField = $formField.closest('.t3js-formengine-palette-field');
-               $paletteField.addClass('has-change');
+               // add class to palette field
+               $formField.closest('.t3js-formengine-palette-field').addClass('has-change');
 
-               // Set required flag:
-               var imgReqObjName = "req_"+table+"_"+uid+"_"+field;
-               if (TBE_EDITOR.getElement(theRecord,field,'required') && document[TBE_EDITOR.formname][theField]) {
-                       if (TBE_EDITOR.checkElements('required', false, theRecord, field)) {
-                               TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.clear);
-                       } else {
-                               TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.req);
-                       }
-               }
-               if (TBE_EDITOR.getElement(theRecord,field,'range') && document[TBE_EDITOR.formname][theField]) {
-                       if (TBE_EDITOR.checkElements('range', false, theRecord, field)) {
-                               TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.clear);
-                       } else {
-                               TBE_EDITOR.setImage(imgReqObjName,TBE_EDITOR.images.req);
-                       }
-               }
-               if (TBE_EDITOR.isPalettedoc) { TBE_EDITOR.setOriginalFormFieldValue(theField) }
                if (TYPO3.FormEngine && TYPO3.FormEngine.Validation) {
                        TYPO3.FormEngine.Validation.updateInputField(theField);
                        TYPO3.FormEngine.Validation.validate();
                }
        },
-       setOriginalFormFieldValue: function(theField) {
-               if (TBE_EDITOR.isPalettedoc && (TBE_EDITOR.isPalettedoc).document[TBE_EDITOR.formname] && (TBE_EDITOR.isPalettedoc).document[TBE_EDITOR.formname][theField]) {
-                       (TBE_EDITOR.isPalettedoc).document[TBE_EDITOR.formname][theField].value = document[TBE_EDITOR.formname][theField].value;
-               }
-       },
        isFormChanged: function(noAlert) {
-               if (TBE_EDITOR.isChanged && !noAlert && confirm(TBE_EDITOR.labels.fieldsChanged)) {
+               if (TBE_EDITOR.isChanged && !noAlert && confirm(TYPO3.lang['FormEngine.fieldsChanged'])) {
                        return 0;
                }
                return TBE_EDITOR.isChanged;
@@ -218,10 +151,9 @@ var TBE_EDITOR = {
                                OK = 1;
                        }
                }
-               // $reqLinesCheck
-               if (!TBE_EDITOR.checkElements('required', false)) { OK = 0; }
-               // $reqRangeCheck
-               if (!TBE_EDITOR.checkElements('range', false)) { OK = 0; }
+               if (!TBE_EDITOR.checkElements()) {
+                       OK = 0;
+               }
 
                if (OK || sendAlert==-1) {
                        return true;
@@ -230,7 +162,7 @@ var TBE_EDITOR = {
                                var t = (opener != null && typeof opener.top.TYPO3 !== 'undefined' ? opener.top : top);
                                t.TYPO3.Modal.confirm(
                                        t.TYPO3.lang['alert'] || 'Alert',
-                                       TBE_EDITOR.labels.fieldsMissing,
+                                       t.TYPO3.lang['FormEngine.fieldsMissing'],
                                        t.TYPO3.Severity.error,
                                        [
                                                {
@@ -247,33 +179,6 @@ var TBE_EDITOR = {
                        return false;
                }
        },
-       checkRange: function(numberOfElements, lower, upper) {
-                       // for backwards compatibility, check if we're dealing with an element as first parameter
-               if(typeof numberOfElements == 'object') {
-                       numberOfElements = numberOfElements.length;
-               }
-
-               if (numberOfElements >= lower && numberOfElements <= upper) {
-                       return true;
-               } else {
-                       return false;
-               }
-       },
-       setImage: function(name,image) {
-               var object;
-               if (document[name]) {
-                       object = document[name];
-               } else if (document.getElementById(name)) {
-                       object = document.getElementById(name);
-               }
-               if (object) {
-                       if (typeof image == 'object') {
-                               document[name].src = image.src;
-                       } else {
-                               document[name].src = eval(image+'.src');
-                       }
-               }
-       },
        submitForm: function() {
                if (TBE_EDITOR.doSaveFieldName) {
                        document[TBE_EDITOR.formname][TBE_EDITOR.doSaveFieldName].value=1;
@@ -334,40 +239,16 @@ var TBE_EDITOR = {
                output+=''+input.substr(pointer);
                return output;
        },
-       toggle_display_states: function(id, state_1, state_2) {
-               var node = document.getElementById(id);
-               if (node) {
-                       switch (node.style.display) {
-                               case state_1:
-                                       node.style.display = state_2;
-                                       break;
-                               case state_2:
-                                       node.style.display = state_1;
-                                       break;
-                       }
-               }
-               return false;
-       },
-
 };
 
-function typoSetup     () {
-       this.passwordDummy = '********';
-}
-// @todo: maybe obsolete, need a deeper check
-var TS = new typoSetup();
-
 // backwards compatibility for extensions
 var TBE_EDITOR_setHiddenContent = TBE_EDITOR.setHiddenContent;
 var TBE_EDITOR_isChanged = TBE_EDITOR.isChanged;
 var TBE_EDITOR_fieldChanged_fName = TBE_EDITOR.fieldChanged_fName;
 var TBE_EDITOR_fieldChanged = TBE_EDITOR.fieldChanged;
-var TBE_EDITOR_setOriginalFormFieldValue = TBE_EDITOR.setOriginalFormFieldValue;
 var TBE_EDITOR_isFormChanged = TBE_EDITOR.isFormChanged;
 var TBE_EDITOR_checkAndDoSubmit = TBE_EDITOR.checkAndDoSubmit;
 var TBE_EDITOR_checkSubmit = TBE_EDITOR.checkSubmit;
-var TBE_EDITOR_checkRange = TBE_EDITOR.checkRange;
-var TBE_EDITOR_setImage = TBE_EDITOR.setImage;
 var TBE_EDITOR_submitForm = TBE_EDITOR.submitForm;
 var TBE_EDITOR_split = TBE_EDITOR.split;
 var TBE_EDITOR_curSelected = TBE_EDITOR.curSelected;