Comment details and comment voting.
This commit is contained in:
@@ -37,6 +37,7 @@ class @DiscussionThreadView extends Backbone.View
|
||||
@vote()
|
||||
else
|
||||
@unvote()
|
||||
false
|
||||
|
||||
toggleFollowing: (event) ->
|
||||
$elem = $(event.target)
|
||||
|
||||
@@ -3,4 +3,5 @@ class @ResponseCommentView extends Backbone.View
|
||||
template: _.template($("#response-comment-template").html())
|
||||
render: ->
|
||||
@$el.html(@template(@model.toJSON()))
|
||||
@$(".timeago").timeago()
|
||||
@
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
class @ThreadResponseView extends Backbone.View
|
||||
tagName: "li"
|
||||
template: _.template($("#thread-response-template").html())
|
||||
events:
|
||||
"click .vote-btn": "toggleVote"
|
||||
render: ->
|
||||
@$el.html(@template(@model.toJSON()))
|
||||
if window.user.voted(@model)
|
||||
@$(".vote-btn").addClass("is-cast")
|
||||
@$(".posted-details").timeago()
|
||||
@renderComments()
|
||||
@
|
||||
|
||||
@@ -12,4 +17,34 @@ class @ThreadResponseView extends Backbone.View
|
||||
renderComment: (comment) =>
|
||||
view = new ResponseCommentView(model: comment)
|
||||
view.render()
|
||||
@$(".comments").append(view.el)
|
||||
@$(".comments li:last").before(view.el)
|
||||
|
||||
toggleVote: ->
|
||||
@$(".vote-btn").toggleClass("is-cast")
|
||||
if @$(".vote-btn").hasClass("is-cast")
|
||||
@vote()
|
||||
else
|
||||
@unvote()
|
||||
false
|
||||
|
||||
vote: ->
|
||||
url = @model.urlFor("upvote")
|
||||
@$(".votes-count-number").html(parseInt(@$(".votes-count-number").html()) + 1)
|
||||
DiscussionUtil.safeAjax
|
||||
$elem: @$(".discussion-vote")
|
||||
url: url
|
||||
type: "POST"
|
||||
success: (response, textStatus) =>
|
||||
if textStatus == 'success'
|
||||
@model.set(response)
|
||||
|
||||
unvote: ->
|
||||
url = @model.urlFor("unvote")
|
||||
@$(".votes-count-number").html(parseInt(@$(".votes-count-number").html()) - 1)
|
||||
DiscussionUtil.safeAjax
|
||||
$elem: @$(".discussion-vote")
|
||||
url: url
|
||||
type: "POST"
|
||||
success: (response, textStatus) =>
|
||||
if textStatus == 'success'
|
||||
@model.set(response)
|
||||
|
||||
Reference in New Issue
Block a user