Merge branch 'feature/arjun/new-discussions' of github.com:MITx/mitx into feature/arjun/new-discussions
This commit is contained in:
@@ -2,7 +2,7 @@ if Backbone?
|
||||
class @Discussion extends Backbone.Collection
|
||||
model: Thread
|
||||
|
||||
initialize: (models, options)->
|
||||
initialize: (models, options={})->
|
||||
@pages = options['pages'] || 1
|
||||
@current_page = 1
|
||||
@bind "add", (item) =>
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user