[FEATURE] Introduce stage change buttons in frontent preview
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Controller / PreviewController.php
index c304ca3..90e6d6a 100644 (file)
 class Tx_Workspaces_Controller_PreviewController extends Tx_Workspaces_Controller_AbstractController {
 
        /**
+        * @var Tx_Workspaces_Service_Stages
+        */
+       protected $stageService;
+
+       /**
+        * @var tx_Workspaces_Service_Workspaces
+        */
+       protected $workspaceService;
+
+       /**
         * Initializes the controller before invoking an action method.
         *
         * @return void
         */
        protected function initializeAction() {
                parent::initializeAction();
-
+               $this->stageService = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
+               $this->workspaceService = t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
                $this->template->setExtDirectStateProvider();
 
-               $resourcePath = t3lib_extMgm::extRelPath('workspaces') . 'Resources/Public/';
-               $GLOBALS['TBE_STYLES']['extJS']['theme'] = $resourcePath . 'StyleSheet/preview.css';
+               $resourcePath = t3lib_extMgm::extRelPath('workspaces') . 'Resources/Public/StyleSheet/preview.css';
+               $GLOBALS['TBE_STYLES']['extJS']['theme'] = $resourcePath;
+
                $this->pageRenderer->loadExtJS();
                $this->pageRenderer->enableExtJSQuickTips();
 
-
                        // Load  JavaScript:
                $this->pageRenderer->addExtDirectCode(array(
                        'TYPO3.Workspaces',
@@ -59,11 +70,25 @@ class Tx_Workspaces_Controller_PreviewController extends Tx_Workspaces_Controlle
                $states = $GLOBALS['BE_USER']->uc['moduleData']['Workspaces']['States'];
                $this->pageRenderer->addInlineSetting('Workspaces', 'States', $states);
 
+               $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/notifications.js');
+
                $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/ux/flashmessages.js');
                $this->pageRenderer->addJsFile($this->backPath . 'js/extjs/iframepanel.js');
 
-               $this->pageRenderer->addJsFile($resourcePath . 'JavaScript/Ext.ux.plugins.TabStripContainer.js');
-               $this->pageRenderer->addJsFile($resourcePath . 'JavaScript/preview.js');
+               $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/notifications.js');
+
+               $resourcePathJavaScript = t3lib_extMgm::extRelPath('workspaces') . 'Resources/Public/JavaScript/';
+
+               $jsFiles = array(
+                       'Ext.ux.plugins.TabStripContainer.js',
+                       'Store/mainstore.js',
+                       'helpers.js',
+                       'actions.js',
+               );
+
+               foreach ($jsFiles as $jsFile) {
+                       $this->pageRenderer->addJsFile($resourcePathJavaScript . $jsFile);
+               }
 
                        // todo this part should be done with inlineLocallanglabels
                $this->pageRenderer->addJsInlineCode('workspace-inline-code', $this->generateJavascript());
@@ -74,14 +99,33 @@ class Tx_Workspaces_Controller_PreviewController extends Tx_Workspaces_Controlle
         * The preview itself consists of three frames, so there are
         * only the frames-urls we've to generate here
         *
+        * @param integer $previewWS
+        *
         * @return void
         */
-       public function indexAction() {
+       public function indexAction($previewWS = NULL) {
                // @todo language doesn't always come throught the L parameter
                // @todo Evaluate how the intval() call can be used with Extbase validators/filters
                $language = intval(t3lib_div::_GP('L'));
 
-               $controller = t3lib_div::makeInstance('Tx_Workspaces_Controller_ReviewController', TRUE);
+                       // fetch the next and previous stage
+               $workspaceItemsArray = $this->workspaceService->selectVersionsInWorkspace($this->stageService->getWorkspaceId(), $filter = 1, $stage = -99, $this->pageId, $recursionLevel = 0, $selectionType = 'tables_modify');
+               list(, $nextStage) = $this->stageService->getNextStageForElementCollection($workspaceItemsArray);
+               list(, $previousStage) = $this->stageService->getPreviousStageForElementCollection($workspaceItemsArray);
+
+               /** @var $wsService tx_Workspaces_Service_Workspaces */
+               $wsService = t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
+               $wsList = $wsService->getAvailableWorkspaces();
+               $activeWorkspace = $GLOBALS['BE_USER']->workspace;
+
+               if (!is_null($previewWS)) {
+                       if (in_array($previewWS, array_keys($wsList)) && $activeWorkspace != $previewWS) {
+                               $activeWorkspace = $previewWS;
+                               $GLOBALS['BE_USER']->setWorkspace($activeWorkspace);
+                               t3lib_BEfunc::setUpdateSignal('updatePageTree');
+                       }
+               }
+
                /** @var $uriBuilder Tx_Extbase_MVC_Web_Routing_UriBuilder */
                $uriBuilder = $this->objectManager->create('Tx_Extbase_MVC_Web_Routing_UriBuilder');
 
@@ -105,18 +149,51 @@ class Tx_Workspaces_Controller_PreviewController extends Tx_Workspaces_Controlle
                $this->view->assign('wsUrl', $wsBaseUrl . '&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS=' . $GLOBALS['BE_USER']->workspace);
                $this->view->assign('wsSettingsUrl', $wsSettingsUrl);
                $this->view->assign('backendDomain', t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'));
+
+               $splitPreviewTsConfig = t3lib_BEfunc::getModTSconfig($this->pageId, 'workspaces.splitPreviewModes');
+               $splitPreviewModes = t3lib_div::trimExplode(',', $splitPreviewTsConfig['value']);
+               $allPreviewModes = array('slider', 'vbox', 'hbox');
+               if (!array_intersect($splitPreviewModes, $allPreviewModes)) {
+                       $splitPreviewModes = $allPreviewModes;
+               }
+               $this->pageRenderer->addInlineSetting('Workspaces', 'SplitPreviewModes', $splitPreviewModes);
+
                $GLOBALS['BE_USER']->setAndSaveSessionData('workspaces.backend_domain', t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'));
-               $this->pageRenderer->addJsInlineCode("workspaces.preview.lll" , "TYPO3.LLL.Workspaces = {
-                       visualPreview: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.visualPreview', true) . "',
-                       listView: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.listView', true) . "',
-                       livePreview: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.livePreview', true) . "',
-                       livePreviewDetail: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.livePreviewDetail', true) . "',
-                       workspacePreview: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.workspacePreview', true) . "',
-                       workspacePreviewDetail: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.workspacePreviewDetail', true) . "',
-                       modeSlider: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeSlider', true) . "',
-                       modeVbox: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeVbox', true) . "',
-                       modeHbox: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeHbox', true) . "'
+
+               $this->pageRenderer->addInlineSetting('Workspaces', 'disableNextStageButton', $this->isInvalidStage($nextStage));
+               $this->pageRenderer->addInlineSetting('Workspaces', 'disablePreviousStageButton', $this->isInvalidStage($previousStage));
+               $this->pageRenderer->addInlineSetting('Workspaces', 'disableDiscardStageButton', $this->isInvalidStage($nextStage) && $this->isInvalidStage($previousStage));
+
+               $this->pageRenderer->addJsInlineCode("workspaces.preview.lll", "
+               TYPO3.LLL.Workspaces = {
+                       visualPreview: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.visualPreview', TRUE) . "',
+                       listView: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.listView', TRUE) . "',
+                       livePreview: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.livePreview', TRUE) . "',
+                       livePreviewDetail: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.livePreviewDetail', TRUE) . "',
+                       workspacePreview: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.workspacePreview', TRUE) . "',
+                       workspacePreviewDetail: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.workspacePreviewDetail', TRUE) . "',
+                       modeSlider: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeSlider', TRUE) . "',
+                       modeVbox: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeVbox', TRUE) . "',
+                       modeHbox: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:preview.modeHbox', TRUE) . "',
+                       discard: '" . $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xml:label_doaction_discard', TRUE) . "',
+                       nextStage: '" . $nextStage['title'] . "',
+                       previousStage: '" . $previousStage['title'] . "'
                };\n");
+
+               $resourcePath = t3lib_extMgm::extRelPath('workspaces') . 'Resources/Public/';
+               $this->pageRenderer->addJsFile($resourcePath . 'JavaScript/preview.js');
+       }
+
+       /**
+        * Evaluate the activate state based on given $stageArray.
+        *
+        * @param array $stageArray
+        * @return boolean
+        *
+        * @author Michael Klapper <development@morphodo.com>
+        */
+       protected function isInvalidStage($stageArray) {
+               return !(is_array($stageArray) && count($stageArray) > 0);
        }
 
        /**