2016-06-12 14:04:42 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-17 20:25:44 +02:00
|
|
|
const events = require('../events.js');
|
2016-06-12 14:04:42 +02:00
|
|
|
const views = require('../util/views.js');
|
|
|
|
const CommentListControl = require('../controls/comment_list_control.js');
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
const template = views.getTemplate('comments-page');
|
|
|
|
|
2016-06-17 20:25:44 +02:00
|
|
|
class CommentsPageView extends events.EventTarget {
|
2016-06-14 10:31:48 +02:00
|
|
|
constructor(ctx) {
|
2016-06-17 20:25:44 +02:00
|
|
|
super();
|
2016-06-14 10:31:48 +02:00
|
|
|
this._hostNode = ctx.hostNode;
|
2016-06-12 14:04:42 +02:00
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
const sourceNode = template(ctx);
|
2016-06-12 14:04:42 +02:00
|
|
|
|
2017-02-09 00:48:06 +01:00
|
|
|
for (let post of ctx.response.results) {
|
2016-06-17 20:25:44 +02:00
|
|
|
const commentListControl = new CommentListControl(
|
|
|
|
sourceNode.querySelector(
|
|
|
|
`.comments-container[data-for="${post.id}"]`),
|
|
|
|
post.comments,
|
|
|
|
true);
|
2016-08-22 20:45:58 +02:00
|
|
|
events.proxyEvent(commentListControl, this, 'submit');
|
2016-06-17 20:25:44 +02:00
|
|
|
events.proxyEvent(commentListControl, this, 'score');
|
|
|
|
events.proxyEvent(commentListControl, this, 'delete');
|
2016-06-12 14:04:42 +02:00
|
|
|
}
|
|
|
|
|
2016-06-14 10:31:48 +02:00
|
|
|
views.replaceContent(this._hostNode, sourceNode);
|
2016-06-12 14:04:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = CommentsPageView;
|