client/comments: add comment list view for post

This commit is contained in:
rr-
2016-06-11 17:41:28 +02:00
parent 0908323290
commit 7e8a9a0948
18 changed files with 581 additions and 59 deletions

View File

@ -0,0 +1,41 @@
'use strict';
const api = require('../api.js');
const views = require('../util/views.js');
const CommentControl = require('../controls/comment_control.js');
class CommentListControl {
constructor(hostNode, comments) {
this._hostNode = hostNode;
this._comments = comments;
this._template = views.getTemplate('comment-list');
this.install();
}
install() {
const sourceNode = this._template({
comments: this._comments,
canListComments: api.hasPrivilege('comments:list'),
});
views.showView(this._hostNode, sourceNode);
this._renderComments();
}
_renderComments() {
if (!this._comments.length) {
return;
}
const commentList = new DocumentFragment();
for (let comment of this._comments) {
const commentListItemNode = document.createElement('li');
new CommentControl(commentListItemNode, comment);
commentList.appendChild(commentListItemNode);
}
views.showView(this._hostNode.querySelector('ul'), commentList);
}
};
module.exports = CommentListControl;