Commit 7dbea50d by Arjun Singh

reasonable behavior when creating a thread

parent 27b80bc8
...@@ -13,7 +13,7 @@ if Backbone? ...@@ -13,7 +13,7 @@ if Backbone?
@nav.render() @nav.render()
@newPostView = new NewPostView(el: $(".new-post-article"), collection: @discussion) @newPostView = new NewPostView(el: $(".new-post-article"), collection: @discussion)
@newPostView.on "thread:created", @navigateToThread @nav.on "thread:created", @navigateToThread
allThreads: -> allThreads: ->
@nav.updateSidebar() @nav.updateSidebar()
...@@ -42,5 +42,4 @@ if Backbone? ...@@ -42,5 +42,4 @@ if Backbone?
@navigate("#{thread.get("commentable_id")}/threads/#{thread_id}", trigger: true) @navigate("#{thread.get("commentable_id")}/threads/#{thread_id}", trigger: true)
navigateToAllThreads: => navigateToAllThreads: =>
console.log "navigating"
@navigate("", trigger: true) @navigate("", trigger: true)
...@@ -40,15 +40,13 @@ if Backbone? ...@@ -40,15 +40,13 @@ if Backbone?
if active if active
@setActiveThread(thread_id) @setActiveThread(thread_id)
#TODO fix this entire chain of events
addAndSelectThread: (thread) => addAndSelectThread: (thread) =>
commentable_id = thread.get("commentable_id") commentable_id = thread.get("commentable_id")
commentable = @$(".board-name[data-discussion_id]").filter(-> $(this).data("discussion_id").id == commentable_id) commentable = @$(".board-name[data-discussion_id]").filter(-> $(this).data("discussion_id").id == commentable_id)
commentable.click() @setTopicHack(commentable)
@displayedCollection.add thread @retrieveDiscussion commentable_id, =>
content = @renderThread(thread) @trigger "thread:created", thread.get('id')
$(".post-list").prepend content
content.wrap("<li data-id='#{thread.get('id')}' />")
content.click()
updateSidebar: => updateSidebar: =>
...@@ -187,6 +185,13 @@ if Backbone? ...@@ -187,6 +185,13 @@ if Backbone?
$("body").unbind "click", @toggleTopicDrop $("body").unbind "click", @toggleTopicDrop
$("body").unbind "keydown", @setActiveItem $("body").unbind "keydown", @setActiveItem
# TODO get rid of this asap
setTopicHack: (boardNameContainer) ->
item = $(boardNameContainer).closest('a')
boardName = item.find(".board-name").html()
_.each item.parents('ul').not('.browse-topic-drop-menu'), (parent) ->
boardName = $(parent).siblings('a').find('.board-name').html() + ' / ' + boardName
@$(".current-board").html(@fitName(boardName))
setTopic: (event) -> setTopic: (event) ->
item = $(event.target).closest('a') item = $(event.target).closest('a')
...@@ -243,6 +248,20 @@ if Backbone? ...@@ -243,6 +248,20 @@ if Backbone?
discussionIds = _.map item.find(".board-name[data-discussion_id]"), (board) -> $(board).data("discussion_id").id discussionIds = _.map item.find(".board-name[data-discussion_id]"), (board) -> $(board).data("discussion_id").id
@retrieveDiscussions(discussionIds) @retrieveDiscussions(discussionIds)
retrieveDiscussion: (discussion_id, callback=null) ->
url = DiscussionUtil.urlFor("retrieve_discussion", discussion_id)
DiscussionUtil.safeAjax
url: url
type: "GET"
success: (response, textStatus) =>
@collection.current_page = response.page
@collection.pages = response.num_pages
@collection.reset(response.discussion_data)
Content.loadContentInfos(response.content_info)
@displayedCollection.reset(@collection.models)
if callback?
callback()
retrieveDiscussions: (discussion_ids) -> retrieveDiscussions: (discussion_ids) ->
@discussionIds = discussion_ids.join(',') @discussionIds = discussion_ids.join(',')
url = DiscussionUtil.urlFor("search") url = DiscussionUtil.urlFor("search")
......
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