Commit 37c78524 by Rocky Duan

migrated threads reloading related stuff

parent 4a3975c7
......@@ -142,19 +142,23 @@ def forum_form_discussion(request, course_id):
threads, query_params = get_threads(request, course_id)
content = render_forum_discussion(request, course_id, threads, discussion_id=_general_discussion_id(course_id), query_params=query_params)
recent_active_threads = cc.search_recent_active_threads(
course_id,
recursive=False,
query_params={'follower_id': request.user.id},
)
trending_tags = cc.search_trending_tags(
course_id,
)
if request.is_ajax():
return utils.HtmlResponse(content)
return utils.JsonResponse({
'html': content,
'discussionData': threads,
})
else:
recent_active_threads = cc.search_recent_active_threads(
course_id,
recursive=False,
query_params={'follower_id': request.user.id},
)
trending_tags = cc.search_trending_tags(
course_id,
)
context = {
'csrf': csrf(request)['csrf_token'],
'course': course,
......
......@@ -87,6 +87,7 @@ class @ContentView extends Backbone.View
@$(".discussion-follow-thread").removeClass("discussion-unfollow-thread").html("Follow")
ability: (ability) ->
console.log "triggered"
for action, elemSelector of @model.actions
if not ability[action]
@$(elemSelector).parent().remove()
......
......@@ -26,15 +26,41 @@ class @DiscussionView extends Backbone.View
@model.view = @
@$el.children(".threads").children(".thread").each (index, elem) =>
threadView = new ThreadView el: elem, model: @model.find $(elem).attr("_id")
if @$el.hasClass("forum-discussion")
$(".discussion-sidebar").find(".sidebar-new-post-button")
.unbind('click').click $.proxy @newPost, @
else if @$el.hasClass("inline-discussion")
@newPost()
search: ->
reload: ($elem, url) ->
if not url then return
DiscussionUtil.get $elem, url, (response, textStatus) =>
$discussion = $(response.html)
$parent = @$el.parent()
@$el.replaceWith($discussion)
@model.reset(response.discussionData, { silent: false })
view = new DiscussionView el: $discussion[0], model: @model
DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info)
newPost: ->
search: (event) ->
$elem = $(event.target)
url = URI($elem.attr("action")).addSearch({text: @$(".search-input").val()})
@reload($elem, url)
sort: ->
$elem = $(event.target)
url = $elem.attr("sort-url")
@reload($elem, url)
page: ->
page: (event) ->
$elem = $(event.target)
url = $elem.attr("page-url")
@reload($elem, url)
events:
"submit .search-wrapper>.discussion-search-form": "search"
"click .discussion-search-link": "search"
"click .discussion-sort-link": "sort"
"click .discussion-paginator>.discussion-page-link": "page"
"click .discussion-page-link": "page"
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