2020-06-06 00:03:37 +02:00
|
|
|
"use strict";
|
2016-06-12 14:04:42 +02:00
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
const events = require("../events.js");
|
|
|
|
const views = require("../util/views.js");
|
|
|
|
const CommentListControl = require("../controls/comment_list_control.js");
|
2016-06-12 14:04:42 +02:00
|
|
|
|
2020-06-06 00:03:37 +02:00
|
|
|
const template = views.getTemplate("comments-page");
|
2016-06-14 10:31:48 +02:00
|
|
|
|
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(
|
2020-06-06 00:03:37 +02:00
|
|
|
`.comments-container[data-for="${post.id}"]`
|
|
|
|
),
|
2016-06-17 20:25:44 +02:00
|
|
|
post.comments,
|
2020-06-06 00:03:37 +02:00
|
|
|
true
|
|
|
|
);
|
|
|
|
events.proxyEvent(commentListControl, this, "submit");
|
|
|
|
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;
|