diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index f8b130e328..601efa8122 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -65,7 +65,9 @@ def create_thread(request, course_id, commentable_id): 'thread': response, } html = render_to_string('discussion/ajax_thread_only.html', context) - return HtmlResponse(html) + return JsonResponse({ + 'html': html, + }) else: return JsonResponse(response) diff --git a/lms/static/coffee/src/discussion/content.coffee b/lms/static/coffee/src/discussion/content.coffee index c53800782d..b60020cf3d 100644 --- a/lms/static/coffee/src/discussion/content.coffee +++ b/lms/static/coffee/src/discussion/content.coffee @@ -66,6 +66,7 @@ Discussion = @Discussion $elem: $(elem) url: url type: "POST" + dataType: 'json' data: body: body anonymous: anonymous @@ -80,7 +81,6 @@ Discussion = @Discussion $local(".discussion-reply-new").hide() $discussionContent.attr("status", "normal") ) - dataType: 'json' handleVote = (elem, value) -> contentType = if $content.hasClass("thread") then "thread" else "comment" @@ -128,10 +128,11 @@ Discussion = @Discussion $.ajax url: url type: "POST" - data: {title: title, body: body, tags: tags}, - success: Discussion.formErrorHandler $local(".discussion-update-errors"), (response, textStatus) -> - Discussion.handleAnchorAndReload(response) dataType: 'json' + data: {title: title, body: body, tags: tags}, + success: Discussion.formErrorHandler($local(".discussion-update-errors"), (response, textStatus) -> + Discussion.handleAnchorAndReload(response) + ) handleEditComment = (elem) -> $local(".discussion-content-wrapper").hide() @@ -150,11 +151,12 @@ Discussion = @Discussion body = Discussion.getWmdContent $content, $local, "comment-body-edit" $.ajax url: url - data: {body: body} type: "POST" - success: Discussion.formErrorHandler $local(".discussion-update-errors"), (response, textStatus) -> - Discussion.handleAnchorAndReload(response) dataType: "json" + data: {body: body} + success: Discussion.formErrorHandler($local(".discussion-update-errors"), (response, textStatus) -> + Discussion.handleAnchorAndReload(response) + ) handleEndorse = (elem) -> url = Discussion.urlFor('endorse_comment', id) @@ -196,6 +198,7 @@ Discussion = @Discussion $elem: $.merge($threadTitle, $showComments) url: url type: "GET" + dataType: 'json' success: (response, textStatus) -> if not $$annotated_content_info? window.$$annotated_content_info = {} @@ -205,7 +208,6 @@ Discussion = @Discussion Discussion.initializeContent(comment) Discussion.bindContentEvents(comment) rebindHideEvents() - dataType: 'json' Discussion.bindLocalEvents $local, diff --git a/lms/static/coffee/src/discussion/discussion.coffee b/lms/static/coffee/src/discussion/discussion.coffee index 0f96609fe2..5b90b08caa 100644 --- a/lms/static/coffee/src/discussion/discussion.coffee +++ b/lms/static/coffee/src/discussion/discussion.coffee @@ -94,14 +94,25 @@ initializeFollowThread = (index, thread) -> body = Discussion.getWmdContent $discussion, $local, "new-post-body" tags = $local(".new-post-tags").val() url = Discussion.urlFor('create_thread', $local(".new-post-form").attr("_id")) - $.post url, {title: title, body: body, tags: tags}, (response, textStatus) -> - if response.errors - errorsField = $local(".discussion-errors").empty() - for error in response.errors - errorsField.append($("
  • ").addClass("new-post-form-error").html(error)) - else - Discussion.handleAnchorAndReload(response) - , 'json' + Discussion.safeAjax + $elem: $(elem) + url: url + type: "POST" + dataType: 'json' + data: + title: title + body: body + tags: tags + success: Discussion.formErrorHandler($local(".new-post-form-error"), (response, textStatus) -> + console.log response + $thread = $(response.html) + $discussion.children(".threads").prepend($thread) + Discussion.setWmdContent $discussion, $local, "new-post-body", "" + Discussion.initializeContent($thread) + Discussion.bindContentEvents($thread) + $(".new-post-form").hide() + $local(".discussion-new-post").show() + ) handleCancelNewPost = (elem) -> $local(".new-post-form").hide() diff --git a/lms/templates/discussion/_forum.html b/lms/templates/discussion/_forum.html index f98c538f34..080305f5d3 100644 --- a/lms/templates/discussion/_forum.html +++ b/lms/templates/discussion/_forum.html @@ -15,9 +15,11 @@
    New Post
    <%include file="_sort.html" /> - % for thread in threads: - ${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)} - % endfor +
    + % for thread in threads: + ${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)} + % endfor +
    <%include file="_paginator.html" /> diff --git a/lms/templates/discussion/_inline.html b/lms/templates/discussion/_inline.html index c779499792..70681b1cf4 100644 --- a/lms/templates/discussion/_inline.html +++ b/lms/templates/discussion/_inline.html @@ -8,9 +8,11 @@
    New Post
    <%include file="_sort.html" /> - % for thread in threads: - ${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)} - % endfor +
    + % for thread in threads: + ${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)} + % endfor +
    <%include file="_paginator.html" />