Implemented enable feature for responses
authorAlexander Ebert <ebert@woltlab.com>
Thu, 9 Mar 2017 13:58:32 +0000 (14:58 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 9 Mar 2017 13:58:32 +0000 (14:58 +0100)
See #2219

com.woltlab.wcf/templates/commentResponseList.tpl
wcfsetup/install/files/js/WCF.Comment.js
wcfsetup/install/files/lib/data/comment/CommentAction.class.php
wcfsetup/install/files/lib/data/comment/response/CommentResponseAction.class.php
wcfsetup/install/files/style/ui/comment.scss

index 10e422386560d833ec369cd1d9f1f72576dc0124..7b585d6d004e0843abb07761a091132a98615e94 100644 (file)
@@ -1,5 +1,5 @@
 {foreach from=$responseList item=response}
-       {if $response->isDisabled && $commentCanModerate|isset && !$commentCanModerate}
+       {if $response->isDisabled && !$commentCanModerate}
                <li>
                        <p class="info commentModerationDisabledComment">{lang}wcf.comment.moderation.disabledComment{/lang}</p>
                </li>
@@ -39,6 +39,9 @@
                                        
                                        <nav class="jsMobileNavigation buttonGroupNavigation">
                                                <ul class="buttonList iconList">
+                                                       {if $response->isDisabled && $commentCanModerate}
+                                                               <li class="jsOnly"><a href="#" class="jsEnableResponse"><span class="icon icon16 fa-check"></span> <span class="invisible">{lang}wcf.comment.approve{/lang}</span></a></li>
+                                                       {/if}
                                                        {if $commentManager->supportsReport() && $__wcf->session->getPermission('user.profile.canReportContent')}
                                                                <li class="jsReportCommentResponse jsOnly" data-object-id="{@$response->responseID}"><a href="#" title="{lang}wcf.moderation.report.reportContent{/lang}" class="jsTooltip"><span class="icon icon16 fa-exclamation-triangle"></span> <span class="invisible">{lang}wcf.moderation.report.reportContent{/lang}</span></a></li>
                                                        {/if}
index 5304baddd4aa2ae2fa37a041b35bf7540513e9b5..908c40a8a8fb4102ab26d538c2ef8915687a23fd 100644 (file)
@@ -440,13 +440,7 @@ WCF.Comment.Handler = Class.extend({
                this._proxy.setOption('data', {
                        actionName: 'enable',
                        className: 'wcf\\data\\comment\\CommentAction',
-                       objectIDs: [elData(comment, 'object-id')],
-                       parameters: {
-                               data: {
-                                       objectID: elData(this._container[0], 'object-id'),
-                                       objectTypeID: elData(this._container[0], 'object-type-id')
-                               }
-                       }
+                       objectIDs: [elData(comment, 'object-id')]
                });
                this._proxy.sendRequest();
        },
@@ -492,11 +486,33 @@ WCF.Comment.Handler = Class.extend({
                                        
                                        //noinspection JSReferencingMutableVariableFromClosure
                                        this._initPermalinkResponse(commentId, response, $responseID, link);
+                                       
+                                       var enableResponse = elBySel('.jsEnableResponse', response);
+                                       if (enableResponse) {
+                                               enableResponse.addEventListener(WCF_CLICK_EVENT, this._enableCommentResponse.bind(this));
+                                       }
                                }).bind(this));
                        }
                }
        },
        
