Commit 7ece39f3 by Tom Giannattasio

Merge branch 'feature/tomg/new-discussions' of github.com:MITx/mitx into…

Merge branch 'feature/tomg/new-discussions' of github.com:MITx/mitx into feature/tomg/new-discussions
parents 757c817b 3cc3876b
class @DiscussionThreadView extends Backbone.View class @DiscussionThreadView extends Backbone.View
events: events:
"click .discussion-vote-up": "toggleVote" "click .discussion-vote": "toggleVote"
"click .dogear": "toggleFollowing" "click .dogear": "toggleFollowing"
"click .discussion-submit-post": "submitComment"
template: _.template($("#thread-template").html()) template: _.template($("#thread-template").html())
initialize: (options) -> initialize: (options) ->
...@@ -9,7 +10,7 @@ class @DiscussionThreadView extends Backbone.View ...@@ -9,7 +10,7 @@ class @DiscussionThreadView extends Backbone.View
@$el.html(@template(@model.toJSON())) @$el.html(@template(@model.toJSON()))
updateModelDetails: => updateModelDetails: =>
@$(".votes-count-number").html(@model.get("votes")["up_count"]) @$(".discussion-vote .votes-count-number").html(@model.get("votes")["up_count"])
render: -> render: ->
if window.user.following(@model) if window.user.following(@model)
...@@ -18,10 +19,16 @@ class @DiscussionThreadView extends Backbone.View ...@@ -18,10 +19,16 @@ class @DiscussionThreadView extends Backbone.View
if window.user.voted(@model) if window.user.voted(@model)
@$(".vote-btn").addClass("is-cast") @$(".vote-btn").addClass("is-cast")
@$("span.timeago").timeago() @$("span.timeago").timeago()
DiscussionUtil.makeWmdEditor @$el, $.proxy(@$, @), "reply-body" Markdown.makeWmdEditor @$(".reply-body"), "", DiscussionUtil.urlFor("upload"), (text) -> DiscussionUtil.postMathJaxProcessor(text)
@convertMath()
@renderResponses() @renderResponses()
@ @
convertMath: ->
element = @$(".post-body")
element.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight element.html()
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element.attr("id")]
renderResponses: -> renderResponses: ->
$.ajax @model.id, success: (data, textStatus, xhr) => $.ajax @model.id, success: (data, textStatus, xhr) =>
comments = new Comments(data['content']['children']) comments = new Comments(data['content']['children'])
...@@ -37,8 +44,8 @@ class @DiscussionThreadView extends Backbone.View ...@@ -37,8 +44,8 @@ class @DiscussionThreadView extends Backbone.View
@model.trigger "comment:add" @model.trigger "comment:add"
toggleVote: -> toggleVote: ->
@$(".vote-btn").toggleClass("is-cast") @$(".discussion-vote").toggleClass("is-cast")
if @$(".vote-btn").hasClass("is-cast") if @$(".discussion-vote").hasClass("is-cast")
@vote() @vote()
else else
@unvote() @unvote()
...@@ -61,7 +68,7 @@ class @DiscussionThreadView extends Backbone.View ...@@ -61,7 +68,7 @@ class @DiscussionThreadView extends Backbone.View
vote: -> vote: ->
url = @model.urlFor("upvote") url = @model.urlFor("upvote")
@$(".votes-count-number").html(parseInt(@$(".votes-count-number").html()) + 1) @$(".discussion-vote .votes-count-number").html(parseInt(@$(".discussion-vote .votes-count-number").html()) + 1)
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
$elem: @$(".discussion-vote") $elem: @$(".discussion-vote")
url: url url: url
...@@ -72,7 +79,7 @@ class @DiscussionThreadView extends Backbone.View ...@@ -72,7 +79,7 @@ class @DiscussionThreadView extends Backbone.View
unvote: -> unvote: ->
url = @model.urlFor("unvote") url = @model.urlFor("unvote")
@$(".votes-count-number").html(parseInt(@$(".votes-count-number").html()) - 1) @$(".discussion-vote .votes-count-number").html(parseInt(@$(".discussion-vote .votes-count-number").html()) - 1)
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
$elem: @$(".discussion-vote") $elem: @$(".discussion-vote")
url: url url: url
...@@ -80,3 +87,18 @@ class @DiscussionThreadView extends Backbone.View ...@@ -80,3 +87,18 @@ class @DiscussionThreadView extends Backbone.View
success: (response, textStatus) => success: (response, textStatus) =>
if textStatus == 'success' if textStatus == 'success'
@model.set(response) @model.set(response)
submitComment: ->
url = @model.urlFor('reply')
body = @$("#wmd-input").val()
response = new Comment(body: body, created_at: (new Date()).toISOString(), username: window.user.get("username"), votes: { up_count: 0 })
@renderResponse(response)
DiscussionUtil.safeAjax
$elem: $(event.target)
url: url
type: "POST"
dataType: 'json'
data:
body: body
false
...@@ -10,9 +10,15 @@ class @ThreadResponseView extends Backbone.View ...@@ -10,9 +10,15 @@ class @ThreadResponseView extends Backbone.View
if window.user.voted(@model) if window.user.voted(@model)
@$(".vote-btn").addClass("is-cast") @$(".vote-btn").addClass("is-cast")
@$(".posted-details").timeago() @$(".posted-details").timeago()
@convertMath()
@renderComments() @renderComments()
@ @
convertMath: ->
element = @$(".response-body")
element.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight element.html()
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element.attr("id")]
renderComments: -> renderComments: ->
@model.get("comments").each @renderComment @model.get("comments").each @renderComment
......
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