this._insertComments(data);
break;
+ case 'loadResponse':
+ this._insertResponse(data);
+ break;
+
case 'loadResponses':
this._insertResponses(data);
break;
if (data.returnValues.template === '') {
// comment id is invalid or there is a mismatch, silently ignore it
return;
- }
+ }
+
+ // TODO: handle 'response' value
$(data.returnValues.template).insertBefore(this._permalinkComment);
var comment = this._permalinkComment.previousElementSibling;
//noinspection BadExpressionStatementJS
comment.offsetTop;
- comment.classList.add('fadeIn');
+ comment.classList.add('commentHighlightTarget');
+ },
+
+ _insertResponse: function(data) {
+ if (data.returnValues.template === '') {
+ // comment id is invalid or there is a mismatch, silently ignore it
+ return;
+ }
+
+ $(data.returnValues.template).insertBefore(this._permalinkResponse);
+ var response = this._permalinkResponse.previousElementSibling;
+ response.classList.add('commentResponsePermalinkContainer');
+
+ elRemove(this._permalinkResponse);
+ this._permalinkResponse = response;
+
+ //noinspection BadExpressionStatementJS
+ response.offsetTop;
+
+ response.classList.add('commentHighlightTarget');
},
/**
/**
* @inheritDoc
*/
- protected $allowGuestAccess = ['addComment', 'addResponse', 'loadComment', 'loadComments', 'getGuestDialog'];
+ protected $allowGuestAccess = ['addComment', 'addResponse', 'loadComment', 'loadComments', 'loadResponse', 'getGuestDialog'];
/**
* captcha object type used for comments
public function validateLoadComment() {
$this->readInteger('objectID', false, 'data');
+ $this->readInteger('responseID', true, 'data');
try {
$this->comment = $this->getSingleObject()->getDecoratedObject();
if (!$this->commentProcessor->isAccessible($this->parameters['data']['objectID'])) {
throw new PermissionDeniedException();
}
+
+ if (!empty($this->parameters['data']['responseID'])) {
+ $this->response = new CommentResponse($this->parameters['data']['responseID']);
+ if (!$this->response->responseID) {
+ $this->response = null;
+ }
+ }
}
public function loadComment() {
return ['template' => ''];
}
+ $returnValues = $this->renderComment($this->comment, $this->response);
+ return (is_array($returnValues)) ? $returnValues : ['template' => $returnValues];
+ }
+
+ public function validateLoadResponse() {
+ $this->validateLoadComment();
+ }
+
+ public function loadResponse() {
+ if ($this->comment === null || $this->response === null) {
+ return ['template' => ''];
+ }
+ else if ($this->comment->objectTypeID != $this->parameters['data']['objectTypeID'] || $this->comment->objectID != $this->parameters['data']['objectID']) {
+ return ['template' => ''];
+ }
+
return [
- 'template' => $this->renderComment($this->comment)
+ 'template' => $this->renderResponse($this->response)
];
}
* Renders a comment.
*
* @param Comment $comment
- * @return string
+ * @param CommentResponse $response
+ * @return string|string[]
*/
- protected function renderComment(Comment $comment) {
+ protected function renderComment(Comment $comment, CommentResponse $response = null) {
$comment = new StructuredComment($comment);
$comment->setIsDeletable($this->commentProcessor->canDeleteComment($comment->getDecoratedObject()));
$comment->setIsEditable($this->commentProcessor->canEditComment($comment->getDecoratedObject()));
+ if ($response !== null) {
+ // check if response is not visible
+ /** @var CommentResponse $visibleResponse */
+ foreach ($comment as $visibleResponse) {
+ if ($visibleResponse->responseID == $response->responseID) {
+ $response = null;
+ break;
+ }
+ }
+ }
+
WCF::getTPL()->assign([
'commentList' => [$comment],
'commentManager' => $this->commentProcessor
]);
- return WCF::getTPL()->fetch('commentList');
+
+ $template = WCF::getTPL()->fetch('commentList');
+ if ($response === null) {
+ return $template;
+ }
+
+ return [
+ 'template' => $template,
+ 'response' => $this->renderResponse($response)
+ ];
}
/**