From 4c775f12ff6eda48fc22bec9ed336e60c1a0e07e Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 11 Dec 2017 04:25:19 +0100 Subject: cssssssss --- public/assets/js/lib/views/details/comments.js | 27 ++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'public/assets/js/lib/views/details/comments.js') diff --git a/public/assets/js/lib/views/details/comments.js b/public/assets/js/lib/views/details/comments.js index c031efc..65473c6 100644 --- a/public/assets/js/lib/views/details/comments.js +++ b/public/assets/js/lib/views/details/comments.js @@ -5,6 +5,7 @@ var CommentsView = FormView.extend({ events: { "focus textarea": "focus", "blur textarea": "blur", + "click .remove": "remove", }, initialize: function(){ @@ -18,22 +19,26 @@ var CommentsView = FormView.extend({ }, parse: function(comment){ - if (! comment.comment.length) return "" + if (! comment.comment.length) return $('
') var datetime = verbose_date(comment.date, true) var t = this.template.replace(/{{username}}/g, comment.username) + .replace(/{{id}}/g, comment.id) .replace(/{{comment}}/g, tidy_urls(comment.comment)) .replace(/{{date}}/g, datetime[0]) .replace(/{{time}}/g, datetime[1]) - return t + console.log(t) + var $t = $(t) + return $t }, prependComment: function(comment){ - var $el = $( this.parse(comment) ) + var $el = this.parse(comment) this.$el.prepend($el) }, appendComment: function(comment){ - var $el = $( this.parse(comment) ) + var $el = this.parse(comment) + console.log($el) $el.insertBefore(this.$formRow) }, @@ -48,5 +53,19 @@ var CommentsView = FormView.extend({ blur: function(){ app.typing = false }, + + remove: function(e){ + var id = $(e.target).data('id') + var should_remove = confirm("Are you sure you want to delete this comment? #" + id) + if (should_remove) { + $.ajax({ + method: "DELETE", + url: "/api/comment/" + id, + success: function(){ + window.location.reload() + }, + }) + } + }, }) \ No newline at end of file -- cgit v1.2.3-70-g09d2