Commit aa3a4c79 by Ibrahim Awwal

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

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