Commit 7c9fcfbc by Rocky Duan

ajax submit new post

parent 4ceee380
......@@ -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)
......
......@@ -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"
dataType: 'json'
data: {title: title, body: body, tags: tags},
success: Discussion.formErrorHandler $local(".discussion-update-errors"), (response, textStatus) ->
success: Discussion.formErrorHandler($local(".discussion-update-errors"), (response, textStatus) ->
Discussion.handleAnchorAndReload(response)
dataType: 'json'
)
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,
......
......@@ -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($("<li>").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()
......
......@@ -15,9 +15,11 @@
<div class="discussion-new-post control-button" href="javascript:void(0)">New Post</div>
</div>
<%include file="_sort.html" />
% for thread in threads:
${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)}
% endfor
<div class="threads">
% for thread in threads:
${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)}
% endfor
</div>
<%include file="_paginator.html" />
</section>
......
......@@ -8,9 +8,11 @@
<div class="discussion-new-post control-button" href="javascript:void(0)">New Post</div>
<%include file="_sort.html" />
</div>
% for thread in threads:
${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)}
% endfor
<div class="threads">
% for thread in threads:
${renderer.render_thread(course_id, thread, edit_thread=False, show_comments=False)}
% endfor
</div>
<%include file="_paginator.html" />
</section>
......
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