diff options
Diffstat (limited to 'static/js/controllers/replies_controller.js')
-rw-r--r-- | static/js/controllers/replies_controller.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/static/js/controllers/replies_controller.js b/static/js/controllers/replies_controller.js index 5e67057..5d638a5 100644 --- a/static/js/controllers/replies_controller.js +++ b/static/js/controllers/replies_controller.js @@ -6,11 +6,16 @@ export class RepliesController extends BaseController { } async init() { + this.comment_id = 0; this.reply_form = await this.getReplyForm(); this.listenButtons("replies-button", this.showReplies.bind(this)); this.listenButtons("new-reply-button", this.showReplyForm.bind(this)); } + async submit(event) { + await super.submit(event, `${this.comments_server_host}/api/comments/${this.comment_id}/replies`); + } + listenButtons(class_name, func) { const buttons = document.getElementsByClassName(class_name); @@ -24,20 +29,27 @@ export class RepliesController extends BaseController { const replies_section = event.target.parentElement.parentElement.childNodes[3]; const form = replies_section.querySelector(".reply-form"); - if(form == null) + if(form == null) { replies_section.appendChild(this.reply_form); - else + this.setCommentId(replies_section); + this.reply_form.addEventListener("submit", this.submit.bind(this)); + } else form.remove(); } 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]; + this.setCommentId(event.target); console.log("You're in showReplies()"); } + setCommentId(parent) { + const replies_section = parent.parentElement.parentElement.childNodes[3]; + + this.comment_id = /\d/.exec(replies_section.id)[0]; + } + async getReplyForm() { var form = await this.get("/api/replies/new"); |