From 0c8658b2a68a8e12f5e87bc82952e40ae3324a00 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 14 May 2018 16:38:21 +0200 Subject: inline comment and delete --- public/assets/js/lib/views/details/commentform.js | 11 +++++++---- public/assets/js/lib/views/details/comments.js | 11 +++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'public/assets/js/lib/views') diff --git a/public/assets/js/lib/views/details/commentform.js b/public/assets/js/lib/views/details/commentform.js index 7f04ec3..d4a9149 100644 --- a/public/assets/js/lib/views/details/commentform.js +++ b/public/assets/js/lib/views/details/commentform.js @@ -10,8 +10,8 @@ var CommentForm = FormView.extend({ action: "", - initialize: function(){ - this.__super__.initialize.call(this) + initialize: function(opt){ + this.__super__.initialize.call(this, opt) this.template = this.$(".template").html() this.$comment = this.$("[name=comment]") }, @@ -48,9 +48,12 @@ var CommentForm = FormView.extend({ return errors.length ? errors : null }, - success: function(){ + success: function(data){ $("[name=comment").val('') $("[name=files").val('') - window.location.reload() + // window.location.reload() + console.log(this) + console.log(this.parent) + this.parent.comments.load([data.comment]) } }) diff --git a/public/assets/js/lib/views/details/comments.js b/public/assets/js/lib/views/details/comments.js index 688750c..b1c86bb 100644 --- a/public/assets/js/lib/views/details/comments.js +++ b/public/assets/js/lib/views/details/comments.js @@ -15,6 +15,8 @@ var CommentsView = FormView.extend({ }, load: function(comments, thread){ +console.log(comments) + thread = this.thread = thread || this.thread if (thread.settings.hootbox) { comments .sort((a,b) => cmp(a.date, b.date)) @@ -61,6 +63,10 @@ var CommentsView = FormView.extend({ var $el = this.parse(comment) $el.insertBefore(this.$formRow) }, + + removeComment: function(id) { + this.$("[title='" + id + "']").closest('tr').remove() + }, success: function(){ this.prependComment(comment) @@ -83,8 +89,9 @@ var CommentsView = FormView.extend({ url: "/api/comment/" + id, headers: { "csrf-token": $("[name=_csrf]").attr("value") }, data: { csrf: csrf() }, - success: function(){ - window.location.reload() + success: () => { + this.removeComment(id) + // window.location.reload() }, }) } -- cgit v1.2.3-70-g09d2