Commit df825608 by Matthew Mongeau

Update display when creating new post.

parent 12c391ad
......@@ -12,6 +12,7 @@ class @DiscussionThreadListView extends Backbone.View
initialize: ->
@displayedCollection = new Discussion(@collection.models)
@collection.on "change", @reloadDisplayedCollection
@collection.on "add", @addAndSelectThread
@sidebar_padding = 10
@sidebar_header_height = 87
......@@ -24,6 +25,16 @@ class @DiscussionThreadListView extends Backbone.View
if active
@setActiveThread(thread_id)
addAndSelectThread: (thread) =>
commentable_id = thread.get("commentable_id")
commentable = @$(".board-name[data-discussion_id]").filter(-> $(this).data("discussion_id").id == commentable_id)
commentable.click()
@displayedCollection.add thread
content = @renderThread(thread)
$(".post-list").prepend content
content.wrap("<li data-id='#{thread.get('id')}' />")
content.click()
updateSidebar: =>
scrollTop = $(window).scrollTop();
......@@ -153,8 +164,7 @@ class @DiscussionThreadListView extends Backbone.View
item = $(event.target).closest('li')
if item.find("span.board-name").data("discussion_id") == "#all"
item = item.parent()
discussionIds = _.compact _.map item.find("span.board-name"), (board) -> $(board).data("discussion_id")
discussionIds = _.map discussionIds, (info) -> info.id
discussionIds = _.map item.find(".board-name[data-discussion_id]"), (board) -> $(board).data("discussion_id").id
filtered = @collection.filter (thread) =>
_.include(discussionIds, thread.get('commentable_id'))
@displayedCollection.reset filtered
......
......@@ -30,10 +30,10 @@ class @NewPostView extends Backbone.View
toggleTopicDropdown: (event) ->
event.stopPropagation()
if @menuOpen
@hideTopicDropdown()
@hideTopicDropdown()
else
@showTopicDropdown()
@showTopicDropdown()
showTopicDropdown: () ->
@menuOpen = true
@dropdownButton.addClass('dropped')
......@@ -85,7 +85,7 @@ class @NewPostView extends Backbone.View
width = test.width()
test.remove()
return width
fitName: (name) ->
width = @getNameWidth(name)
if width < @maxNameWidth
......@@ -136,6 +136,7 @@ class @NewPostView extends Backbone.View
auto_subscribe: follow
error: DiscussionUtil.formErrorHandler(@$(".new-post-form-errors"))
success: (response, textStatus) =>
# TODO: Move this out of the callback, this makes it feel sluggish
thread = new Thread response['content']
DiscussionUtil.clearFormErrors(@$(".new-post-form-errors"))
@$el.hide()
......@@ -144,20 +145,6 @@ class @NewPostView extends Backbone.View
@$(".new-post-tags").val("")
@$(".new-post-tags").importTags("")
@collection.add thread
@collection.trigger "reset"
@trigger "thread:created", thread.id
#@$el.children(".threads").prepend($thread)
# no idea what this is
#@$el.children(".blank").remove()
#@$(".new-post-similar-posts").empty()
#@$(".new-post-similar-posts-wrapper").hide()
#DiscussionUtil.setWmdContent @$el, $.proxy(@$, @), "new-post-body", ""
#thread = @model.addThread response.content
#threadView = new ThreadView el: $thread[0], model: thread
#thread.updateInfo response.annotated_content_info
#@cancelNewPost()
setActiveItem: (event) ->
if event.which == 13
......@@ -182,6 +169,3 @@ class @NewPostView extends Backbone.View
scrollTarget = Math.min(index * itemHeight, $(".topic_menu").scrollTop())
scrollTarget = Math.max(index * itemHeight - $(".topic_menu").height() + itemHeight, scrollTarget)
$(".topic_menu").scrollTop(scrollTarget)
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