Commit e28dde32 by Jonathan Piacenti

Load thread if requested thread isn't loaded yet.

parent 0569c5dd
...@@ -51,6 +51,15 @@ if Backbone? ...@@ -51,6 +51,15 @@ if Backbone?
showThread: (forum_name, thread_id) -> showThread: (forum_name, thread_id) ->
@thread = @discussion.get(thread_id) @thread = @discussion.get(thread_id)
if !@thread
callback = (thread) =>
@thread = thread
@renderThreadView()
@retrieveSingleThread(forum_name, thread_id, callback)
else
@renderThreadView()
renderThreadView: () ->
@thread.set("unread_comments_count", 0) @thread.set("unread_comments_count", 0)
@thread.set("read", true) @thread.set("read", true)
@setActiveThread() @setActiveThread()
...@@ -97,3 +106,21 @@ if Backbone? ...@@ -97,3 +106,21 @@ if Backbone?
complete: => complete: =>
$('.forum-content').fadeIn(200).find('.thread-wrapper').focus() $('.forum-content').fadeIn(200).find('.thread-wrapper').focus()
) )
retrieveSingleThread: (forum_name, thread_id, callback) ->
DiscussionUtil.safeAjax
url: DiscussionUtil.urlFor('retrieve_single_thread', forum_name, thread_id)
success: (data, textStatus, xhr) =>
callback(new Thread(data['content']))
error: (xhr) =>
if xhr.status == 404
DiscussionUtil.discussionAlert(
gettext("Sorry"),
gettext("The thread you selected has been deleted. Please select another thread.")
)
else
DiscussionUtil.discussionAlert(
gettext("Sorry"),
gettext("We had some trouble loading more responses. Please try again.")
)
@allThreads()
...@@ -22,12 +22,6 @@ if Backbone? ...@@ -22,12 +22,6 @@ if Backbone?
if @mode not in ["tab", "inline"] if @mode not in ["tab", "inline"]
throw new Error("invalid mode: " + @mode) throw new Error("invalid mode: " + @mode)
# Quick fix to have an actual model when we're receiving new models from
# the server.
@model.collection.on "reset", (collection) =>
id = @model.get("id")
@model = collection.get(id) if collection.get(id)
@createShowView() @createShowView()
@responses = new Comments() @responses = new Comments()
@loadedResponses = false @loadedResponses = false
......
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