Commit 41b669d6 by Matthew Mongeau

Show current following status in list view.

parent 7f67fc5a
...@@ -421,6 +421,12 @@ if Backbone? ...@@ -421,6 +421,12 @@ if Backbone?
@set('thread', @) @set('thread', @)
super() super()
follow: ->
@trigger "thread:follow"
unfollow: ->
@trigger "thread:unfollow"
class @ThreadView extends @ContentView class @ThreadView extends @ContentView
class @Comment extends @Content class @Comment extends @Content
......
...@@ -44,8 +44,10 @@ class @DiscussionThreadView extends Backbone.View ...@@ -44,8 +44,10 @@ class @DiscussionThreadView extends Backbone.View
@$(".dogear").toggleClass("is-followed") @$(".dogear").toggleClass("is-followed")
url = null url = null
if @$(".dogear").hasClass("is-followed") if @$(".dogear").hasClass("is-followed")
@model.follow()
url = @model.urlFor("follow") url = @model.urlFor("follow")
else else
@model.unfollow()
url = @model.urlFor("unfollow") url = @model.urlFor("unfollow")
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
$elem: $elem $elem: $elem
......
...@@ -5,11 +5,17 @@ class @ThreadListItemView extends Backbone.View ...@@ -5,11 +5,17 @@ class @ThreadListItemView extends Backbone.View
"click a": "threadSelected" "click a": "threadSelected"
initialize: -> initialize: ->
@model.on "change", @render @model.on "change", @render
@model.on "thread:follow", @follow
@model.on "thread:unfollow", @unfollow
render: => render: =>
@$el.html(@template(@model.toJSON())) @$el.html(@template(@model.toJSON()))
if window.user.following(@model) if window.user.following(@model)
@$("a").addClass("followed") @follow()
@ @
threadSelected: -> threadSelected: ->
@trigger("thread:selected", @model.id) @trigger("thread:selected", @model.id)
false false
follow: =>
@$("a").addClass("followed")
unfollow: =>
@$("a").removeClass("followed")
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