From b39de8cc12c83029168f311a7d3e4ddd96d52635 Mon Sep 17 00:00:00 2001 From: julian laplace Date: Fri, 28 Oct 2022 13:47:06 +0200 Subject: toggle form --- public/assets/js/lib/views/stream/hootstream.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'public/assets/js/lib/views/stream/hootstream.js') diff --git a/public/assets/js/lib/views/stream/hootstream.js b/public/assets/js/lib/views/stream/hootstream.js index dcac22c..4a846d7 100644 --- a/public/assets/js/lib/views/stream/hootstream.js +++ b/public/assets/js/lib/views/stream/hootstream.js @@ -5,7 +5,6 @@ var HootStream = View.extend({ "click a": "onClickLink", "click .filename": "onClickFilename", "click .action": "onClickAction", - "submit .streamForm form": "onSubmitComment", }, initialize: function ({ parent }) { @@ -20,6 +19,7 @@ var HootStream = View.extend({ this.commentFormTemplate = this.$(".commentFormTemplate").html(); this.onClickLink = this.onClickLink.bind(this); this.onClickFilename = this.onClickFilename.bind(this); + this.forms = {}; }, onClickLink: function (event) { @@ -118,15 +118,31 @@ var HootStream = View.extend({ }, onShowCommentForm: function (event, thread) { + if (this.forms[thread]) { + this.forms[thread].hide(); + this.forms[thread].$el.remove(); + this.forms[thread] = null; + return; + } const $threadTitle = $(event.target).closest(".threadTitle"); const $form = $(this.commentFormTemplate); $form.data("thread", thread); $form.insertAfter($threadTitle); $form.find("textarea").focus(); + const commentForm = new CommentForm({ parent: this }); + commentForm.action = `/api/thread/${thread}/comment`; + commentForm.setElement($form); + commentForm.initialize({ + parent: this, + onSubmit: this.onSubmitComment.bind(this), + }); + this.forms[thread] = commentForm; }, onSubmitComment: function (event) { event.preventDefault(); + console.log("onsubmit"); + this.forms[thread] = null; }, load: function (data, filters) { -- cgit v1.2.3-70-g09d2