summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/details/comments.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js/lib/views/details/comments.js')
-rw-r--r--public/assets/js/lib/views/details/comments.js27
1 files changed, 23 insertions, 4 deletions
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 $('<div></div>')
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