Added feature #9591: Integrate sys_actions into toolbar
authorIngo Renner <ingo.renner@typo3.org>
Wed, 29 Oct 2008 17:46:29 +0000 (17:46 +0000)
committerIngo Renner <ingo.renner@typo3.org>
Wed, 29 Oct 2008 17:46:29 +0000 (17:46 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@4383 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/sys_action/ext_tables.php
typo3/sysext/sys_action/toolbarmenu/class.tx_sysaction_toolbarmenu.php [new file with mode: 0644]
typo3/sysext/sys_action/toolbarmenu/registerToolbarItem.php [new file with mode: 0644]
typo3/sysext/sys_action/toolbarmenu/tx_sysactions.css [new file with mode: 0644]
typo3/sysext/sys_action/toolbarmenu/tx_sysactions.js [new file with mode: 0644]

index c7869be..764875a 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-10-29  Ingo Renner  <ingo@typo3.org>
+
+       * Added feature #9591: Integrate sys_actions into toolbar
+
 2008-10-28  Ingo Renner  <ingo@typo3.org>
 
        * Added the manual for the OpenID system extension
index b1e9766..3541ed0 100755 (executable)
@@ -14,7 +14,7 @@ if (TYPO3_MODE=='BE') {
                        'label' => 'title',
                        'tstamp' => 'tstamp',
                        'default_sortby' => 'ORDER BY title',
-                       "sortby" => "sorting",  
+                       'sortby' => 'sorting',
                        'prependAtCopy' => 'LLL:EXT:lang/locallang_general.php:LGL.prependAtCopy',
                        'title' => 'LLL:EXT:sys_action/locallang_tca.php:sys_action',
                        'crdate' => 'crdate',
@@ -30,6 +30,8 @@ if (TYPO3_MODE=='BE') {
                        'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY).'tca.php'
                )
        );
+
+       $GLOBALS['TYPO3_CONF_VARS']['typo3/backend.php']['additionalBackendItems'][] = t3lib_extMgm::extPath('sys_action') . 'toolbarmenu/registerToolbarItem.php';
 }
 
 t3lib_extMgm::addLLrefForTCAdescr('sys_action','EXT:sys_action/locallang_csh_sysaction.xml');
