Implemented enabling of comments
authorAlexander Ebert <ebert@woltlab.com>
Wed, 8 Mar 2017 17:37:14 +0000 (18:37 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 8 Mar 2017 17:37:14 +0000 (18:37 +0100)
See #2219

wcfsetup/install/files/js/WCF.Comment.js
wcfsetup/install/files/lib/data/comment/CommentAction.class.php

index af9f320a978b95b984fc0c847f326266b1a21b23..5579aafd9a615b988c1468631609f855c3c02f5a 100644 (file)
@@ -425,6 +425,30 @@ WCF.Comment.Handler = Class.extend({
                        var $deleteButton = $('<li><a href="#" class="jsTooltip" title="' + WCF.Language.get('wcf.global.button.delete') + '"><span class="icon icon16 fa-times" /> <span class="invisible">' + WCF.Language.get('wcf.global.button.delete') + '</span></a></li>');
                        $deleteButton.data('commentID', commentID).appendTo(comment.find('ul.buttonList:eq(0)')).click($.proxy(this._delete, this));
                }
+               
+               var enableComment = elBySel('.jsEnableComment', comment[0]);
+               if (enableComment) {
+                       enableComment.addEventListener(WCF_CLICK_EVENT, this._enableComment.bind(this));
+               }
+       },
+       
+       _enableComment: function (event) {
+               event.preventDefault();
+               
+               var comment = event.currentTarget.closest('.comment');
+               
+               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')
+                               }
+                       }
+               });
+               this._proxy.sendRequest();
        },
        
        _initPermalink: function(comment, link) {
@@ -755,6 +779,10 @@ WCF.Comment.Handler = Class.extend({
                                this._update(data);
                        break;
                        
+                       case 'enable':
+                               this._enable(data);
+                               break;
+                       
                        case 'loadComment':
                                this._insertComment(data);
                                break;
@@ -787,6 +815,20 @@ WCF.Comment.Handler = Class.extend({
                WCF.DOMNodeInsertedHandler.execute();
        },
        
+       _enable: function(data) {
+               if (data.returnValues.commentID) {
+                       var comment = elBySel('.comment[data-object-id="' + data.returnValues.commentID + '"]', this._container[0]);
+                       if (comment) {
+                               elData(comment, 'is-disabled', 0);
+                               var badge = elBySel('.jsIconDisabled', comment);
+                               if (badge) elRemove(badge);
+                               
+                               var enableLink = elBySel('.jsEnableComment', comment);
+                               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 73f0a306f0bffcd5ad8c36999f2ee6b240d71cd3..b919bb8ee21ddb6114905b7c4aa1a49779e185e2 100644 (file)
@@ -355,6 +355,7 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli
                /** @var CommentEditor $comment */
                foreach ($this->objects as $comment) {
                        // update counter
+                       $comment->update(['isDisabled' => 0]);
                        $this->commentProcessor->updateCounter($comment->objectID, 1);
                        
                        // fire activity event
@@ -596,6 +597,28 @@ 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);
+               $this->commentProcessor = $objectType->getProcessor();
+               if (!$this->commentProcessor->canModerate($this->comment->objectTypeID, $this->comment->objectID)) {
+                       throw new PermissionDeniedException();
+               }
+       }
+       
+       public function enable() {
+               if ($this->comment->isDisabled) {
+                       $action = new CommentAction([$this->comment], 'triggerPublication', [
+                               'commentProcessor' => $this->commentProcessor
+                       ]);
+                       $action->executeAction();
+               }
+               
+               return ['commentID' => $this->comment->commentID];
+       }
+       
        /**
         * Validates parameters to edit a comment or a response.
         */