diff options
Diffstat (limited to 'static/js/controllers/replies_controller.js')
-rw-r--r-- | static/js/controllers/replies_controller.js | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/static/js/controllers/replies_controller.js b/static/js/controllers/replies_controller.js index 3bdf831..af0f2ec 100644 --- a/static/js/controllers/replies_controller.js +++ b/static/js/controllers/replies_controller.js @@ -1,18 +1,44 @@ import { BaseController } from "./base_controller.js"; export class RepliesController extends BaseController { - constructor(domain) { - super(domain); - this.reply_form = this.getReplyForm(); + constructor() { + super(); } - getReplyForm() { - var form; - - this.get("/api/replies/new").then((response) => { - form = value?.getElementById("reply-form"); - }); + async init() { + this.reply_form = await this.getReplyForm(); + this.listenButtons("replies-button", this.showReplies.bind(this)); + this.listenButtons("new-reply-button", this.showReplyForm.bind(this)); + } + + listenButtons(class_name, func) { + const buttons = document.getElementsByClassName(class_name); + + if(buttons) { + for(let button of buttons) + button.addEventListener("click", func); + } + } + + showReplyForm(event) { + const replies_section = event.target.parentElement.parentElement.childNodes[3]; + + if(replies_section.querySelector(".reply-form") == null) + replies_section.appendChild(this.reply_form); + /*else hide*/ + } + + showReplies(event) { + /* The div to contain the comment's replies. From the element id + we can get the comment's id. */ + const replies_section = event.target.parentElement.parentElement.childNodes[3]; + const comment_id = /\d/.exec(replies_section.id)[0] + console.log("You're in showReplies()"); + } + + async getReplyForm() { + var form = await this.get("/api/replies/new"); - return form; + return form.getElementsByClassName("reply-form")[0]; } } |