[+FEATURE] t3editor: use the t3editor in TCA-Forms
authorTobias Liebig <mail_typo3.org@etobi.de>
Wed, 2 Mar 2011 15:00:11 +0000 (16:00 +0100)
committerJochen Rau <j.rau@web.de>
Sat, 5 Mar 2011 07:08:52 +0000 (08:08 +0100)
Change-Id: Ib61434c6a959d492dcee42b2a38631482c93b713
Resolves: #M17863
Reviewed-on: http://review.typo3.org/1033
Reviewed-by: Markus Klein <klein.t3@mfc-linz.at>
Tested-by: Markus Klein <klein.t3@mfc-linz.at>
Reviewed-by: Jochen Rau <j.rau@web.de>
Tested-by: Jochen Rau <j.rau@web.de>
typo3/sysext/cms/tbl_tt_content.php
typo3/sysext/t3editor/classes/class.tx_t3editor.php
typo3/sysext/t3editor/classes/class.tx_t3editor_tceforms_wizard.php [new file with mode: 0644]
typo3/sysext/t3editor/res/jslib/t3editor.js

index c322f36..ff0c5ff 100755 (executable)
@@ -475,6 +475,17 @@ $TCA['tt_content'] = array(
                                                        'xmlOutput' => 0,
                                                ),
                                        ),
+                                       't3editor' => array(
+                                               'enableByTypeConfig' => 1,
+                                               'type' => 'userFunc',
+                                               'userFunc' => 'EXT:t3editor/classes/class.tx_t3editor_tceforms_wizard.php:tx_t3editor_tceforms_wizard->main',
+                                               'title' => 't3editor',
+                                               'icon' => 'wizard_table.gif',
+                                               'script' => 'wizard_table.php',
+                                               'params' => array(
+                                                       'format' => 'html',
+                                               ),
+                                       ),
                                ),
                                'softref' => 'typolink_tag,images,email[subst],url',
                        ),
