2 /***************************************************************
5 * (c) 2007-2011 Ingo Renner <ingo@typo3.org>
6 * (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
29 if(TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
) {
30 require_once(PATH_typo3
. 'interfaces/interface.backend_toolbaritem.php');
34 * class to render the workspace selector
36 * @author Ingo Renner <ingo@typo3.org>
38 * @subpackage BackendUserInterface
40 class WorkspaceSelectorToolbarItem
implements backend_toolbarItem
{
42 protected $changeWorkspace;
43 protected $changeWorkspacePreview;
46 * reference back to the backend object
50 protected $backendReference;
52 protected $checkAccess = NULL;
57 * @param TYPO3backend TYPO3 backend object reference
59 public function __construct(TYPO3backend
&$backendReference = null) {
60 $this->backendReference
= $backendReference;
61 $this->changeWorkspace
= t3lib_div
::_GP('changeWorkspace');
62 $this->changeWorkspacePreview
= t3lib_div
::_GP('changeWorkspacePreview');
64 $pageRenderer = t3lib_div
::makeInstance('t3lib_pageRenderer');
65 $this->backendReference
->addJavaScript("TYPO3.Workspaces = { workspaceTitle : '" . htmlspecialchars(tx_Workspaces_Service_Workspaces
::getWorkspaceTitle($GLOBALS['BE_USER']->workspace
)) . "'};\n");
69 * checks whether the user has access to this toolbar item
71 * @see typo3/alt_shortcut.php
72 * @return boolean true if user has access, false if not
74 public function checkAccess() {
75 if (t3lib_extMgm
::isLoaded('workspaces')) {
76 if ($this->checkAccess
== NULL) {
77 $availableWorkspaces = tx_Workspaces_Service_Workspaces
::getAvailableWorkspaces();
78 if (count($availableWorkspaces) > 0) {
79 $this->checkAccess
= TRUE;
81 $this->checkAccess
= FALSE;
84 return $this->checkAccess
;
90 * Creates the selector for workspaces
92 * @return string workspace selector as HTML select
94 public function render() {
95 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.workspace', true);
96 $this->addJavascriptToBackend();
97 $availableWorkspaces = tx_Workspaces_Service_Workspaces
::getAvailableWorkspaces();
98 $workspaceMenu = array();
100 $stateCheckedIcon = t3lib_iconWorks
::getSpriteIcon('status-status-checked');
102 $stateUncheckedIcon = t3lib_iconWorks
::getSpriteIcon('empty-empty', array(
103 'title' => $GLOBALS['LANG']->getLL('bookmark_inactive')
106 $workspaceMenu[] = '<a href="#" class="toolbar-item">' .
107 t3lib_iconWorks
::getSpriteIcon('apps-toolbar-menu-workspace', array('title' => $title)) .
109 $workspaceMenu[] = '<ul class="toolbar-item-menu" style="display: none;">';
111 if (count($availableWorkspaces)) {
112 foreach($availableWorkspaces as $workspaceId => $label) {
114 $icon = $stateUncheckedIcon;
115 if((int) $GLOBALS['BE_USER']->workspace
=== $workspaceId) {
116 $selected = ' class="selected"';
117 $icon = $stateCheckedIcon;
120 $workspaceMenu[] = '<li' . $selected . '>' . $icon .
121 ' <a href="backend.php?changeWorkspace=' .
122 intval($workspaceId) . '" id="ws-' . intval($workspaceId) .
123 '" class="ws">' . $label . '</a></li>';
126 $workspaceMenu[] = '<li>' . $stateUncheckedIcon . ' ' .
127 $GLOBALS['LANG']->getLL('bookmark_noWSfound', true) .
131 if ($GLOBALS['BE_USER']->check('modules', 'web_WorkspacesWorkspaces')) {
132 // go to workspace module link
133 $workspaceMenu[] = '<li class="divider">' . $stateUncheckedIcon . ' ' .
134 '<a href="javascript:top.goToModule(\'web_WorkspacesWorkspaces\');" target="content" id="goToWsModule">' .
135 ' '. $GLOBALS['LANG']->getLL('bookmark_workspace', true) . '</a></li>';
138 $workspaceMenu[] = '</ul>';
140 return implode(LF
, $workspaceMenu);
144 * adds the necessary JavaScript to the backend
148 protected function addJavascriptToBackend() {
149 $this->backendReference
->addJavascriptFile(t3lib_extMgm
::extRelPath('workspaces') . 'Resources/Public/JavaScript/workspacemenu.js');
153 * returns additional attributes for the list item in the toolbar
155 * @return string list item HTML attibutes
157 public function getAdditionalAttributes() {
158 return ' id="workspace-selector-menu"';
163 if(!(TYPO3_REQUESTTYPE
& TYPO3_REQUESTTYPE_AJAX
)) {
164 $GLOBALS['TYPO3backend']->addToolbarItem('workSpaceSelector', 'WorkspaceSelectorToolbarItem');
168 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['ext/workspaces/Classes/BackendUserInterface/WorkspaceSelectorToolbarItem.php'])) {
169 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['ext/workspaces/Classes/BackendUserInterface/WorkspaceSelectorToolbarItem.php']);