Use new popover improvements for anchor template plugin
authorMatthias Schmidt <gravatronics@live.com>
Sun, 24 May 2020 08:46:12 +0000 (10:46 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 24 May 2020 08:46:12 +0000 (10:46 +0200)
See WoltLab/WCF#3318

files/js/WCF.Conversation.js
files/js/WoltLabSuite/Core/Conversation/Ui/Subject/Editor.js
files/lib/data/conversation/Conversation.class.php
files/lib/data/conversation/ConversationAction.class.php
language/de.xml
language/en.xml
templates/conversationList.tpl

index d30c839f1e08bff12e576d27a61ee39150620dc8..c0b1865d9584ee51b03839e3e62e83b85513f52e 100644 (file)
@@ -1186,6 +1186,7 @@ WCF.Conversation.Label.Manager = Class.extend({
  * Provides a flexible conversation preview.
  * 
  * @see        WCF.Popover
+ * @deprecated  5.3     handled via `WoltLabSuite/Core/Controller/Popover`
  */
 WCF.Conversation.Preview = WCF.Popover.extend({
        /**
index 5456ff13f74e922ea00b46891dcbae5386fcc0ad..d7e9e85a297d2a7930fbcaeef084802f399c6b8e 100644 (file)
@@ -66,7 +66,7 @@ define(['Ajax', 'EventKey', 'Language', 'Ui/Dialog', 'Ui/Notification'], functio
                 */
                _getCurrentValue: function () {
                        var value = '';
-                       elBySelAll('.jsConversationSubject[data-conversation-id="' + _objectId + '"], .conversationLink[data-conversation-id="' + _objectId + '"]', undefined, function (subject) {
+                       elBySelAll('.jsConversationSubject[data-conversation-id="' + _objectId + '"], .conversationLink[data-object-id="' + _objectId + '"]', undefined, function (subject) {
                                value = subject.textContent;
                        });
                        
@@ -76,7 +76,7 @@ define(['Ajax', 'EventKey', 'Language', 'Ui/Dialog', 'Ui/Notification'], functio
                _ajaxSuccess: function (data) {
                        UiDialog.close(this);
                        
-                       elBySelAll('.jsConversationSubject[data-conversation-id="' + _objectId + '"], .conversationLink[data-conversation-id="' + _objectId + '"]', undefined, function (subject) {
+                       elBySelAll('.jsConversationSubject[data-conversation-id="' + _objectId + '"], .conversationLink[data-object-id="' + _objectId + '"]', undefined, function (subject) {
                                subject.textContent = data.returnValues.subject;
                        });
                        
index 51b93fc19330700ca1a852138b2237ea8186455b..98d11bfc600d26c0de4670d2b20eb4bd30f51940 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 namespace wcf\data\conversation;
 use wcf\data\conversation\message\ConversationMessage;
+use wcf\data\IPopoverObject;
 use wcf\data\user\group\UserGroup;
 use wcf\data\user\UserProfile;
 use wcf\data\DatabaseObject;
-use wcf\data\ITitledLinkObject;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
 use wcf\system\conversation\ConversationHandler;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
@@ -48,7 +48,7 @@ use wcf\util\ArrayUtil;
  * @property-read      integer|null    $leftAt                 timestamp at which the user left the conversation or `0` if they did not leave the conversation; is `null` if the conversation has not been fetched via `UserConversationList`
  * @property-read      integer|null    $lastMessageID          id of the last message written before the user left the conversation or `0` if they did not leave the conversation; is `null` if the conversation has not been fetched via `UserConversationList`
  */
-class Conversation extends DatabaseObject implements IRouteController, ITitledLinkObject {
+class Conversation extends DatabaseObject implements IPopoverObject, IRouteController {
        /**
         * default participation state
         * @var integer
@@ -420,6 +420,13 @@ class Conversation extends DatabaseObject implements IRouteController, ITitledLi
                return $this->isActiveParticipant;
        }
        
+       /**
+        * @inheritDoc
+        */
+       public function getPopoverLinkClass() {
+               return 'conversationLink';
+       }
+       
        /**
         * Returns true if the given user id (default: current user) is participant
         * of all given conversation ids.
index 4af71262922d42b6dadcf7e380a93da9422faa5f..9a1dec18c1573cbab8d1efd29bbaf68d0a0f7f22 100644 (file)
@@ -6,6 +6,7 @@ use wcf\data\conversation\message\ConversationMessageList;
 use wcf\data\conversation\message\SimplifiedViewableConversationMessageList;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\IClipboardAction;
+use wcf\data\IPopoverAction;
 use wcf\data\IVisitableObjectAction;
 use wcf\system\clipboard\ClipboardHandler;
 use wcf\system\conversation\ConversationHandler;
@@ -31,7 +32,7 @@ use wcf\system\WCF;
  * @method     ConversationEditor[]    getObjects()
  * @method     ConversationEditor      getSingleObject()
  */
-class ConversationAction extends AbstractDatabaseObjectAction implements IClipboardAction, IVisitableObjectAction {
+class ConversationAction extends AbstractDatabaseObjectAction implements IClipboardAction, IPopoverAction, IVisitableObjectAction {
        /**
         * @inheritDoc
         */
@@ -433,11 +434,9 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
        }
        
        /**
-        * Validates the get message preview action.
-        * 
-        * @throws      PermissionDeniedException
+        * @inheritDoc
         */
-       public function validateGetMessagePreview() {
+       public function validateGetPopover() {
                $this->conversation = $this->getSingleObject();
                if (!Conversation::isParticipant([$this->conversation->conversationID])) {
                        throw new PermissionDeniedException();
@@ -445,25 +444,40 @@ class ConversationAction extends AbstractDatabaseObjectAction implements IClipbo
        }
        
        /**
-        * Returns a preview of a message in a specific conversation.
-        * 
-        * @return      string[]
+        * @inheritDoc
         */
-       public function getMessagePreview() {
+       public function getPopover() {
                $messageList = new SimplifiedViewableConversationMessageList();
-               
                $messageList->getConditionBuilder()->add("conversation_message.messageID = ?", [$this->conversation->firstMessageID]);
                $messageList->readObjects();
-               $messages = $messageList->getObjects();
                
-               WCF::getTPL()->assign([
-                       'message' => reset($messages)
-               ]);
                return [
-                       'template' => WCF::getTPL()->fetch('conversationMessagePreview')
+                       'template' => WCF::getTPL()->fetch('conversationMessagePreview', 'wcf', [
+                               'message' => $messageList->getSingleObject(),
+                       ]),
                ];
        }
        
+       /**
+        * Validates the get message preview action.
+        * 
+        * @throws      PermissionDeniedException
+        * @deprecated  5.3     Use `validateGetPopover()` instead.
+        */
+       public function validateGetMessagePreview() {
+               $this->validateGetPopover();
+       }
+       
+       /**
+        * Returns a preview of a message in a specific conversation.
+        * 
+        * @return      string[]
+        * @deprecated  5.3     Use `getPopover()` instead.
+        */
+       public function getMessagePreview() {
+               return $this->getPopover();
+       }
+       
        /**
         * Validates parameters to close conversations.
         * 
index 9c865e5a632a9d136e06a55bb4e534e6da63ed81..fe3abf7bb219e1e5f2ab9c1bb2d4edb999d7ca42 100644 (file)
                <item name="wcf.moderation.type.com.woltlab.wcf.conversation.message"><![CDATA[Konversation]]></item>
        </category>
        <category name="wcf.page">
-               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.Conversation"><![CDATA[Konversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
+               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.Conversation"><![CDATA[Konversation {anchor object=$conversation class='conversationLink'}]]></item>
        </category>
        <category name="wcf.search">
                <item name="wcf.search.type.com.woltlab.wcf.conversation"><![CDATA[Diese Konversation]]></item>
index c028c0e8b0981094ba4683d5151e9855f80db098..209ba2d9b770500d6e96fe01606ae3f25a6b841c 100644 (file)
                <item name="wcf.moderation.type.com.woltlab.wcf.conversation.message"><![CDATA[Conversation]]></item>
        </category>
        <category name="wcf.page">
-               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.Conversation"><![CDATA[Conversation <a href="{link controller='Conversation' object=$conversation}{/link}" class="conversationLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>]]></item>
+               <item name="wcf.page.onlineLocation.com.woltlab.wcf.conversation.Conversation"><![CDATA[Conversation {anchor object=$conversation class='conversationLink'}]]></item>
        </category>
        <category name="wcf.search">
                <item name="wcf.search.type.com.woltlab.wcf.conversation"><![CDATA[This Conversation]]></item>
index 58c6618e42eab9f66eb557a78089b1f3c43450e8..0d45e3b7a00c677b6f2f5a968dd0d4e4f7ad08a5 100644 (file)
                                                        {/hascontent}
                                                                
                                                        <h3>
-                                                               <a href="{if $conversation->isNew()}{link controller='Conversation' object=$conversation}action=firstNew{/link}{else}{link controller='Conversation' object=$conversation}{/link}{/if}" class="conversationLink messageGroupLink" data-conversation-id="{@$conversation->conversationID}">{$conversation->subject}</a>
+                                                               <a href="{if $conversation->isNew()}{link controller='Conversation' object=$conversation}action=firstNew{/link}{else}{$conversation->getLink()}{/if}" class="conversationLink messageGroupLink" data-object-id="{@$conversation->conversationID}">{$conversation->subject}</a>
                                                                {if $conversation->replies}
                                                                        <span class="badge messageGroupCounterMobile">{@$conversation->replies|shortUnit}</span>
                                                                {/if}
 
 <script data-relocate="true" src="{@$__wcf->getPath()}js/WCF.Conversation{if !ENABLE_DEBUG_MODE}.min{/if}.js?v={@LAST_UPDATE_TIME}"></script>
 <script data-relocate="true">
-       require(['Language', 'WoltLabSuite/Core/Ui/ItemList/User'], function(Language, UiItemListUser) {
+       require(['Language', 'WoltLabSuite/Core/Controller/Popover', 'WoltLabSuite/Core/Ui/ItemList/User'], function(Language, ControllerPopover, UiItemListUser) {
                Language.addObject({
                        'wcf.conversation.edit.addParticipants': '{lang}wcf.conversation.edit.addParticipants{/lang}',
                        'wcf.conversation.edit.assignLabel': '{lang}wcf.conversation.edit.assignLabel{/lang}',
                
                new WCF.Conversation.Clipboard($editorHandler);
                new WCF.Conversation.Label.Manager('{link controller='ConversationList' encode=false}{if $filter}filter={@$filter}&{/if}{if !$participants|empty}participants={implode from=$participants item=participant}{$participant|rawurlencode}{/implode}&{/if}sortField={$sortField}&sortOrder={$sortOrder}&pageNo={@$pageNo}{/link}');
-               new WCF.Conversation.Preview();
                new WCF.Conversation.MarkAsRead();
                new WCF.Conversation.MarkAllAsRead();
                
                        excludedSearchValues: ['{$__wcf->user->username|encodeJS}'],
                        maxItems: 20
                });
+               
+               ControllerPopover.init({
+                       className: 'conversationLink',
+                       dboAction: 'wcf\\data\\conversation\\ConversationAction',
+                       identifier: 'com.woltlab.wcf.conversation'
+               });
        });
 </script>