[TASK] Add action selector in toolbar in workspaces menu 73/31273/2
authorOliver Hader <oliver@typo3.org>
Thu, 26 Jun 2014 09:42:45 +0000 (11:42 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 1 Jul 2014 19:39:22 +0000 (21:39 +0200)
Currently there are two selectors in the bottom toolbar of
the workspace module. One to handle stage changes on selected
elements and one for mass actions (publish, swap, discard) for
the whole workspace. To circumvent this, an additional selector
shall be added for record selections.

Resolves: #59898
Releases: 6.2, 6.3
Change-Id: I5991cc16a65ba5ac473ec380f534379ec925cad3
Reviewed-on: https://review.typo3.org/31273
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/workspaces/Classes/ExtDirect/ActionHandler.php
typo3/sysext/workspaces/Resources/Private/Language/locallang.xlf
typo3/sysext/workspaces/Resources/Public/JavaScript/grid.js
typo3/sysext/workspaces/Resources/Public/JavaScript/toolbar.js

index a52365e..bf6d85e 100644 (file)
@@ -101,6 +101,68 @@ class ActionHandler extends \TYPO3\CMS\Workspaces\ExtDirect\AbstractHandler {
        }
 
        /**
+        * Executes an action (publish, discard, swap) to a selection set.
+        *
+        * @param \stdClass $parameter
+        * @return array
+        */
+       public function executeSelectionAction($parameter) {
+               $result = array();
+
+               if (empty($parameter->action) || empty($parameter->selection)) {
+                       $result['error'] = 'No action or record selection given';
+                       return $result;
+               }
+
+               $commands = array();
+               $swapIntoWorkspace = ($parameter->action === 'swap');
+               if ($parameter->action === 'publish' || $swapIntoWorkspace) {
+                       $commands = $this->getPublishSwapCommands($parameter->selection, $swapIntoWorkspace);
+               } elseif ($parameter->action === 'discard') {
+                       $commands = $this->getFlushCommands($parameter->selection);
+               }
+
+               $result = $this->processTcaCmd($commands);
+               $result['total'] = count($commands);
+               return $result;
+       }
+
+       /**
+        * Get publish swap commands
+        *
+        * @param array|\stdClass[] $selection
+        * @param boolean $swapIntoWorkspace
+        * @return array
+        */
+       protected function getPublishSwapCommands(array $selection, $swapIntoWorkspace) {
+               $commands = array();
+               foreach ($selection as $record) {
+                       $commands[$record->table][$record->liveId]['version'] = array(
+                               'action' => 'swap',
+                               'swapWith' => $record->versionId,
+                               'swapIntoWS' => (bool)$swapIntoWorkspace,
+                       );
+               }
+               return $commands;
+       }
+
+       /**
+        * Get flush commands
+        *
+        * @param array|\stdClass[] $selection
+        * @return array
+        */
+       protected function getFlushCommands(array $selection) {
+               $commands = array();
+               foreach ($selection as $record) {
+                       $commands[$record->table][$record->versionId]['version'] = array(
+                               'action' => 'clearWSID',
+                       );
+               }
+               return $commands;
+       }
+
+       /**
         * Saves the selected columns to be shown to the preferences of the current backend user.
         *
         * @param object $model
@@ -369,13 +431,27 @@ class ActionHandler extends \TYPO3\CMS\Workspaces\ExtDirect\AbstractHandler {
         * Process TCA command map array.
         *
         * @param array $cmdMapArray
-        * @return void
+        * @return array
         * @author Michael Klapper <development@morphodo.com>
         */
        protected function processTcaCmd(array $cmdMapArray) {
-               $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
-               $tce->start(array(), $cmdMapArray);
-               $tce->process_cmdmap();
+               $result = array();
+
+               if (empty($cmdMapArray)) {
+                       $result['error'] = 'No commands given to be processed';
+                       return $result;
+               }
+
+               /** @var \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler */
+               $dataHandler = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
+               $dataHandler->start(array(), $cmdMapArray);
+               $dataHandler->process_cmdmap();
+
+               if ($dataHandler->errorLog) {
+                       $result['error'] = implode('<br/>', $dataHandler->errorLog);
+               }
+
+               return $result;
        }
 
        /**
index 48f3fd8..141c314 100644 (file)
                        <trans-unit id="tooltip.discardAll" xml:space="preserve">
                                <source>Do you really want to discard changes from the whole workspace?</source>
                        </trans-unit>
+                       <trans-unit id="tooltip.publishSelected" xml:space="preserve">
+                               <source>Really publish selected elements?</source>
+                       </trans-unit>
+                       <trans-unit id="tooltip.swapSelected" xml:space="preserve">
+                               <source>Really swap selected elements?</source>
+                       </trans-unit>
+                       <trans-unit id="tooltip.discardSelected" xml:space="preserve">
+                               <source>Really discard changes of the selected elements?</source>
+                       </trans-unit>
                        <trans-unit id="tooltip.affectWholeWorkspace" xml:space="preserve">
                                <source>Please note that this will affect all changes in the current workspace, which may be more than
                                        you are currently seeing on your screen.
                        <trans-unit id="window.massAction.title" xml:space="preserve">
                                <source>Prepare to start mass action</source>
                        </trans-unit>
+                       <trans-unit id="window.selectionAction.title" xml:space="preserve">
+                               <source>Prepare to execute actions on selection</source>
+                       </trans-unit>
                        <trans-unit id="error.stageId.integer" xml:space="preserve">
                                <source>StageId is supposed to be an integer</source>
                        </trans-unit>
index b612f7e..731f72d 100644 (file)
@@ -68,9 +68,11 @@ TYPO3.Workspaces.SelectionModel = new Ext.grid.CheckboxSelectionModel({
                        var record = selection.grid.getSelectionModel().getSelections();
                        if (record.length > 0) {
                                TYPO3.Workspaces.Toolbar.selectStateActionCombo.setDisabled(false);
+                               TYPO3.Workspaces.Toolbar.selectionActionCombo.setDisabled(false);
                                TYPO3.Workspaces.Toolbar.selectStateMassActionCombo.setDisabled(true);
                        } else {
                                TYPO3.Workspaces.Toolbar.selectStateActionCombo.setDisabled(true);
+                               TYPO3.Workspaces.Toolbar.selectionActionCombo.setDisabled(true);
                                TYPO3.Workspaces.Toolbar.selectStateMassActionCombo.setDisabled(false);
                        }
                }
index 523aa05..bcb82b4 100644 (file)
@@ -92,14 +92,116 @@ TYPO3.Workspaces.Toolbar.selectMassActionStore = new Ext.data.DirectStore({
        listeners : {
                load : function(store, records) {
                        if (records.length == 0 || TYPO3.settings.Workspaces.singleView === '1') {
+                               TYPO3.Workspaces.Toolbar.selectionActionCombo.hide();
                                TYPO3.Workspaces.Toolbar.selectStateMassActionCombo.hide();
                        } else {
+                               TYPO3.Workspaces.Toolbar.selectionActionCombo.show();
                                TYPO3.Workspaces.Toolbar.selectStateMassActionCombo.show();
                        }
                }
        }
 });
 
+TYPO3.Workspaces.Toolbar.selectionActionCombo = new Ext.form.ComboBox({
+       width: 150,
+       lazyRender: true,
+       valueField: 'action',
+       displayField: 'title',
+       mode: 'local',
+       emptyText: 'choose selection action',
+       selectOnFocus: true,
+       triggerAction: 'all',
+       editable: false,
+       disabled : true, // disabled per default, enabled if selections are done in the grid
+       hidden : true, // hidden per default, shown if actions are available
+       forceSelection: true,
+       store: TYPO3.Workspaces.Toolbar.selectMassActionStore,
+       listeners: {
+               'select' : function(combo, record) {
+                       var label;
+                       var checkIntegrity = false;
+                       var selection = TYPO3.Workspaces.Helpers.getElementsArrayOfSelectionForIntegrityCheck(
+                               TYPO3.Workspaces.WorkspaceGrid.getSelectionModel().getSelections()
+                       );
+
+                       switch (record.data.action) {
+                               case 'publish':
+                                       label = TYPO3.l10n.localize('tooltip.publishSelected');
+                                       checkIntegrity = true;
+                                       break;
+                               case 'swap':
+                                       label = TYPO3.l10n.localize('tooltip.swapSelected');
+                                       checkIntegrity = true;
+                                       break;
+                               case 'discard':
+                                       label = TYPO3.l10n.localize('tooltip.discardSelected');
+                                       break;
+                       }
+
+                       top.TYPO3.Windows.close('executeSelectionActionWindow');
+
+                       var configuration = {
+                               id: 'executeSelectionActionWindow',
+                               title: TYPO3.l10n.localize('window.selectionAction.title'),
+                               items: [
+                                       {
+                                               xtype: 'form',
+                                               id: 'executeSelectionActionForm',
+                                               width: '100%',
+                                               html: label,
+                                               bodyStyle: 'padding: 5px 5px 3px 5px; border-width: 0; margin-bottom: 7px;'
+                                       }
+                               ],
+                               buttons: [
+                                       {
+                                               id: 'executeSelectionActionOkButton',
+                                               data: { action: record.data.action, selection: selection },
+                                               scope: this,
+                                               text: TYPO3.l10n.localize('ok'),
+                                               disabled:false,
+                                               handler: function(event) {
+                                                       top.Ext.getCmp('executeSelectionActionForm').update('Working...');
+                                                       top.Ext.getCmp('executeSelectionActionOkButton').disable();
+                                                       TYPO3.Workspaces.ExtDirectActions.executeSelectionAction(event.data, function(response) {
+                                                               top.Ext.getCmp('executeSelectionActionOkButton').hide();
+                                                               top.Ext.getCmp('executeSelectionActionCancelButton').setText(TYPO3.lang.close);
+                                                               if (response.error) {
+                                                                       top.Ext.getCmp('executeSelectionActionForm').update('<strong>' + TYPO3.l10n.localize('status.error') + ':</strong> ' + response.error);
+                                                               } else {
+                                                                       top.Ext.getCmp('executeSelectionActionForm').update(TYPO3.l10n.localize('runMassAction.done').replace('%d', response.total));
+                                                                       top.TYPO3.Backend.NavigationContainer.PageTree.refreshTree();
+                                                               }
+                                                       });
+                                               }
+                                       },
+                                       {
+                                               id: 'executeSelectionActionCancelButton',
+                                               scope: this,
+                                               text: TYPO3.l10n.localize('cancel'),
+                                               handler: function() {
+                                                       top.TYPO3.Windows.close('executeSelectionActionWindow');
+                                                       top.TYPO3.ModuleMenu.App.reloadFrames();
+                                               }
+                                       }
+                               ]
+                       };
+
+                       if (checkIntegrity) {
+                               var parameters = {
+                                       type: 'selection',
+                                       selection: selection
+                               };
+
+                               TYPO3.Workspaces.Actions.checkIntegrity(parameters, function() {
+                                       top.TYPO3.Windows.showWindow(configuration);
+                               });
+                       } else {
+                               top.TYPO3.Windows.showWindow(configuration);
+                       }
+               }
+       }
+});
+
 TYPO3.Workspaces.Toolbar.selectStateMassActionCombo = new Ext.form.ComboBox({
        width: 150,
        lazyRender: true,
@@ -297,6 +399,8 @@ TYPO3.Workspaces.Toolbar.FullTopToolbar = [
 TYPO3.Workspaces.Toolbar.FullBottomBar = [
        (TYPO3.settings.Workspaces.isLiveWorkspace == true || TYPO3.settings.Workspaces.allView) ? {hidden: true} : TYPO3.Workspaces.Toolbar.selectStateActionCombo,
        (TYPO3.settings.Workspaces.isLiveWorkspace == true || TYPO3.settings.Workspaces.allView) ? {hidden: true} : '-',
+       (TYPO3.settings.Workspaces.isLiveWorkspace == true || TYPO3.settings.Workspaces.allView) ? {hidden: true} : TYPO3.Workspaces.Toolbar.selectionActionCombo,
+       (TYPO3.settings.Workspaces.isLiveWorkspace == true || TYPO3.settings.Workspaces.allView) ? {hidden: true} : '-',
        (TYPO3.settings.Workspaces.isLiveWorkspace == true || TYPO3.settings.Workspaces.allView) ? {hidden: true} : TYPO3.Workspaces.Toolbar.selectStateMassActionCombo,
        {xtype: 'tbfill'},
        TYPO3.Workspaces.Toolbar.Pager