[FEATURE] Implement configurable background colors for tree branches
authorStefan Galinski <stefan.galinski@gmail.com>
Sat, 14 Apr 2012 20:25:04 +0000 (22:25 +0200)
committerTolleiv Nietsch <tolleiv.nietsch@typo3.org>
Mon, 16 Apr 2012 19:12:52 +0000 (21:12 +0200)
The syntax of the new user typoscript setting:
options.pageTree.backgroundColor.<pageId> = <color>

Change-Id: Ic91257c83c8b5e012374e5d5731dd70ae3daee36
Resolves: #36066
Releases: 6.0
Reviewed-on: http://review.typo3.org/10503
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Tolleiv Nietsch
Tested-by: Tolleiv Nietsch
t3lib/js/extjs/components/pagetree/javascript/nodeui.js
t3lib/tree/pagetree/class.t3lib_tree_pagetree_commands.php
t3lib/tree/pagetree/class.t3lib_tree_pagetree_node.php

index 1a10660..1e72db5 100644 (file)
@@ -51,14 +51,19 @@ TYPO3.Components.PageTree.PageTreeNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
         var cb = Ext.isBoolean(a.checked),
             nel,
             href = this.getHref(a.href),
         var cb = Ext.isBoolean(a.checked),
             nel,
             href = this.getHref(a.href),
+                       nodeStyles = '',
                        rootline = '';
 
                        // TYPO3 modification to show the readable rootline above the user mounts
                if (a.readableRootline !== '') {
                        rootline = '';
 
                        // TYPO3 modification to show the readable rootline above the user mounts
                if (a.readableRootline !== '') {
-                       var rootline = '<li class="x-tree-node-readableRootline">' + a.readableRootline + '</li>';
+                       rootline = '<li class="x-tree-node-readableRootline">' + a.readableRootline + '</li>';
                }
 
                }
 
