Commit 5ec864f7 by Matthew Mongeau

Hook up list to voting.

parent ee7ade41
...@@ -241,7 +241,8 @@ def single_thread(request, course_id, discussion_id, thread_id): ...@@ -241,7 +241,8 @@ def single_thread(request, course_id, discussion_id, thread_id):
'recent_active_threads': recent_active_threads, 'recent_active_threads': recent_active_threads,
'trending_tags': trending_tags, 'trending_tags': trending_tags,
'course_id': course.id, 'course_id': course.id,
'threads': threads, 'thread_id': thread_id,
'threads': json.dumps(threads),
} }
return render_to_response('discussion/single_thread.html', context) return render_to_response('discussion/single_thread.html', context)
......
...@@ -8,6 +8,23 @@ class @DiscussionUser ...@@ -8,6 +8,23 @@ class @DiscussionUser
voted: (thread) -> voted: (thread) ->
@content_info[thread.id]['voted'] == 'up' @content_info[thread.id]['voted'] == 'up'
class @ThreadListItemView extends Backbone.View
tagName: "li"
template: _.template($("#thread-list-item-template").html())
initialize: ->
@model.on "change", @render
render: =>
@$el.html(@template(@model.toJSON()))
@
class @DiscussionThreadListView extends Backbone.View
render: ->
@collection.each @renderThreadListItem
renderThreadListItem: (thread) =>
view = new ThreadListItemView(model: thread)
view.render()
@$el.append(view.el)
class @DiscussionThreadView extends Backbone.View class @DiscussionThreadView extends Backbone.View
events: events:
"click .discussion-vote-up": "toggleVote" "click .discussion-vote-up": "toggleVote"
......
...@@ -30,9 +30,6 @@ ...@@ -30,9 +30,6 @@
</div> </div>
<div class="post-list-wrapper"> <div class="post-list-wrapper">
<ul class="post-list"> <ul class="post-list">
% for discussion_thread in threads:
<li><a href="${helpers.permalink(discussion_thread) | h}"><span class="title">${discussion_thread['title'] | h}</span> <span class="comments-count">${discussion_thread['comments_count'] | h}</span><span class="votes-count">+${discussion_thread['votes']['up_count'] | h}</span></a></li>
% endfor
</ul> </ul>
</div> </div>
</div> </div>
...@@ -51,13 +48,22 @@ ...@@ -51,13 +48,22 @@
</div> </div>
</div> </div>
<script type="text/template" id="thread-list-item-template">
<a href="#"><span class="title">${"<%= title %>"}</span> <span class="comments-count">${"<%= comments_count %>"}</span><span class="votes-count">+${"<%= votes['up_count'] %>"}</span></a>
</script>
<script> <script>
$$contents = {} $$contents = {}
$$discussions = {} $$discussions = {}
$(document).ready(function() { $(document).ready(function() {
var user = new DiscussionUser(JSON.parse("${annotated_content_info | escapejs}")); var user = new DiscussionUser(JSON.parse("${annotated_content_info | escapejs}"));
var thread = new Thread(JSON.parse("${thread | escapejs}")); var discussion = new Discussion(JSON.parse("${threads | escapejs}"));
view = new DiscussionThreadView({el: $(".discussion-article"), model: thread, user: user})
view.render() list_view = new DiscussionThreadListView({collection: discussion, el: $(".post-list")});
list_view.render();
var thread = discussion.get("${thread_id | escapejs}")
view = new DiscussionThreadView({el: $(".discussion-article"), model: thread, user: user});
view.render();
}); });
</script> </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