Optional page reload after executing clipboard actions
authorAlexander Ebert <ebert@woltlab.com>
Fri, 22 Jun 2018 15:40:28 +0000 (17:40 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 22 Jun 2018 15:40:28 +0000 (17:40 +0200)
See #2584

wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Clipboard.js
wcfsetup/install/files/lib/data/clipboard/item/ClipboardItemAction.class.php
wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php
wcfsetup/install/files/lib/system/clipboard/action/AbstractClipboardAction.class.php
wcfsetup/install/files/lib/system/clipboard/action/IClipboardAction.class.php

index 5edc21ef3dc98d8b63e2932d547b05935f77a420..2be8dcb930f6337b53985da70da2c5bc53370426 100644 (file)
@@ -50,6 +50,7 @@ define(
        var _itemData = new ObjectMap();
        var _knownCheckboxes = new List();
        var _options = {};
+       var _reloadPageOnSuccess = new Dictionary();
        
        var _callbackCheckbox = null;
        var _callbackItem = null;
@@ -406,6 +407,11 @@ define(
                                                listItem: listItem,
                                                responseData: responseData
                                        });
+                                       
+                                       if (_reloadPageOnSuccess.has(type) && _reloadPageOnSuccess.get(type).indexOf(responseData.actionName) !== -1) {
+                                               window.location.reload();
+                                               return;
+                                       }
                                }
                                
                                this._loadMarkedItems();
@@ -449,7 +455,6 @@ define(
                _ajaxSuccess: function(data) {
                        if (data.actionName === 'unmarkAll') {
                                _containers.forEach((function(containerData) {
-                                       //noinspection JSUnresolvedVariable
                                        if (elData(containerData.element, 'type') === data.returnValues.objectType) {
                                                var clipboardObjects = elByClass('jsMarked', containerData.element);
                                                while (clipboardObjects.length) {
@@ -463,7 +468,6 @@ define(
                                                        containerData.checkboxes[i].checked = false;
                                                }
                                                
-                                               //noinspection JSUnresolvedVariable
                                                UiPageAction.remove('wcfClipboard-' + data.returnValues.objectType);
                                        }
                                }).bind(this));
@@ -472,6 +476,7 @@ define(
                        }
                        
                        _itemData = new ObjectMap();
+                       _reloadPageOnSuccess = new Dictionary();
                        
                        // rebuild markings
                        _containers.forEach((function(containerData) {
@@ -483,11 +488,8 @@ define(
                        }).bind(this));
                        
                        var keepEditors = [], typeName;
-                       //noinspection JSUnresolvedVariable
                        if (data.returnValues && data.returnValues.items) {
-                               //noinspection JSUnresolvedVariable
                                for (typeName in data.returnValues.items) {
-                                       //noinspection JSUnresolvedVariable
                                        if (data.returnValues.items.hasOwnProperty(typeName)) {
                                                keepEditors.push(typeName);
                                        }
@@ -504,7 +506,6 @@ define(
                        });
                        
                        // no items
-                       //noinspection JSUnresolvedVariable
                        if (!data.returnValues || !data.returnValues.items) {
                                return;
                        }
@@ -512,15 +513,14 @@ define(
                        // rebuild editors
                        var actionName, created, dropdown, editor, typeData;
                        var divider, item, itemData, itemIndex, label, unmarkAll;
-                       //noinspection JSUnresolvedVariable
                        for (typeName in data.returnValues.items) {
-                               //noinspection JSUnresolvedVariable
                                if (!data.returnValues.items.hasOwnProperty(typeName)) {
                                        continue;
                                }
                                
-                               //noinspection JSUnresolvedVariable
                                typeData = data.returnValues.items[typeName];
+                               //noinspection JSUnresolvedVariable
+                               _reloadPageOnSuccess.set(typeName, typeData.reloadPageOnSuccess);
                                created = false;
                                
                                editor = _editors.get(typeName);
index 77b4a8ce9472a6dabc5a76ee32374b31f636b8c4..6946b11a40c3930170bf69452a69d7b524174362 100644 (file)
@@ -152,7 +152,8 @@ class ClipboardItemAction extends AbstractDatabaseObjectAction {
                foreach ($data as $typeName => $itemData) {
                        $items = [
                                'label' => $itemData['label'],
-                               'items' => []
+                               'items' => [],
+                               'reloadPageOnSuccess' => $itemData['reloadPageOnSuccess']
                        ];
                        
                        /** @var ClipboardEditorItem $item */
index e8cc198ad3b3c4cf30ac18fbf89ffce11ed777ae..a3a9b52cfedcf638737441d47cc3d1e3cfb7c348 100644 (file)
@@ -371,7 +371,8 @@ class ClipboardHandler extends SingletonFactory {
                        if (!isset($editorData[$typeName])) {
                                $editorData[$typeName] = [
                                        'label' => $clipboardAction->getEditorLabel($this->markedItems[$typeName]),
-                                       'items' => []
+                                       'items' => [],
+                                       'reloadPageOnSuccess' => $clipboardAction->getReloadPageOnSuccess()
                                ];
                        }
                        
index 083c3c81ad971cec01d38ff8facff9d1bb0de7a1..1aa4c3a9621c7114babfb5aa81e65c4326363be8 100644 (file)
@@ -28,6 +28,13 @@ abstract class AbstractClipboardAction implements IClipboardAction {
         */
        protected $objects = [];
        
+       /**
+        * list of action names that should trigger a page reload once they have been executed
+        * @var string[]
+        * @since 3.2
+        */
+       protected $reloadPageOnSuccess = [];
+       
        /**
         * list of the supported clipboard actions
         * @var string[]
@@ -75,4 +82,11 @@ abstract class AbstractClipboardAction implements IClipboardAction {
                        'count' => count($objects)
                ]);
        }
+       
+       /**
+        * @inheritDoc
+        */
+       public function getReloadPageOnSuccess() {
+               return $this->reloadPageOnSuccess;
+       }
 }
index 8a94f23e61c318f43218f0598a8b8ab9ffd905c7..417e2294323da25685652a18b6c918565c3c005e 100644 (file)
@@ -45,4 +45,13 @@ interface IClipboardAction {
         * @return      string
         */
        public function getEditorLabel(array $objects);
+       
+       /**
+        * Returns the list of action names that should trigger a page reload once they
+        * have been executed.
+        * 
+        * @return      string[]
+        * @since       3.2
+        */
+       public function getReloadPageOnSuccess();
 }