From: Alexander Ebert <ebert@woltlab.com>
Date: Fri, 22 Jun 2018 15:40:28 +0000 (+0200)
Subject: Optional page reload after executing clipboard actions
X-Git-Tag: 5.2.0_Alpha_1~140^2~11
X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=37ddf90a11ffea99a45b40d4548d964dae0629fe;p=GitHub%2FWoltLab%2FWCF.git

Optional page reload after executing clipboard actions

See #2584
---

diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Clipboard.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Clipboard.js
index 5edc21ef3d..2be8dcb930 100644
--- a/wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Clipboard.js
+++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Controller/Clipboard.js
@@ -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);
diff --git a/wcfsetup/install/files/lib/data/clipboard/item/ClipboardItemAction.class.php b/wcfsetup/install/files/lib/data/clipboard/item/ClipboardItemAction.class.php
index 77b4a8ce94..6946b11a40 100644
--- a/wcfsetup/install/files/lib/data/clipboard/item/ClipboardItemAction.class.php
+++ b/wcfsetup/install/files/lib/data/clipboard/item/ClipboardItemAction.class.php
@@ -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 */
diff --git a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php
index e8cc198ad3..a3a9b52cfe 100644
--- a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php
+++ b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php
@@ -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()
 				];
 			}
 			
diff --git a/wcfsetup/install/files/lib/system/clipboard/action/AbstractClipboardAction.class.php b/wcfsetup/install/files/lib/system/clipboard/action/AbstractClipboardAction.class.php
index 083c3c81ad..1aa4c3a962 100644
--- a/wcfsetup/install/files/lib/system/clipboard/action/AbstractClipboardAction.class.php
+++ b/wcfsetup/install/files/lib/system/clipboard/action/AbstractClipboardAction.class.php
@@ -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;
+	}
 }
diff --git a/wcfsetup/install/files/lib/system/clipboard/action/IClipboardAction.class.php b/wcfsetup/install/files/lib/system/clipboard/action/IClipboardAction.class.php
index 8a94f23e61..417e229432 100644
--- a/wcfsetup/install/files/lib/system/clipboard/action/IClipboardAction.class.php
+++ b/wcfsetup/install/files/lib/system/clipboard/action/IClipboardAction.class.php
@@ -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();
 }