Comment details and comment voting.

This commit is contained in:
Matthew Mongeau
2012-08-29 16:23:59 -04:00
parent 30a42dd526
commit f23c8fa0d3
4 changed files with 54 additions and 6 deletions

View File

@@ -37,6 +37,7 @@ class @DiscussionThreadView extends Backbone.View
@vote()
else
@unvote()
false
toggleFollowing: (event) ->
$elem = $(event.target)

View File

@@ -3,4 +3,5 @@ class @ResponseCommentView extends Backbone.View
template: _.template($("#response-comment-template").html())
render: ->
@$el.html(@template(@model.toJSON()))
@$(".timeago").timeago()
@

View File

@@ -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)