Commit 452414da by Arjun Singh

Kill requests for loading responses when selecting another thread. This ensures…

Kill requests for loading responses when selecting another thread. This ensures that the thread you're viewing has the right responses loaded.
parent a9009981
...@@ -26,6 +26,7 @@ if Backbone? ...@@ -26,6 +26,7 @@ if Backbone?
@thread = @discussion.get(thread_id) @thread = @discussion.get(thread_id)
@setActiveThread() @setActiveThread()
if(@main) if(@main)
@main.cleanup()
@main.undelegateEvents() @main.undelegateEvents()
@main = new DiscussionThreadView(el: $(".discussion-column"), model: @thread) @main = new DiscussionThreadView(el: $(".discussion-column"), model: @thread)
......
...@@ -71,7 +71,7 @@ class @DiscussionUtil ...@@ -71,7 +71,7 @@ class @DiscussionUtil
params["loadingCallback"].apply(params["$loading"]) params["loadingCallback"].apply(params["$loading"])
else else
params["$loading"].loading() params["$loading"].loading()
$.ajax(params).always -> request = $.ajax(params).always ->
if $elem if $elem
$elem.removeAttr("disabled") $elem.removeAttr("disabled")
if params["$loading"] if params["$loading"]
...@@ -79,6 +79,7 @@ class @DiscussionUtil ...@@ -79,6 +79,7 @@ class @DiscussionUtil
params["loadedCallback"].apply(params["$loading"]) params["loadedCallback"].apply(params["$loading"])
else else
params["$loading"].loaded() params["$loading"].loaded()
return request
@get: ($elem, url, data, success) -> @get: ($elem, url, data, success) ->
@safeAjax @safeAjax
......
...@@ -23,10 +23,15 @@ if Backbone? ...@@ -23,10 +23,15 @@ if Backbone?
@renderResponses() @renderResponses()
@ @
cleanup: ->
if @responsesRequest?
@responsesRequest.abort()
renderResponses: -> renderResponses: ->
DiscussionUtil.safeAjax @responsesRequest = DiscussionUtil.safeAjax
url: "/courses/#{$$course_id}/discussion/forum/#{@model.get('commentable_id')}/threads/#{@model.id}" url: "/courses/#{$$course_id}/discussion/forum/#{@model.get('commentable_id')}/threads/#{@model.id}"
success: (data, textStatus, xhr) => success: (data, textStatus, xhr) =>
@responsesRequest = null
@$el.find(".loading").remove() @$el.find(".loading").remove()
Content.loadContentInfos(data['annotated_content_info']) Content.loadContentInfos(data['annotated_content_info'])
comments = new Comments(data['content']['children']) comments = new Comments(data['content']['children'])
......
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