[!!!][TASK] Remove ExtJS Quicktips where possible
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Controller / ReviewController.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Workspaces\Service\WorkspaceService;
20
21 /**
22 * Review controller.
23 */
24 class ReviewController extends AbstractController {
25
26 /**
27 * Renders the review module user dependent with all workspaces.
28 * The module will show all records of one workspace.
29 *
30 * @return void
31 */
32 public function indexAction() {
33 $wsService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
34 $this->view->assign('showGrid', !($GLOBALS['BE_USER']->workspace === 0 && !$GLOBALS['BE_USER']->isAdmin()));
35 $this->view->assign('showAllWorkspaceTab', TRUE);
36 $this->view->assign('pageUid', GeneralUtility::_GP('id'));
37 if (GeneralUtility::_GP('id')) {
38 $pageRecord = BackendUtility::getRecord('pages', GeneralUtility::_GP('id'));
39 $this->view->assign('pageTitle', BackendUtility::getRecordTitle('pages', $pageRecord));
40 }
41 $this->view->assign('showLegend', !($GLOBALS['BE_USER']->workspace === 0 && !$GLOBALS['BE_USER']->isAdmin()));
42 $wsList = $wsService->getAvailableWorkspaces();
43 $activeWorkspace = $GLOBALS['BE_USER']->workspace;
44 $performWorkspaceSwitch = FALSE;
45 // Only admins see multiple tabs, we decided to use it this
46 // way for usability reasons. Regular users might be confused
47 // by switching workspaces with the tabs in a module.
48 if (!$GLOBALS['BE_USER']->isAdmin()) {
49 $wsCur = array($activeWorkspace => TRUE);
50 $wsList = array_intersect_key($wsList, $wsCur);
51 } else {
52 if ((string)GeneralUtility::_GP('workspace') !== '') {
53 $switchWs = (int)GeneralUtility::_GP('workspace');
54 if (in_array($switchWs, array_keys($wsList)) && $activeWorkspace != $switchWs) {
55 $activeWorkspace = $switchWs;
56 $GLOBALS['BE_USER']->setWorkspace($activeWorkspace);
57 $performWorkspaceSwitch = TRUE;
58 BackendUtility::setUpdateSignal('updatePageTree');
59 } elseif ($switchWs == WorkspaceService::SELECT_ALL_WORKSPACES) {
60 $this->redirect('fullIndex');
61 }
62 }
63 }
64 $this->pageRenderer->addInlineSetting('Workspaces', 'isLiveWorkspace', (int)$GLOBALS['BE_USER']->workspace === 0);
65 $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->prepareWorkspaceTabs($wsList, $activeWorkspace));
66 $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', $activeWorkspace);
67 $this->pageRenderer->addInlineSetting('FormEngine', 'moduleUrl', BackendUtility::getModuleUrl('record_edit'));
68 $this->view->assign('performWorkspaceSwitch', $performWorkspaceSwitch);
69 $this->view->assign('workspaceList', $wsList);
70 $this->view->assign('activeWorkspaceUid', $activeWorkspace);
71 $this->view->assign('activeWorkspaceTitle', WorkspaceService::getWorkspaceTitle($activeWorkspace));
72 $this->view->assign('showPreviewLink', $wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace));
73 $GLOBALS['BE_USER']->setAndSaveSessionData('tx_workspace_activeWorkspace', $activeWorkspace);
74 }
75
76 /**
77 * Renders the review module user dependent.
78 * The module will show all records of all workspaces.
79 *
80 * @return void
81 */
82 public function fullIndexAction() {
83 $wsService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
84 $wsList = $wsService->getAvailableWorkspaces();
85
86 if (!$GLOBALS['BE_USER']->isAdmin()) {
87 $activeWorkspace = $GLOBALS['BE_USER']->workspace;
88 $wsCur = array($activeWorkspace => TRUE);
89 $wsList = array_intersect_key($wsList, $wsCur);
90 }
91
92 $this->pageRenderer->addInlineSetting('Workspaces', 'workspaceTabs', $this->prepareWorkspaceTabs($wsList, WorkspaceService::SELECT_ALL_WORKSPACES));
93 $this->pageRenderer->addInlineSetting('Workspaces', 'activeWorkspaceId', WorkspaceService::SELECT_ALL_WORKSPACES);
94 $this->view->assign('pageUid', GeneralUtility::_GP('id'));
95 $this->view->assign('showGrid', TRUE);
96 $this->view->assign('showLegend', TRUE);
97 $this->view->assign('showAllWorkspaceTab', TRUE);
98 $this->view->assign('workspaceList', $wsList);
99 $this->view->assign('activeWorkspaceUid', WorkspaceService::SELECT_ALL_WORKSPACES);
100 $this->view->assign('showPreviewLink', FALSE);
101 $GLOBALS['BE_USER']->setAndSaveSessionData('tx_workspace_activeWorkspace', WorkspaceService::SELECT_ALL_WORKSPACES);
102 // set flag for javascript
103 $this->pageRenderer->addInlineSetting('Workspaces', 'allView', '1');
104 }
105
106 /**
107 * Renders the review module for a single page. This is used within the
108 * workspace-preview frame.
109 *
110 * @return void
111 */
112 public function singleIndexAction() {
113 $wsService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
114 $wsList = $wsService->getAvailableWorkspaces();
115 $activeWorkspace = $GLOBALS['BE_USER']->workspace;
116 $wsCur = array($activeWorkspace => TRUE);
117 $wsList = array_intersect_key($wsList, $wsCur);
118 $this->view->assign('pageUid', GeneralUtility::_GP('id'));
119 $this->view->assign('showGrid', TRUE);
120 $this->view->assign('showAllWorkspaceTab', FALSE);
121 $this->view->assign('workspaceList', $wsList);
122 $this->view->assign('backendDomain', GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'));
123 $this->pageRenderer->addInlineSetting('Workspaces', 'singleView', '1');
124 }
125
126 /**
127 * Initializes the controller before invoking an action method.
128 *
129 * @return void
130 */
131 protected function initializeAction() {
132 parent::initializeAction();
133 $this->template->setExtDirectStateProvider();
134 if (WorkspaceService::isOldStyleWorkspaceUsed()) {
135 $flashMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:warning.oldStyleWorkspaceInUser'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
136 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
137 $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
138 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
139 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
140 $defaultFlashMessageQueue->enqueue($flashMessage);
141 }
142 $this->pageRenderer->loadExtJS();
143 $states = $GLOBALS['BE_USER']->uc['moduleData']['Workspaces']['States'];
144 $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
145 // Load JavaScript:
146 $this->pageRenderer->addExtDirectCode(array(
147 'TYPO3.Workspaces'
148 ));
149 $this->pageRenderer->addJsFile($this->backPath . 'sysext/backend/Resources/Public/JavaScript/extjs/ux/Ext.grid.RowExpander.js');
150 $this->pageRenderer->addJsFile($this->backPath . 'sysext/backend/Resources/Public/JavaScript/extjs/ux/Ext.app.SearchField.js');
151 $this->pageRenderer->addJsFile($this->backPath . 'sysext/backend/Resources/Public/JavaScript/extjs/ux/Ext.ux.FitToParent.js');
152 $resourcePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/JavaScript/';
153
154 // @todo Integrate additional stylesheet resources
155 $this->pageRenderer->addCssFile($resourcePath . 'gridfilters/css/GridFilters.css');
156 $this->pageRenderer->addCssFile($resourcePath . 'gridfilters/css/RangeMenu.css');
157
158 $filters = array(
159 $resourcePath . 'gridfilters/menu/RangeMenu.js',
160 $resourcePath . 'gridfilters/menu/ListMenu.js',
161 $resourcePath . 'gridfilters/GridFilters.js',
162 $resourcePath . 'gridfilters/filter/Filter.js',
163 $resourcePath . 'gridfilters/filter/StringFilter.js',
164 $resourcePath . 'gridfilters/filter/DateFilter.js',
165 $resourcePath . 'gridfilters/filter/ListFilter.js',
166 $resourcePath . 'gridfilters/filter/NumericFilter.js',
167 $resourcePath . 'gridfilters/filter/BooleanFilter.js',
168 $resourcePath . 'gridfilters/filter/BooleanFilter.js',
169 );
170
171 $custom = $this->getAdditionalResourceService()->getJavaScriptResources();
172
173 $resources = array(
174 $resourcePath . 'Component/RowDetailTemplate.js',
175 $resourcePath . 'Component/RowExpander.js',
176 $resourcePath . 'Component/TabPanel.js',
177 $resourcePath . 'Store/mainstore.js',
178 $resourcePath . 'configuration.js',
179 $resourcePath . 'helpers.js',
180 $resourcePath . 'actions.js',
181 $resourcePath . 'component.js',
182 $resourcePath . 'toolbar.js',
183 $resourcePath . 'grid.js',
184 $resourcePath . 'workspaces.js'
185 );
186
187 $javaScriptFiles = array_merge($filters, $custom, $resources);
188
189 foreach ($javaScriptFiles as $javaScriptFile) {
190 $this->pageRenderer->addJsFile($javaScriptFile);
191 }
192 foreach ($this->getAdditionalResourceService()->getLocalizationResources() as $localizationResource) {
193 $this->pageRenderer->addInlineLanguageLabelFile($localizationResource);
194 }
195 $this->pageRenderer->addInlineSetting('RecordHistory', 'moduleUrl', BackendUtility::getModuleUrl('record_history'));
196 }
197
198 /**
199 * Prepares available workspace tabs.
200 *
201 * @param array $workspaceList
202 * @param int $activeWorkspace
203 * @return array
204 */
205 protected function prepareWorkspaceTabs(array $workspaceList, $activeWorkspace) {
206 $tabs = array();
207
208 if ($activeWorkspace !== WorkspaceService::SELECT_ALL_WORKSPACES) {
209 $tabs[] = array(
210 'title' => $workspaceList[$activeWorkspace],
211 'itemId' => 'workspace-' . $activeWorkspace,
212 'workspaceId' => $activeWorkspace,
213 'triggerUrl' => $this->getModuleUri($activeWorkspace),
214 );
215 }
216
217 $tabs[] = array(
218 'title' => 'All workspaces',
219 'itemId' => 'workspace-' . WorkspaceService::SELECT_ALL_WORKSPACES,
220 'workspaceId' => WorkspaceService::SELECT_ALL_WORKSPACES,
221 'triggerUrl' => $this->getModuleUri(WorkspaceService::SELECT_ALL_WORKSPACES),
222 );
223
224 foreach ($workspaceList as $workspaceId => $workspaceTitle) {
225 if ($workspaceId === $activeWorkspace) {
226 continue;
227 }
228 $tabs[] = array(
229 'title' => $workspaceTitle,
230 'itemId' => 'workspace-' . $workspaceId,
231 'workspaceId' => $workspaceId,
232 'triggerUrl' => $this->getModuleUri($workspaceId),
233 );
234 }
235
236 return $tabs;
237 }
238
239 /**
240 * Gets the module URI.
241 *
242 * @param int $workspaceId
243 * @return string
244 */
245 protected function getModuleUri($workspaceId) {
246 $parameters = array(
247 'id' => (int)$this->pageId,
248 'workspace' => (int)$workspaceId,
249 );
250 // The "all workspaces" tab is handled in fullIndexAction
251 // which is required as additional GET parameter in the URI then
252 if ($workspaceId === WorkspaceService::SELECT_ALL_WORKSPACES) {
253 $this->uriBuilder->reset()->uriFor('fullIndex');
254 $parameters = array_merge($parameters, $this->uriBuilder->getArguments());
255 }
256 return BackendUtility::getModuleUrl('web_WorkspacesWorkspaces', $parameters);
257 }
258
259 }