Fix pagination and sorting for followed threads. Also fixed sorting so that it always retrieves a new set of threads from the server for the initial set.

This commit is contained in:
Ibrahim Awwal
2012-09-18 04:35:32 -07:00
parent a444166d98
commit ef8ca23dee
3 changed files with 20 additions and 9 deletions

View File

@@ -52,6 +52,7 @@ if Backbone?
new_collection = _.union(models, new_threads)
Content.loadContentInfos(response.annotated_content_info)
@reset new_collection
@pages = response.num_pages
sortByDate: (thread) ->
thread.get("created_at")

View File

@@ -307,12 +307,13 @@ if Backbone?
@$(".sort-bar a").removeClass("active")
$(event.target).addClass("active")
@sortBy = $(event.target).data("sort")
if @sortBy == "date"
@displayedCollection.comparator = @displayedCollection.sortByDateRecentFirst
else if @sortBy == "votes"
@displayedCollection.comparator = @displayedCollection.sortByVotes
else if @sortBy == "comments"
@displayedCollection.comparator = @displayedCollection.sortByComments
@collection.reset()
@collection.current_page = 0
@loadMorePages(event)
@displayedCollection.comparator = switch @sortBy
when 'date' then @displayedCollection.sortByDateRecentFirst
when 'votes' then @displayedCollection.sortByVotes
when 'comments' then @displayedCollection.sortByComments
@displayedCollection.sort()
performSearch: (event) ->
@@ -330,6 +331,9 @@ if Backbone?
@mode = 'search'
@current_search = text
url = DiscussionUtil.urlFor("search")
#TODO: This might be better done by setting discussion.current_page=0 and calling discussion.loadMorePages
# Mainly because this currently does not reset any pagination variables which could cause problems.
# This doesn't use pagination either.
DiscussionUtil.safeAjax
$elem: @$(".post-search-field")
data: { text: text }