diff --git a/typo3/sysext/sys_action/toolbarmenu/class.tx_sysaction_toolbarmenu.php b/typo3/sysext/sys_action/toolbarmenu/class.tx_sysaction_toolbarmenu.php
new file mode 100644 (file)
index 0000000..fb5475d
--- /dev/null
@@ -0,0 +1,205 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2008 Steffen Kamper <info@sk-typo3.de>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+require_once(PATH_typo3 . 'interfaces/interface.backend_toolbaritem.php');
+
+/**
+ * Adds action links to the backend's toolbar
+ *
+ * @author     Steffen Kamper <info@sk-typo3.de>
+ * @package TYPO3
+ * @subpackage tx_sysaction
+ */
+class tx_sysactionToolbarMenu implements backend_toolbarItem {
+
+       /**
+        * reference back to the backend object
+        *
+        * @var TYPO3backend
+        */
+       protected $backendReference;
+       protected $EXTKEY = 'sys_action';
+
+       /**
+        * constructor
+        *
+        * @return      void
+        */
+       public function __construct(TYPO3backend &$backendReference = null) {
+               $this->backendReference = $backendReference;
+       }
+
+       /**
+        * sets the backend reference
+        *
+        * @param       TYPO3backend    backend object reference
+        * @return      void
+        */
+       public function setBackend(TYPO3backend &$backendReference) {
+               $this->backendReference = $backendReference;
+       }
+
+       /**
+        * renders the toolbar menu
+        *
+        * @return      string  the rendered backend menu
+        * @author      Ingo Renner <ingo@typo3.org>
+        */
+       public function render() {
+               $actionMenu    = array();
+               $actionEntries = $this->getActionEntries();
+
+               if ($actionEntries) {
+                       $this->addJavascriptToBackend();
+                       $this->addCssToBackend();
+
+                       $actionMenu[] = '<a href="#" class="toolbar-item"><img' .
+                               t3lib_iconWorks::skinImg(
+                                       $this->backPath,
+                                       t3lib_extMgm::extRelPath($this->EXTKEY) . 'ext_icon.gif',
+                                       'width="16" height="16"'
+                               ) . ' title="System Actions" alt="" /></a>';
+
+                       $actionMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
+                       foreach ($actionEntries as $linkConf) {
+                               $actionMenu[] = '<li><a href="' . $linkConf[1] .
+                                       '" target="content">' . $linkConf[2] .
+                                       htmlspecialchars($linkConf[0]) . '</a></li>';
+                       }
+
+                       $actionMenu[] = '</ul>';
+               }
+
+               return implode("\n", $actionMenu);
+       }
+
+       /**
+        * gets the entries for the action menu
+        *
+        * @return      array   array of action menu entries
+        * @author      Steffen Kamper <info@sk-typo3.de>
+        * @author      Ingo Renner <ingo@typo3.org>
+        */
+       protected function getActionEntries() {
+               $actions = array();
+
+               if ($GLOBALS['BE_USER']->isAdmin()) {
+                       $queryResource = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
+                               '*',
+                               'sys_action',
+                               'sys_action.pid = 0',
+                               '',
+                               'sys_action.sorting'
+                       );
+               } else {
+                       $groupList = 0;
+                       if ($GLOBALS['BE_USER']->groupList) {
+                               $groupList = $GLOBALS['BE_USER']->groupList;
+                       }
+
+                       $queryResource = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
+                               'sys_action.*',
+                               'sys_action',
+                               'sys_action_asgr_mm',
+                               'be_groups',
+                               ' AND be_groups.uid IN (' . $groupList .
+                                       ') AND sys_action.pid = 0 AND sys_action.hidden = 0',
+                               'sys_action.uid',
+                               'sys_action.sorting'
+                       );
+               }
+
+               if ($queryResource) {
+                       while ($actionRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($queryResource)) {
+                               $actions[] = array(
+                                       $actionRow['title'],
+                                       'sysext/taskcenter/task/index.php?SET[function]=tx_sysaction&sys_action_uid=' . $actionRow['uid'],
+                                       t3lib_iconworks::getIconImage(
+                                               'sys_action',
+                                               $actionRow,
+                                               $GLOBALS['BACK_PATH'],
+                                               'hspace="2" class="absmiddle"'
+                                       ),
+                               );
+                       }
+
+                       $GLOBALS['TYPO3_DB']->sql_free_result($queryResource);
+               }
+
+               return $actions;
+       }
+
+       /**
+        * returns additional attributes for the list item in the toolbar
+        *
+        * @return      string  list item HTML attibutes
+        */
+       public function getAdditionalAttributes() {
+               return ' id="tx-sys-action-menu"';
+       }
+
+       /**
+        * adds the neccessary javascript ot the backend
+        *
+        * @return      void
+        */
+       protected function addJavascriptToBackend() {
+               $this->backendReference->addJavascriptFile(
+                       t3lib_extMgm::extRelPath($this->EXTKEY) . 'toolbarmenu/tx_sysactions.js'
+               );
+       }
+
+       /**
+        * adds the neccessary css ot the backend
+        *
+        * @return      void
+        */
+       protected function addCssToBackend() {
+               $this->backendReference->addCssFile(
+                       'sysaction',
+                       t3lib_extMgm::extRelPath($this->EXTKEY) .
+                               'toolbarmenu/tx_sysactions.css'
+               );
+       }
+
+       /**
+        * Checks if user has access to the sys action menu
+        *
+        * @return      boolean true if the user has access, false otherwise
+        */
+       public function checkAccess() {
+                       // taskcenter is enabled for everybody
+               return true;
+       }
+}
+
+
+if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sys_action/toolbarmenu/class.tx_sysaction_toolbarmenu.php']) {
+       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sys_action/toolbarmenu/class.tx_sysaction_toolbarmenu.php']);
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/sys_action/toolbarmenu/registerToolbarItem.php b/typo3/sysext/sys_action/toolbarmenu/registerToolbarItem.php
new file mode 100644 (file)
index 0000000..6e1aa8c
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+if (!defined('TYPO3_MODE')) {
+       die ('Access denied.');
+}
+
+if (TYPO3_MODE == 'BE') {
+               // first include the class file
+       include_once(t3lib_extMgm::extPath('sys_action')
+               . 'toolbarmenu/class.tx_sysaction_toolbarmenu.php');
+
+               // now register the class as toolbar item
+       $GLOBALS['TYPO3backend']->addToolbarItem(
+               'sys_action',
+               'tx_sysactionToolbarMenu'
+       );
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/sys_action/toolbarmenu/tx_sysactions.css b/typo3/sysext/sys_action/toolbarmenu/tx_sysactions.css
new file mode 100644 (file)
index 0000000..c6b0a18
--- /dev/null
@@ -0,0 +1,37 @@
+#tx-sys-action-menu {
+       width: 30px;
+}
+
+#tx-sys-action-menu ul {
+       position: absolute;
+       list-style: none;
+       padding: 2px 0px 0px;
+       margin: 0px;
+       background-color: #f9f9f9;
+       border: 1px solid #abb2bc;
+       border-top: none;
+       width: 180px;
+}
+
+#tx-sys-action-menu li {
+       padding-top: 2px;
+       text-align: left;
+       float: none;
+       vertical-align: middle;
+       min-height: 19px;
+}
+
+#tx-sys-action-menu li img {
+       float: left;
+       padding-right: 3px;
+}
+
+#tx-sys-action-menu li a {
+       text-decoration: none;
+       line-height: 12px;
+       vertical-align: middle;
+       display: block;
+       padding-bottom: 2px;
+       padding-left: 3px;
+       font-size: 11px;
+}
\ No newline at end of file
diff --git a/typo3/sysext/sys_action/toolbarmenu/tx_sysactions.js b/typo3/sysext/sys_action/toolbarmenu/tx_sysactions.js
new file mode 100644 (file)
index 0000000..9ef8bd1
--- /dev/null
@@ -0,0 +1,100 @@
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2008 Steffen Kamper <info@sk-typo3.de>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * class to handle the dev links menu
+ *
+ * $Id$
+ */
+var SysActionMenu = Class.create({
+
+       /**
+        * registers for resize event listener and executes on DOM ready
+        */
+       initialize: function() {
+               Event.observe(window, 'resize', this.positionMenu);
+
+               Event.observe(window, 'load', function(){
+                       this.positionMenu();
+                       this.toolbarItemIcon = $$('#tx-sys-action-menu .toolbar-item img')[0].src;
+
+                       Event.observe('tx-sys-action-menu', 'click', this.toggleMenu);
+
+               }.bindAsEventListener(this));
+       },
+
+       /**
+        * positions the menu below the toolbar icon, let's do some math!
+        */
+       positionMenu: function() {
+               var calculatedOffset = 0;
+               var parentWidth      = $('tx-sys-action-menu').getWidth();
+               var ownWidth         = $$('#tx-sys-action-menu ul')[0].getWidth();
+               var parentSiblings   = $('tx-sys-action-menu').previousSiblings();
+
+               parentSiblings.each(function(toolbarItem) {
+                       calculatedOffset += toolbarItem.getWidth() - 1;
+                       // -1 to compensate for the margin-right -1px of the list items,
+                       // which itself is necessary for overlaying the separator with the active state background
+
+                       if(toolbarItem.down().hasClassName('no-separator')) {
+                               calculatedOffset -= 1;
+                       }
+               });
+               calculatedOffset = calculatedOffset - ownWidth + parentWidth;
+
+
+               $$('#tx-sys-action-menu ul')[0].setStyle({
+                       left: calculatedOffset + 'px'
+               });
+       },
+
+       /**
+        * toggles the visibility of the menu and places it under the toolbar icon
+        */
+       toggleMenu: function(event) {
+               var toolbarItem = $$('#tx-sys-action-menu > a')[0];
+               var menu        = $$('#tx-sys-action-menu .toolbar-item-menu')[0];
+               toolbarItem.blur();
+
+               if(!toolbarItem.hasClassName('toolbar-item-active')) {
+                       toolbarItem.addClassName('toolbar-item-active');
+                       Effect.Appear(menu, {duration: 0.2});
+                       TYPO3BackendToolbarManager.hideOthers(toolbarItem);
+               } else {
+                       toolbarItem.removeClassName('toolbar-item-active');
+                       Effect.Fade(menu, {duration: 0.1});
+               }
+
+               if(event && (Event.element(event).hasClassName('toolbar-item') || Event.element(event).up().hasClassName('toolbar-item'))) {
+                       Event.stop(event);
+               }
+       }
+
+});
+
+var TYPO3BackendSysactionMenu = new SysActionMenu();
+