Commit dd054237 by Greg Price

Re-render forum responses when marked as answer

parent aaa2f353
......@@ -3,4 +3,4 @@ class @DiscussionSpecHelper
@setUpGlobals = ->
DiscussionUtil.loadRoles({"Moderator": [], "Administrator": [], "Community TA": []})
window.$$course_id = "edX/999/test"
window.user = new DiscussionUser({id: "567", upvoted_ids: []})
window.user = new DiscussionUser({username: "test_user", id: "567", upvoted_ids: []})
......@@ -97,3 +97,14 @@ describe "ThreadResponseShowView", ->
@view.render()
expect(@view.$(".posted-details").text()).toMatch("marked as answer less than a minute ago")
expect(@view.$(".posted-details").text()).not.toMatch(" by ")
it "re-renders correctly when endorsement changes", ->
@thread.set("thread_type", "question")
@comment.updateInfo({"ability": {"can_endorse": true}})
expect(@view.$(".posted-details").text()).not.toMatch("marked as answer")
@view.$(".action-endorse").click()
expect(@view.$(".posted-details").text()).toMatch(
"marked as answer less than a minute ago by " + user.get("username")
)
@view.$(".action-endorse").click()
expect(@view.$(".posted-details").text()).not.toMatch("marked as answer")
......@@ -17,7 +17,7 @@ if Backbone?
initialize: ->
super()
@model.on "change", @updateModelDetails
@listenTo(@model, "change", @render)
renderTemplate: ->
@template = _.template($("#thread-response-show-template").html())
......@@ -60,8 +60,16 @@ if Backbone?
$elem = $(event.target)
url = @model.urlFor('endorse')
endorsed = @model.get('endorsed')
data = { endorsed: not endorsed }
@model.set('endorsed', not endorsed)
new_endorsed = not endorsed
data = { endorsed: new_endorsed }
endorsement = {
"username": window.user.get("username"),
"time": new Date().toISOString()
}
@model.set(
"endorsed": new_endorsed
"endorsement": if new_endorsed then endorsement else null
)
@trigger "comment:endorse", not endorsed
DiscussionUtil.safeAjax
$elem: $elem
......@@ -86,7 +94,3 @@ if Backbone?
@$("[data-role=thread-flag]").addClass("notflagged")
@$(".discussion-flag-abuse").attr("aria-pressed", "false")
@$(".discussion-flag-abuse .flag-label").html(gettext("Report Misuse"))
updateModelDetails: =>
@renderVote()
@renderFlagged()
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