Commit d6bece9b by Matthew Mongeau

Move user to window. Mark followed threads in list view.

parent 4735ce0a
...@@ -4,7 +4,6 @@ class @DiscussionRouter extends Backbone.Router ...@@ -4,7 +4,6 @@ class @DiscussionRouter extends Backbone.Router
":forum_name/threads/:thread_id" : "showThread" ":forum_name/threads/:thread_id" : "showThread"
initialize: (options) -> initialize: (options) ->
@user = options['user']
@discussion = options['discussion'] @discussion = options['discussion']
@nav = new DiscussionThreadListView(collection: @discussion, el: $(".post-list")) @nav = new DiscussionThreadListView(collection: @discussion, el: $(".post-list"))
@nav.on "thread:selected", @navigateToThread @nav.on "thread:selected", @navigateToThread
...@@ -16,7 +15,7 @@ class @DiscussionRouter extends Backbone.Router ...@@ -16,7 +15,7 @@ class @DiscussionRouter extends Backbone.Router
showThread: (forum_name, thread_id) -> showThread: (forum_name, thread_id) ->
@nav.setActiveThread(thread_id) @nav.setActiveThread(thread_id)
thread = @discussion.get(thread_id) thread = @discussion.get(thread_id)
view = new DiscussionThreadView(el: $(".discussion-column"), model: thread, user: @user) view = new DiscussionThreadView(el: $(".discussion-column"), model: thread)
view.render() view.render()
navigateToThread: (thread_id) => navigateToThread: (thread_id) =>
......
...@@ -5,7 +5,6 @@ class @DiscussionThreadView extends Backbone.View ...@@ -5,7 +5,6 @@ class @DiscussionThreadView extends Backbone.View
template: _.template($("#thread-template").html()) template: _.template($("#thread-template").html())
initialize: (options) -> initialize: (options) ->
@user = options['user']
@model.bind "change", @updateModelDetails @model.bind "change", @updateModelDetails
@$el.html(@template(@model.toJSON())) @$el.html(@template(@model.toJSON()))
...@@ -13,10 +12,10 @@ class @DiscussionThreadView extends Backbone.View ...@@ -13,10 +12,10 @@ class @DiscussionThreadView extends Backbone.View
@$(".votes-count-number").html(@model.get("votes")["up_count"]) @$(".votes-count-number").html(@model.get("votes")["up_count"])
render: -> render: ->
if @user.following(@model) if window.user.following(@model)
@$(".dogear").addClass("is-followed") @$(".dogear").addClass("is-followed")
if @user.voted(@model) if window.user.voted(@model)
@$(".vote-btn").addClass("is-cast") @$(".vote-btn").addClass("is-cast")
@$("span.timeago").timeago() @$("span.timeago").timeago()
@renderResponses() @renderResponses()
......
...@@ -7,6 +7,8 @@ class @ThreadListItemView extends Backbone.View ...@@ -7,6 +7,8 @@ class @ThreadListItemView extends Backbone.View
@model.on "change", @render @model.on "change", @render
render: => render: =>
@$el.html(@template(@model.toJSON())) @$el.html(@template(@model.toJSON()))
if window.user.following(@model)
@$("a").addClass("followed")
@ @
threadSelected: -> threadSelected: ->
@trigger("thread:selected", @model.id) @trigger("thread:selected", @model.id)
......
...@@ -143,10 +143,10 @@ ...@@ -143,10 +143,10 @@
$$contents = {} $$contents = {}
$$discussions = {} $$discussions = {}
$(document).ready(function() { $(document).ready(function() {
var user = new DiscussionUser(JSON.parse("${user_info | escapejs}")); window.user = new DiscussionUser(JSON.parse("${user_info | escapejs}"));
var discussion = new Discussion(JSON.parse("${threads | escapejs}")); var discussion = new Discussion(JSON.parse("${threads | escapejs}"));
var app = new DiscussionRouter({user: user, discussion: discussion}) var app = new DiscussionRouter({discussion: discussion})
Backbone.history.start({pushState: true, root: "/courses/${course_id}/discussion/forum/"}) Backbone.history.start({pushState: true, root: "/courses/${course_id}/discussion/forum/"})
}); });
</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