Commit aa3a4c79 by Ibrahim Awwal

Obey current search query and sort order when retrieving additional pages.

parent 2b1c913c
......@@ -23,10 +23,13 @@ if Backbone?
@add model
model
retrieveAnotherPage: ->
retrieveAnotherPage: (search_text="", commentable_id="", sort_key="")->
# TODO: Obey dropdown filter (commentable_id)
@current_page += 1
url = DiscussionUtil.urlFor 'threads'
data = { page: @current_page }
data = { page: @current_page, text: search_text }
if sort_key
data['sort_key'] = sort_key
DiscussionUtil.safeAjax
$elem: @$el
url: url
......
......@@ -13,6 +13,7 @@ if Backbone?
initialize: ->
@displayedCollection = new Discussion(@collection.models, pages: @collection.pages)
@collection.on "change", @reloadDisplayedCollection
@sortBy = "date"
@collection.on "reset", (discussion) =>
board = $(".current-board").html()
@displayedCollection.current_page = discussion.current_page
......@@ -116,9 +117,10 @@ if Backbone?
@$(".post-list").append("<li class='more-pages'><a href='#'>Load more</a></li>")
loadMorePages: ->
# TODO: Obey dropdown filter
@$(".more-pages").html('<div class="loading-animation"></div>')
@$(".more-pages").addClass("loading")
@collection.retrieveAnotherPage()
@collection.retrieveAnotherPage(@current_search, "", @sortBy)
renderThread: (thread) =>
content = $(_.template($("#thread-list-item-template").html())(thread.toJSON()))
......@@ -242,12 +244,12 @@ if Backbone?
sortThreads: (event) ->
@$(".sort-bar a").removeClass("active")
$(event.target).addClass("active")
sortBy = $(event.target).data("sort")
if sortBy == "date"
@sortBy = $(event.target).data("sort")
if @sortBy == "date"
@displayedCollection.comparator = @displayedCollection.sortByDateRecentFirst
else if sortBy == "votes"
else if @sortBy == "votes"
@displayedCollection.comparator = @displayedCollection.sortByVotes
else if sortBy == "comments"
else if @sortBy == "comments"
@displayedCollection.comparator = @displayedCollection.sortByComments
@displayedCollection.sort()
......@@ -278,6 +280,7 @@ if Backbone?
callback.apply @, [value]
success: (response, textStatus) =>
if textStatus == 'success'
# TODO: Augment existing collection?
@collection.reset(response.discussion_data)
Content.loadContentInfos(response.content_info)
# TODO: Perhaps reload user info so that votes can be updated.
......
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