diff --git a/lms/static/coffee/src/discussion/discussion.coffee b/lms/static/coffee/src/discussion/discussion.coffee index ecf5ee6f1d..91083c94e3 100644 --- a/lms/static/coffee/src/discussion/discussion.coffee +++ b/lms/static/coffee/src/discussion/discussion.coffee @@ -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 diff --git a/lms/static/coffee/src/discussion/views/discussion_thread_list_view.coffee b/lms/static/coffee/src/discussion/views/discussion_thread_list_view.coffee index a8f1466011..90bd7c4978 100644 --- a/lms/static/coffee/src/discussion/views/discussion_thread_list_view.coffee +++ b/lms/static/coffee/src/discussion/views/discussion_thread_list_view.coffee @@ -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("
  • Load more
  • ") loadMorePages: -> + # TODO: Obey dropdown filter @$(".more-pages").html('
    ') @$(".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.