Commit 2b5e93a0 by Ibrahim Awwal

Fix clicking on commentables in the dropdown.

parent 18354673
...@@ -32,8 +32,9 @@ if Backbone? ...@@ -32,8 +32,9 @@ if Backbone?
when 'search' when 'search'
url = DiscussionUtil.urlFor 'search' url = DiscussionUtil.urlFor 'search'
data['text'] = options.search_text data['text'] = options.search_text
if options.commentable_ids when 'commentables'
data['commentable_ids'] = options.commentable_ids url = DiscussionUtil.urlFor 'search'
data['commentable_ids'] = options.commentable_ids
when 'all' when 'all'
url = DiscussionUtil.urlFor 'threads' url = DiscussionUtil.urlFor 'threads'
when 'followed' when 'followed'
......
...@@ -120,16 +120,18 @@ if Backbone? ...@@ -120,16 +120,18 @@ if Backbone?
@$(".post-list").append("<li class='more-pages'><a href='#'>Load more</a></li>") @$(".post-list").append("<li class='more-pages'><a href='#'>Load more</a></li>")
loadMorePages: (event) -> loadMorePages: (event) ->
event.preventDefault() if event
event.preventDefault()
@$(".more-pages").html('<div class="loading-animation"></div>') @$(".more-pages").html('<div class="loading-animation"></div>')
@$(".more-pages").addClass("loading") @$(".more-pages").addClass("loading")
options = {} options = {}
switch @mode switch @mode
when 'search' when 'search'
options.search_text = @current_search options.search_text = @current_search
options.commentable_ids = @discussionIds
when 'followed' when 'followed'
options.user_id = window.user.id options.user_id = window.user.id
when 'commentables'
options.commentable_ids = @discussionIds
@collection.retrieveAnotherPage(@mode, options, {sort_key: @sortBy}) @collection.retrieveAnotherPage(@mode, options, {sort_key: @sortBy})
renderThread: (thread) => renderThread: (thread) =>
...@@ -273,25 +275,30 @@ if Backbone? ...@@ -273,25 +275,30 @@ if Backbone?
@collection.pages = response.num_pages @collection.pages = response.num_pages
@collection.reset(response.discussion_data) @collection.reset(response.discussion_data)
Content.loadContentInfos(response.annotated_content_info) Content.loadContentInfos(response.annotated_content_info)
@displayedCollection.reset(@collection.models) @displayedCollection.reset(@collection.models)# Don't think this is necessary because it's called on collection.reset
if callback? if callback?
callback() callback()
retrieveDiscussions: (discussion_ids) -> retrieveDiscussions: (discussion_ids) ->
@discussionIds = discussion_ids.join(',') @discussionIds = discussion_ids.join(',')
url = DiscussionUtil.urlFor("search") @mode = 'commentables'
DiscussionUtil.safeAjax @collection.current_page = 0
data: { 'commentable_ids': @discussionIds } @collection.reset()
url: url @loadMorePages()
type: "GET" # url = DiscussionUtil.urlFor("search")
success: (response, textStatus) => # DiscussionUtil.safeAjax
@collection.current_page = response.page # data: { 'commentable_ids': @discussionIds }
@collection.pages = response.num_pages # url: url
@collection.reset(response.discussion_data) # type: "GET"
Content.loadContentInfos(response.annotated_content_info) # success: (response, textStatus) =>
@displayedCollection.reset(@collection.models) # @collection.current_page = response.page
# @collection.pages = response.num_pages
# @collection.reset(response.discussion_data)
# Content.loadContentInfos(response.annotated_content_info)
# @displayedCollection.reset(@collection.models)
retrieveAllThreads: () -> retrieveAllThreads: () ->
@mode='all'
url = DiscussionUtil.urlFor("threads") url = DiscussionUtil.urlFor("threads")
DiscussionUtil.safeAjax DiscussionUtil.safeAjax
url: url url: url
...@@ -301,7 +308,7 @@ if Backbone? ...@@ -301,7 +308,7 @@ if Backbone?
@collection.pages = response.num_pages @collection.pages = response.num_pages
@collection.reset(response.discussion_data) @collection.reset(response.discussion_data)
Content.loadContentInfos(response.annotated_content_info) Content.loadContentInfos(response.annotated_content_info)
@displayedCollection.reset(@collection.models) @displayedCollection.reset(@collection.models) #Don't think this is necessary
sortThreads: (event) -> sortThreads: (event) ->
@$(".sort-bar a").removeClass("active") @$(".sort-bar a").removeClass("active")
...@@ -309,12 +316,12 @@ if Backbone? ...@@ -309,12 +316,12 @@ if Backbone?
@sortBy = $(event.target).data("sort") @sortBy = $(event.target).data("sort")
@collection.reset() @collection.reset()
@collection.current_page = 0 @collection.current_page = 0
@loadMorePages(event)
@displayedCollection.comparator = switch @sortBy @displayedCollection.comparator = switch @sortBy
when 'date' then @displayedCollection.sortByDateRecentFirst when 'date' then @displayedCollection.sortByDateRecentFirst
when 'votes' then @displayedCollection.sortByVotes when 'votes' then @displayedCollection.sortByVotes
when 'comments' then @displayedCollection.sortByComments when 'comments' then @displayedCollection.sortByComments
@displayedCollection.sort() @loadMorePages(event)
#@displayedCollection.sort() # This should be called automatically and calling this makes the loading indicator go away
performSearch: (event) -> performSearch: (event) ->
if event.which == 13 if event.which == 13
...@@ -355,7 +362,7 @@ if Backbone? ...@@ -355,7 +362,7 @@ if Backbone?
# TODO: Perhaps reload user info so that votes can be updated. # TODO: Perhaps reload user info so that votes can be updated.
# In the future we might not load all of a user's votes at once # In the future we might not load all of a user's votes at once
# so this would probably be necessary anyway # so this would probably be necessary anyway
@displayedCollection.reset(@collection.models) @displayedCollection.reset(@collection.models) # Don't think this is necessary
clearSearch: (callback, value) -> clearSearch: (callback, value) ->
@$(".post-search-field").val("") @$(".post-search-field").val("")
......
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