@@ -1911,7 +1922,7 @@ $TCA['tt_content'] = array(
                        'showitem' =>
                                        '--palette--;LLL:EXT:cms/locallang_ttc.xml:palette.general;general,
                                        header;LLL:EXT:cms/locallang_ttc.xml:header.ALT.html_formlabel,
-                                       bodytext;LLL:EXT:cms/locallang_ttc.xml:bodytext.ALT.html_formlabel;;nowrap,
+                                       bodytext;LLL:EXT:cms/locallang_ttc.xml:bodytext.ALT.html_formlabel;;nowrap:wizards[t3editor],
                                --div--;LLL:EXT:cms/locallang_ttc.xml:tabs.access,
                                        --palette--;LLL:EXT:cms/locallang_ttc.xml:palette.visibility;visibility,
                                        --palette--;LLL:EXT:cms/locallang_ttc.xml:palette.access;access,
index 0329efb..260b065 100644 (file)
@@ -42,6 +42,7 @@ class tx_t3editor implements t3lib_Singleton {
        const MODE_XML = 'xml';
        const MODE_HTML = 'html';
        const MODE_PHP = 'php';
+       const MODE_SPARQL = 'sparql';
        const MODE_MIXED = 'mixed';
 
        protected $mode = '';
@@ -85,7 +86,11 @@ class tx_t3editor implements t3lib_Singleton {
 
        public function setModeByFile($file) {
                $fileInfo = t3lib_div::split_fileref($file);
-               switch ($fileInfo['fileext']) {
+               return $this->setModeByType($fileInfo['fileext']);
+       }
+
+       public function setModeByType($type) {
+               switch ($type) {
                        case 'html':
                        case 'htm':
                        case 'tmpl':
@@ -104,6 +109,9 @@ class tx_t3editor implements t3lib_Singleton {
                        case 'ts':
                                $mode = self::MODE_TYPOSCRIPT;
                                break;
+                       case 'sparql':
+                               $mode = self::MODE_SPARQL;
+                               break;
                        case 'php':
                        case 'phpsh':
                        case 'inc':
@@ -169,14 +177,12 @@ class tx_t3editor implements t3lib_Singleton {
 
                        $content .= t3lib_div::wrapJS(
                                'T3editor = T3editor || {};' .
-                               'T3editor.lang = ' . json_encode($this->getJavaScriptLabels()) .';' . LF.
-                               'T3editor.PATH_t3e = "' . $GLOBALS['BACK_PATH'] . $path_t3e . '"; ' . LF.
-                               'T3editor.PATH_codemirror = "' . $GLOBALS['BACK_PATH'] . $path_codemirror . '"; ' . LF.
-                               'T3editor.URL_typo3 = "' . htmlspecialchars(t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir) . '"; ' .LF.
-                               'T3editor.template = '. $this->getPreparedTemplate() .';' .LF.
-                               ($this->ajaxSaveType ? 'T3editor.ajaxSavetype = "' . $this->ajaxSaveType . '";' . LF : '') .
-                               ($this->mode ? 'T3editor.parserfile = ' . $this->getParserfileByMode($this->mode) . ';' . LF : '') .
-                               ($this->mode ? 'T3editor.stylesheet = ' . $this->getStylesheetByMode($this->mode) . ';' : '')
+                               'T3editor.lang = ' . json_encode($this->getJavaScriptLabels()) .';' . LF .
+                               'T3editor.PATH_t3e = "' . $GLOBALS['BACK_PATH'] . $path_t3e . '"; ' . LF .
+                               'T3editor.PATH_codemirror = "' . $GLOBALS['BACK_PATH'] . $path_codemirror . '"; ' . LF .
+                               'T3editor.URL_typo3 = "' . htmlspecialchars(t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir) . '"; ' . LF .
+                               'T3editor.template = '. $this->getPreparedTemplate() .';' . LF .
+                               'T3editor.ajaxSavetype = "' . $this->ajaxSaveType . '";' . LF
                        );
             $content .= $this->getModeSpecificJavascriptCode();
                }
@@ -232,7 +238,7 @@ class tx_t3editor implements t3lib_Singleton {
        protected function getParserfileByMode($mode) {
                switch ($mode) {
                        case tx_t3editor::MODE_TYPOSCRIPT:
-                               $relPath = $GLOBALS['BACK_PATH'] . t3lib_extmgm::extRelPath('t3editor') . 'res/jslib/parse_typoscript/';
+                               $relPath = ($GLOBALS['BACK_PATH'] ? $GLOBALS['BACK_PATH'] : '../../../' ) . t3lib_extmgm::extRelPath('t3editor') . 'res/jslib/parse_typoscript/';
                                $parserfile = '["' . $relPath . 'tokenizetyposcript.js", "' . $relPath . 'parsetyposcript.js"]';
                                break;
 
@@ -248,6 +254,10 @@ class tx_t3editor implements t3lib_Singleton {
                                $parserfile = '"parsexml.js"';
                                break;
 
+                       case tx_t3editor::MODE_SPARQL:
+                               $parserfile = '"parsesparql.js"';
+                               break;
+
                        case tx_t3editor::MODE_HTML:
                                $parserfile = '["tokenizejavascript.js", "parsejavascript.js", "parsecss.js", "parsexml.js", "parsehtmlmixed.js"]';
                                break;
@@ -277,39 +287,46 @@ class tx_t3editor implements t3lib_Singleton {
        protected function getStylesheetByMode($mode) {
                switch ($mode) {
                        case tx_t3editor::MODE_TYPOSCRIPT:
-                               $stylesheet = '"res/css/typoscriptcolors.css"';
-                       break;
+                               $stylesheet = 'T3editor.PATH_t3e + "res/css/typoscriptcolors.css"';
+                               break;
 
                        case tx_t3editor::MODE_JAVASCRIPT:
-                               $stylesheet = '"res/css/jscolors.css"';
-                       break;
+                               $stylesheet = 'T3editor.PATH_codemirror + "../css/jscolors.css"';
+                               break;
 
                        case tx_t3editor::MODE_CSS:
-                               $stylesheet = '"res/css/csscolors.css"';
-                       break;
+                               $stylesheet = 'T3editor.PATH_codemirror + "../css/csscolors.css"';
+                               break;
 
                        case tx_t3editor::MODE_XML:
-                               $stylesheet = '"res/css/xmlcolors.css"';
-                       break;
+                               $stylesheet = 'T3editor.PATH_codemirror + "../css/xmlcolors.css"';
+                               break;
 
                        case tx_t3editor::MODE_HTML:
-                               $stylesheet = '"res/css/xmlcolors.css", ' .
-                                       'T3editor.PATH_t3e + "res/css/jscolors.css", ' .
-                                       'T3editor.PATH_t3e + "res/css/csscolors.css"';
-                       break;
+                               $stylesheet = 'T3editor.PATH_codemirror + "../css/xmlcolors.css", ' .
+                                       'T3editor.PATH_codemirror + "../css/jscolors.css", ' .
+                                       'T3editor.PATH_codemirror + "../css/csscolors.css"';
+                               break;
+
+                       case tx_t3editor::MODE_SPARQL:
+                               $stylesheet = 'T3editor.PATH_codemirror + "../css/sparqlcolors.css"';
+                               break;
 
                        case tx_t3editor::MODE_PHP:
-                               $stylesheet = '"../../contrib/codemirror/contrib/php/css/phpcolors.css"';
-                       break;
+                               $stylesheet = 'T3editor.PATH_codemirror + "../contrib/php/css/phpcolors.css"';
+                               break;
 
                        case tx_t3editor::MODE_MIXED:
-                               $stylesheet = '"res/css/xmlcolors.css", ' .
-                                       'T3editor.PATH_t3e + "res/css/jscolors.css", ' .
-                                       'T3editor.PATH_t3e + "res/css/csscolors.css", ' .
+                               $stylesheet = 'T3editor.PATH_codemirror + "../css/xmlcolors.css", ' .
+                                       'T3editor.PATH_codemirror + "../css/jscolors.css", ' .
+                                       'T3editor.PATH_codemirror + "../css/csscolors.css", ' .
                                        'T3editor.PATH_codemirror + "../contrib/php/css/phpcolors.css"';
-                       break;
+                               break;
+               }
+               if ($stylesheet != '') {
+                       $stylesheet = '' . $stylesheet . ', ';
                }
-               return '[T3editor.PATH_t3e + ' . $stylesheet . ', T3editor.PATH_t3e + "res/css/t3editor_inner.css"]';
+               return '[' . $stylesheet . 'T3editor.PATH_t3e + "res/css/t3editor_inner.css"]';
        }
 
        /**
diff --git a/typo3/sysext/t3editor/classes/class.tx_t3editor_tceforms_wizard.php b/typo3/sysext/t3editor/classes/class.tx_t3editor_tceforms_wizard.php
new file mode 100644 (file)
index 0000000..ab423a1
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+require_once(t3lib_extMgm::extPath('t3editor', 'classes/class.tx_t3editor.php'));
+
+class tx_t3editor_tceforms_wizard {
+
+       public function main($parameters, $pObj) {
+               $t3editor = t3lib_div::makeInstance('tx_t3editor');
+               if (!$t3editor->isEnabled()) {
+                       return;
+               }
+               if ($parameters['params']['format'] !== '') {
+                       $t3editor->setModeByType($parameters['params']['format']);
+               } else {
+                       $t3editor->setMode(tx_t3editor::MODE_MIXED);
+               }
+
+               $config = $GLOBALS['TCA'][$parameters['table']]['columns'][$parameters['field']]['config'];
+               $doc = $GLOBALS['SOBE']->doc;
+
+               $attributes = 'rows="' . $config['rows'] . '" ' .
+                       'cols="' . $config['cols'] . '" ' .
+                       'wrap="off" ' .
+                       'style="width:98%; height: 200px;" ' .
+                       'onchange="' . $parameters['fieldChangeFunc']['TBE_EDITOR_fieldChanged'] . '" ';
+
+               $parameters['item'] = '';
+               $parameters['item'] .= $t3editor->getCodeEditor(
+                       $parameters['itemName'],
+                       'fixed-font enable-tab',
+                       $parameters['row'][$parameters['field']],
+                       $attributes,
+                       $parameters['table'] . ' > ' . $parameters['field'],
+                       array(
+                               'target' => intval($pObj->target)
+                       )
+               );
+               $parameters['item'] .= $t3editor->getJavascriptCode($doc);
+               return '';
+       }
+}
+?>
index 8dc1c2d..931e60a 100644 (file)
@@ -163,6 +163,9 @@ T3editor.prototype = {
                },
 
                saveFunction: function(event) {
+                       if (!T3editor.ajaxSavetype || T3editor.ajaxSavetype == '') {
+                               return;
+                       }
                        this.modalOverlay.show();
                        this.updateTextarea(event);