Commit f23c8fa0 by Matthew Mongeau

Comment details and comment voting.

parent 30a42dd5
......@@ -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()
@
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)
......@@ -127,13 +127,23 @@
</script>
<script type="text/template" id="thread-response-template">
<header>
<a href="#" class="vote-btn" data-tooltip="vote"><span class="plus-icon"></span><span class="votes-count-number">${"<%= votes['up_count'] %>"}</span></a>
<a href="#" class="posted-by">${"<%= username %>"}</a>
<p class="posted-details" title="${'<%= created_at %>'}">Sometime</p>
</header>
<div class="response-body">${"<%= body %>"}</div>
<ol class="comments">
<li>
<form class="comment-form">
<input type="text" placeholder="Comment…" class="comment-form-input">
</form>
</li>
</ol>
</script>
<script type="text/template" id="response-comment-template">
<p>${'<%= body %>'}</p>
<p>${'<%= body %>'}<span class="posted-details">posted <span class="timeago" title="${'<%= created_at %>'}">sometime</span> by <a href="#">${'<%= username %>'}</a></span></p>
</script>
<script type="text/template" id="thread-list-item-template">
......@@ -141,13 +151,14 @@
</script>
<script>
$$contents = {}
$$discussions = {}
$$contents = {};
$$discussions = {};
$$course_id = "${course_id}";
$(document).ready(function() {
window.user = new DiscussionUser(JSON.parse("${user_info | escapejs}"));
var discussion = new Discussion(JSON.parse("${threads | escapejs}"));
var app = new DiscussionRouter({discussion: discussion})
Backbone.history.start({pushState: true, root: "/courses/${course_id}/discussion/forum/"})
var app = new DiscussionRouter({discussion: discussion});
Backbone.history.start({pushState: true, root: "/courses/${course_id}/discussion/forum/"});
});
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment