Use `Ui/Object/Action` instead of `WCF.Action.*`
authorMatthias Schmidt <gravatronics@live.com>
Wed, 24 Mar 2021 13:37:43 +0000 (14:37 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 24 Mar 2021 13:37:43 +0000 (14:37 +0100)
See WoltLab/WCF#4080

files/js/WCF.Conversation.js
files/js/WoltLabSuite/Core/Conversation/Ui/Object/Action/RemoveParticipant.js [new file with mode: 0644]
files/lib/data/conversation/ConversationAction.class.php
templates/conversation.tpl
ts/WoltLabSuite/Core/Conversation/Ui/Object/Action/RemoveParticipant.ts [new file with mode: 0644]

index c0b1865d9584ee51b03839e3e62e83b85513f52e..08372f7fcb47bcbb5d101da648bf268ab3cf175b 100644 (file)
@@ -685,6 +685,7 @@ WCF.Conversation.Leave = Class.extend({
  * Provides methods to remove participants from conversations.
  * 
  * @see        WCF.Action.Delete
+ * @deprecated 5.4 Handled via `WoltLabSuite/Core/Ui/Object/Action`.
  */
 WCF.Conversation.RemoveParticipant = WCF.Action.Delete.extend({
        /**
diff --git a/files/js/WoltLabSuite/Core/Conversation/Ui/Object/Action/RemoveParticipant.js b/files/js/WoltLabSuite/Core/Conversation/Ui/Object/Action/RemoveParticipant.js
new file mode 100644 (file)
index 0000000..fffa028
--- /dev/null
@@ -0,0 +1,22 @@
+/**
+ * Reacts to objects being toggled.
+ *
+ * @author  Matthias Schmidt
+ * @copyright  2001-2021 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Ui/Object/Action/Toggle
+ */
+define(["require", "exports", "tslib", "WoltLabSuite/Core/Ui/Object/Action/Handler"], function (require, exports, tslib_1, Handler_1) {
+    "use strict";
+    Object.defineProperty(exports, "__esModule", { value: true });
+    exports.setup = void 0;
+    Handler_1 = tslib_1.__importDefault(Handler_1);
+    function removeParticipant(data, objectElement) {
+        objectElement.querySelector(".userLink").classList.add("conversationLeft");
+        objectElement.querySelector(".jsObjectAction[data-object-action='removeParticipant']").remove();
+    }
+    function setup() {
+        new Handler_1.default("removeParticipant", [], removeParticipant);
+    }
+    exports.setup = setup;
+});
index 440eea26d2cf577cbb1c1b1859050ccf1922ac78..742491ef03d93e68f03b3854a6a54aad6d2b5b5e 100644 (file)
@@ -1046,7 +1046,14 @@ class ConversationAction extends AbstractDatabaseObjectAction implements
      */
     public function validateRemoveParticipant()
     {
-        $this->readInteger('userID');
+        // The previous request from `WCF.Action.Delete` used `userID`, while the new `Ui/Object/Action`
+        // module passes `userId`.
+        try {
+            $this->readInteger('userID');
+        } catch (UserInputException $e) {
+            $this->readInteger('userId');
+            $this->parameters['userID'] = $this->parameters['userId'];
+        }
 
         // validate conversation
         $this->conversation = $this->getSingleObject();
index 2c6956dabec9f0122420e0ad090e54c85880d278..32dd551af159cc4e0c82bc7749d5ee317143e017 100644 (file)
@@ -60,9 +60,9 @@
        <section class="section">
                <h2 class="sectionTitle">{lang}wcf.conversation.participants{/lang}</h2>
                
-               <ul class="containerBoxList tripleColumned conversationParticipantList">
+               <ul class="containerBoxList tripleColumned conversationParticipantList jsObjectActionContainer" data-object-action-class-name="wcf\data\conversation\ConversationAction">
                        {foreach from=$participants item=participant}
-                               <li class="jsParticipant{if !$participant->userID || $participant->hideConversation == 2 || $participant->leftAt > 0} conversationLeft{/if}">
+                               <li class="jsParticipant jsObjectActionObject{if !$participant->userID || $participant->hideConversation == 2 || $participant->leftAt > 0} conversationLeft{/if}" data-object-id="{@$conversation->getObjectID()}">
                                        <div class="box24">
                                                {user object=$participant type='avatar24' ariaHidden='true' tabindex='-1'}
                                                <div>
@@ -70,7 +70,7 @@
                                                                {user object=$participant}
                                                                {if $participant->isInvisible}<small>({lang}wcf.conversation.invisible{/lang})</small>{/if}
                                                                {if $participant->userID && ($conversation->userID == $__wcf->getUser()->userID) && ($participant->userID != $__wcf->getUser()->userID) && $participant->hideConversation != 2 && $participant->leftAt == 0}
-                                                                       <a href="#" class="jsDeleteButton jsTooltip jsOnly" title="{lang}wcf.conversation.participants.removeParticipant{/lang}" data-confirm-message-html="{lang __encode=true}wcf.conversation.participants.removeParticipant.confirmMessage{/lang}" data-object-id="{@$participant->userID}"><span class="icon icon16 fa-times"></span></a>
+                                                                       <a href="#" class="jsObjectAction jsTooltip jsOnly" data-object-action="removeParticipant" title="{lang}wcf.conversation.participants.removeParticipant{/lang}" data-confirm-message="{lang __encode=true}wcf.conversation.participants.removeParticipant.confirmMessage{/lang}" data-object-action-parameter-user-id="{@$participant->getObjectID()}"><span class="icon icon16 fa-times"></span></a>
                                                                {/if}
                                                        </p>
                                                        <dl class="plain inlineDataList small">
                {if $__wcf->session->getPermission('user.profile.canReportContent')}
                        new WCF.Moderation.Report.Content('com.woltlab.wcf.conversation.message', '.jsReportConversationMessage');
                {/if}
-               new WCF.Conversation.RemoveParticipant({@$conversation->conversationID});
+       });
+       
+       require(['WoltLabSuite/Core/Conversation/Ui/Object/Action/RemoveParticipant'], (UiObjectActionRemoveParticipant) => {
+               UiObjectActionRemoveParticipant.setup();
        });
 </script>
 
diff --git a/ts/WoltLabSuite/Core/Conversation/Ui/Object/Action/RemoveParticipant.ts b/ts/WoltLabSuite/Core/Conversation/Ui/Object/Action/RemoveParticipant.ts
new file mode 100644 (file)
index 0000000..1e79e6e
--- /dev/null
@@ -0,0 +1,20 @@
+/**
+ * Reacts to participants being removed from a conversation.
+ *
+ * @author  Matthias Schmidt
+ * @copyright  2001-2021 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Conversation/Ui/Object/Action/RemoveParticipant
+ */
+
+import UiObjectActionHandler from "WoltLabSuite/Core/Ui/Object/Action/Handler";
+import { DatabaseObjectActionResponse } from "WoltLabSuite/Core/Ajax/Data";
+
+function removeParticipant(data: DatabaseObjectActionResponse, objectElement: HTMLElement): void {
+  objectElement.querySelector(".userLink")!.classList.add("conversationLeft");
+  objectElement.querySelector(".jsObjectAction[data-object-action='removeParticipant']")!.remove();
+}
+
+export function setup(): void {
+  new UiObjectActionHandler("removeParticipant", [], removeParticipant);
+}