-               var buf = [rootline,'<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf x-unselectable ', a.cls,'" unselectable="on">',
+               if (a.nodeData.backgroundColor) {
+                       nodeStyles = 'style="background-color: ' + a.nodeData.backgroundColor + '"';
+               }
+
+               var buf = [rootline,'<li class="x-tree-node" ' + nodeStyles + '><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf x-unselectable ', a.cls,'" unselectable="on">',
             '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
             '<img alt="" src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',
 //            '<img alt="" src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
             '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
             '<img alt="" src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',
 //            '<img alt="" src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
index a4324ee..eff84c7 100644 (file)
  */
 final class t3lib_tree_pagetree_Commands {
        /**
  */
 final class t3lib_tree_pagetree_Commands {
        /**
+        * @var boolean|null
+        */
+       static protected $useNavTitle = NULL;
+
+       /**
+        * @var boolean|null
+        */
+       static protected $addIdAsPrefix = NULL;
+
+       /**
+        * @var boolean|null
+        */
+       static protected $addDomainName = NULL;
+
+       /**
+        * @var array|null
+        */
+       static protected $backgroundColors = NULL;
+
+       /**
+        * @var int|null
+        */
+       static protected $titleLength = NULL;
+
+       /**
         * Visibly the page
         *
         * Visibly the page
         *
-        * @param t3lib_tree_pagetree_Node $nodeData
+        * @param t3lib_tree_pagetree_Node $node
         * @return void
         */
        public static function visiblyNode(t3lib_tree_pagetree_Node $node) {
         * @return void
         */
        public static function visiblyNode(t3lib_tree_pagetree_Node $node) {
@@ -47,7 +72,7 @@ final class t3lib_tree_pagetree_Commands {
        /**
         * Hide the page
         *
        /**
         * Hide the page
         *
-        * @param t3lib_tree_pagetree_Node $nodeData
+        * @param t3lib_tree_pagetree_Node $node
         * @return void
         */
        public static function disableNode(t3lib_tree_pagetree_Node $node) {
         * @return void
         */
        public static function disableNode(t3lib_tree_pagetree_Node $node) {
@@ -58,7 +83,7 @@ final class t3lib_tree_pagetree_Commands {
        /**
         * Delete the page
         *
        /**
         * Delete the page
         *
-        * @param t3lib_tree_pagetree_Node $nodeData
+        * @param t3lib_tree_pagetree_Node $node
         * @return void
         */
        public static function deleteNode(t3lib_tree_pagetree_Node $node) {
         * @return void
         */
        public static function deleteNode(t3lib_tree_pagetree_Node $node) {
@@ -69,7 +94,7 @@ final class t3lib_tree_pagetree_Commands {
        /**
         * Restore the page
         *
        /**
         * Restore the page
         *
-        * @param t3lib_tree_pagetree_Node $nodeData
+        * @param t3lib_tree_pagetree_Node $node
         * @param int $targetId
         * @return void
         */
         * @param int $targetId
         * @return void
         */
@@ -85,7 +110,7 @@ final class t3lib_tree_pagetree_Commands {
        /**
         * Updates the node label
         *
        /**
         * Updates the node label
         *
-        * @param t3lib_tree_pagetree_Node $nodeData
+        * @param t3lib_tree_pagetree_Node $node
         * @param string $updatedLabel
         * @return void
         */
         * @param string $updatedLabel
         * @return void
         */
@@ -214,7 +239,7 @@ final class t3lib_tree_pagetree_Commands {
         *
         * @static
         * @param int $uid
         *
         * @static
         * @param int $uid
-        * @return void
+        * @return string
         */
        public static function getMountPointPath($uid = -1) {
                if ($uid === -1) {
         */
        public static function getMountPointPath($uid = -1) {
                if ($uid === -1) {
@@ -225,7 +250,9 @@ final class t3lib_tree_pagetree_Commands {
                        return '';
                }
 
                        return '';
                }
 
-               $useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
+               if (self::$useNavTitle === NULL) {
+                       self::$useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
+               }
                $rootline = array_reverse(t3lib_BEfunc::BEgetRootLine($uid));
                array_shift($rootline);
 
                $rootline = array_reverse(t3lib_BEfunc::BEgetRootLine($uid));
                array_shift($rootline);
 
@@ -234,7 +261,7 @@ final class t3lib_tree_pagetree_Commands {
                        $record = t3lib_tree_pagetree_Commands::getNodeRecord($rootlineElement['uid']);
 
                        $text = $record['title'];
                        $record = t3lib_tree_pagetree_Commands::getNodeRecord($rootlineElement['uid']);
 
                        $text = $record['title'];
-                       if ($useNavTitle && trim($record['nav_title']) !== '') {
+                       if (self::$useNavTitle && trim($record['nav_title']) !== '') {
                                $text = $record['nav_title'];
                        }
 
                                $text = $record['nav_title'];
                        }
 
@@ -285,13 +312,17 @@ final class t3lib_tree_pagetree_Commands {
         * Creates a node with the given record information's
         *
         * @param array $record
         * Creates a node with the given record information's
         *
         * @param array $record
+        * @param int $mountPoint
         * @return t3lib_tree_pagetree_Node
         */
        public static function getNewNode($record, $mountPoint = 0) {
         * @return t3lib_tree_pagetree_Node
         */
        public static function getNewNode($record, $mountPoint = 0) {
-               $useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
-               $addIdAsPrefix = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
-               $addDomainName = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showDomainNameWithTitle');
-               $titleLength = intval($GLOBALS['BE_USER']->uc['titleLen']);
+               if (self::$titleLength === NULL) {
+                       self::$useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
+                       self::$addIdAsPrefix = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
+                       self::$addDomainName = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showDomainNameWithTitle');
+                       self::$backgroundColors = $GLOBALS['BE_USER']->getTSConfigProp('options.pageTree.backgroundColor');
+                       self::$titleLength = intval($GLOBALS['BE_USER']->uc['titleLen']);
+               }
 
                /** @var $subNode t3lib_tree_pagetree_Node */
                $subNode = t3lib_div::makeInstance('t3lib_tree_pagetree_Node');
 
                /** @var $subNode t3lib_tree_pagetree_Node */
                $subNode = t3lib_div::makeInstance('t3lib_tree_pagetree_Node');
@@ -302,10 +333,11 @@ final class t3lib_tree_pagetree_Commands {
                $subNode->setId($record['uid']);
                $subNode->setMountPoint($mountPoint);
                $subNode->setWorkspaceId(($record['_ORIG_uid'] ? $record['_ORIG_uid'] : $record['uid']));
                $subNode->setId($record['uid']);
                $subNode->setMountPoint($mountPoint);
                $subNode->setWorkspaceId(($record['_ORIG_uid'] ? $record['_ORIG_uid'] : $record['uid']));
+               $subNode->setBackgroundColor(self::$backgroundColors[$record['uid']]);
 
                $field = 'title';
                $text = $record['title'];
 
                $field = 'title';
                $text = $record['title'];
-               if ($useNavTitle && trim($record['nav_title']) !== '') {
+               if (self::$useNavTitle && trim($record['nav_title']) !== '') {
                        $field = 'nav_title';
                        $text = $record['nav_title'];
                }
                        $field = 'nav_title';
                        $text = $record['nav_title'];
                }
@@ -315,10 +347,10 @@ final class t3lib_tree_pagetree_Commands {
                } else {
                        $visibleText = $text;
                }
                } else {
                        $visibleText = $text;
                }
-               $visibleText = t3lib_div::fixed_lgd_cs($visibleText, $titleLength);
+               $visibleText = t3lib_div::fixed_lgd_cs($visibleText, self::$titleLength);
 
                $suffix = '';
 
                $suffix = '';
-               if ($addDomainName) {
+               if (self::$addDomainName) {
                        $domain = self::getDomainName($record['uid']);
                        $suffix = ($domain !== '' ? ' [' . $domain . ']' : '');
                }
                        $domain = self::getDomainName($record['uid']);
                        $suffix = ($domain !== '' ? ' [' . $domain . ']' : '');
                }
@@ -348,7 +380,7 @@ final class t3lib_tree_pagetree_Commands {
                        }
                }
 
                        }
                }
 
-               $prefix .= htmlspecialchars($addIdAsPrefix ? '[' . $record['uid'] . '] ' : '');
+               $prefix .= htmlspecialchars(self::$addIdAsPrefix ? '[' . $record['uid'] . '] ' : '');
                $subNode->setEditableText($text);
                $subNode->setText(
                        htmlspecialchars($visibleText),
                $subNode->setEditableText($text);
                $subNode->setText(
                        htmlspecialchars($visibleText),
index 0365b97..5e00da7 100644 (file)
@@ -69,6 +69,32 @@ class t3lib_tree_pagetree_Node extends t3lib_tree_extdirect_Node {
        protected $isMountPoint = FALSE;
 
        /**
        protected $isMountPoint = FALSE;
 
        /**
+        * Background color for the node
+        *
+        * @var string
+        */
+       protected $backgroundColor = '';
+
+       /**
+        * Sets the background color
+        *
+        * @param string $backgroundColor
+        * @return void
+        */
+       public function setBackgroundColor($backgroundColor) {
+               $this->backgroundColor = $backgroundColor;
+       }
+
+       /**
+        * Returns the background color
+        *
+        * @return string
+        */
+       public function getBackgroundColor() {
+               return $this->backgroundColor;
+       }
+
+       /**
         * Set's the original id of the element
         *
         * @param int $workspaceId
         * Set's the original id of the element
         *
         * @param int $workspaceId
@@ -327,6 +353,7 @@ class t3lib_tree_pagetree_Node extends t3lib_tree_extdirect_Node {
                $arrayRepresentation['nodeData']['mountPoint'] = $this->getMountPoint();
                $arrayRepresentation['nodeData']['workspaceId'] = $this->getWorkspaceId();
                $arrayRepresentation['nodeData']['isMountPoint'] = $this->isMountPoint();
                $arrayRepresentation['nodeData']['mountPoint'] = $this->getMountPoint();
                $arrayRepresentation['nodeData']['workspaceId'] = $this->getWorkspaceId();
                $arrayRepresentation['nodeData']['isMountPoint'] = $this->isMountPoint();
+               $arrayRepresentation['nodeData']['backgroundColor'] = htmlspecialchars($this->getBackgroundColor());
                $arrayRepresentation['nodeData']['serializeClassName'] = get_class($this);
 
                return $arrayRepresentation;
                $arrayRepresentation['nodeData']['serializeClassName'] = get_class($this);
 
                return $arrayRepresentation;
@@ -344,6 +371,7 @@ class t3lib_tree_pagetree_Node extends t3lib_tree_extdirect_Node {
                $this->setMountPoint($data['mountPoint']);
                $this->setReadableRootline($data['readableRootline']);
                $this->setIsMountPoint($data['isMountPoint']);
                $this->setMountPoint($data['mountPoint']);
                $this->setReadableRootline($data['readableRootline']);
                $this->setIsMountPoint($data['isMountPoint']);
+               $this->setBackgroundColor($data['backgroundColor']);
        }
 }
 
        }
 }