+       _enableCommentResponse: function (event) {
+               event.preventDefault();
+               
+               var response = event.currentTarget.closest('.commentResponse');
+               
+               this._proxy.setOption('data', {
+                       actionName: 'enableResponse',
+                       className: 'wcf\\data\\comment\\CommentAction',
+                       parameters: {
+                               data: {
+                                       responseID: elData(response, 'object-id')
+                               }
+                       }
+               });
+               this._proxy.sendRequest();
+       },
+       
        _initPermalinkResponse: function (commentId, response, responseId, link) {
                var anchor = elCreate('a');
                anchor.href = link + (link.indexOf('#') === -1 ? '#' : '/') + 'comment' + commentId + '/response' + responseId;
@@ -787,6 +803,10 @@ WCF.Comment.Handler = Class.extend({
                        case 'enable':
                                this._enable(data);
                                break;
+                               
+                       case 'enableResponse':
+                               this._enableResponse(data);
+                               break;
                        
                        case 'loadComment':
                                this._insertComment(data);
@@ -834,6 +854,20 @@ WCF.Comment.Handler = Class.extend({
                }
        },
        
+       _enableResponse: function(data) {
+               if (data.returnValues.responseID) {
+                       var response = elBySel('.commentResponse[data-object-id="' + data.returnValues.responseID + '"]', this._container[0]);
+                       if (response) {
+                               elData(response, 'is-disabled', 0);
+                               var badge = elBySel('.jsIconDisabled', response);
+                               if (badge) elRemove(badge);
+                               
+                               var enableLink = elBySel('.jsEnableResponse', response);
+                               if (enableLink) elRemove(enableLink.parentNode);
+                       }
+               }
+       },
+       
        _insertComment: function (data) {
                if (data.returnValues.template === '') {
                        // comment id is invalid or there is a mismatch, silently ignore it
index 6c823a5bdb3d3425b2dda583766582520940a092..ec1035590635ce91c18cee03699c51dcc4c8a7d1 100644 (file)
@@ -512,8 +512,10 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                        $this->commentProcessor = $objectType->getProcessor();
                }
                
-               /** @var CommentResponseEditor $response */
+               /** @var CommentResponse $response */
                foreach ($this->parameters['responses'] as $response) {
+                       (new CommentResponseEditor($response))->update(['isDisabled' => 0]);
+                       
                        $comment = $response->getComment();
                        
                        // update response count
@@ -527,14 +529,14 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                        $this->commentProcessor->updateCounter($comment->objectID, 1);
                        
                        // fire activity event
-                       if ($this->createdResponse->userID && UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType.'.response.recentActivityEvent')) {
+                       if ($response->userID && UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType.'.response.recentActivityEvent')) {
                                UserActivityEventHandler::getInstance()->fireEvent($objectType->objectType.'.response.recentActivityEvent', $response->responseID, null, null, $response->time);
                        }
                        
                        // fire notification event
                        if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.response.notification') && UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.notification')) {
                                $notificationObjectType = UserNotificationHandler::getInstance()->getObjectTypeProcessor($objectType->objectType.'.notification');
-                               $notificationObject = new CommentResponseUserNotificationObject($this->createdResponse);
+                               $notificationObject = new CommentResponseUserNotificationObject($response);
                                
                                if ($notificationObjectType instanceof IMultiRecipientCommentUserNotificationObjectType) {
                                        $recipientIDs = $notificationObjectType->getRecipientIDs($comment);
@@ -565,7 +567,7 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                                                        'commentResponse',
                                                        $objectType->objectType . '.response.notification',
                                                        $notificationObject,
-                                                       [$this->comment->userID],
+                                                       [$comment->userID],
                                                        [
                                                                'commentID' => $comment->commentID,
                                                                'objectID' => $comment->objectID,
@@ -597,7 +599,6 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
        }
        
        public function validateEnable() {
-               $this->readInteger('objectID', false, 'data');
                $this->comment = $this->getSingleObject()->getDecoratedObject();
                
                $objectType = $this->validateObjectType($this->comment->objectTypeID);
@@ -618,6 +619,35 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                return ['commentID' => $this->comment->commentID];
        }
        
+       public function validateEnableResponse() {
+               $this->readInteger('responseID', false, 'data');
+               $this->response = new CommentResponse($this->parameters['data']['responseID']);
+               if (!$this->response->responseID) {
+                       throw new UserInputException('responseID');
+               }
+               
+               $this->comment = $this->response->getComment();
+               
+               $objectType = $this->validateObjectType($this->comment->objectTypeID);
+               $this->commentProcessor = $objectType->getProcessor();
+               if (!$this->commentProcessor->canModerate($this->comment->objectTypeID, $this->comment->objectID)) {
+                       throw new PermissionDeniedException();
+               }
+       }
+       
+       public function enableResponse() {
+               if ($this->response->isDisabled) {
+                       $action = new CommentAction([], 'triggerPublicationResponse', [
+                               'commentProcessor' => $this->commentProcessor,
+                               'objectTypeID' => $this->comment->objectTypeID,
+                               'responses' => [$this->response]
+                       ]);
+                       $action->executeAction();
+               }
+               
+               return ['responseID' => $this->response->responseID];
+       }
+       
        /**
         * Validates parameters to edit a comment or a response.
         */
index 302a0c5b4369b3ce25ed70fe5e43ffc7ebdc095f..a2248d35a22199027b780b05c9af8f2a7fc21bca 100644 (file)
@@ -163,9 +163,12 @@ class CommentResponseAction extends AbstractDatabaseObjectAction {
         * @return      array
         */
        public function loadResponses() {
+               $commentCanModerate = $this->commentManager->canModerate($this->comment->objectTypeID, $this->comment->objectID);
+               
                // get response list
                $responseList = new StructuredCommentResponseList($this->commentManager, $this->comment);
                $responseList->getConditionBuilder()->add("comment_response.time > ?", [$this->parameters['data']['lastResponseTime']]);
+               if (!$commentCanModerate) $responseList->getConditionBuilder()->add("comment_response.isDisabled = ?", [0]);
                if (!$this->parameters['data']['loadAllResponses']) $responseList->sqlLimit = 50;
                $responseList->readObjects();
                
@@ -179,6 +182,7 @@ class CommentResponseAction extends AbstractDatabaseObjectAction {
                }
                
                WCF::getTPL()->assign([
+                       'commentCanModerate' => $commentCanModerate,
                        'likeData' => MODULE_LIKE ? $responseList->getLikeData() : [],
                        'responseList' => $responseList,
                        'commentManager' => $this->commentManager
index 328629c6d5d610658a94daa7735b145882ca3d66..9af39d04e6ef338abf8955d7b00032cdf55e86d1 100644 (file)
        position: absolute;
 }
 
-.jsEnableComment > .invisible {
+.jsEnableComment > .invisible,
+.jsEnableResponse > .invisible {
        display: inline;
 }