Commit d343baa3 by Arjun Singh

Merge branch 'feature/rocky/discussion' into arjun/prelaunch_premerge

parents 263eab62 74bc2329
......@@ -282,7 +282,7 @@ def update_moderator_status(request, course_id, user_id):
'course_id': course_id,
'user': request.user,
'django_user': user,
'discussion_user': discussion_user.to_dict(),
'profiled_user': discussion_user.to_dict(),
}
return JsonResponse({
'html': render_to_string('discussion/ajax_user_profile.html', context)
......
......@@ -83,7 +83,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs):
'base_url': base_url,
'query_params': strip_blank(strip_none(extract(query_params, ['page', 'sort_key', 'sort_order', 'tags', 'text']))),
'annotated_content_info': json.dumps(annotated_content_info),
'discussion_data': json.dumps({ discussion_id: threads }),
'discussion_data': json.dumps({ (discussion_id or user_id): threads })
}
context = dict(context.items() + query_params.items())
return render_to_string(template, context)
......@@ -250,7 +250,10 @@ def user_profile(request, course_id, user_id):
content = render_user_discussion(request, course_id, threads, user_id=user_id, query_params=query_params)
if request.is_ajax():
return utils.HtmlResponse(content)
return utils.JsonResponse({
'html': content,
'discussionData': threads,
})
else:
context = {
'course': course,
......
class @Content extends Backbone.Model
if Backbone?
class @Content extends Backbone.Model
template: -> DiscussionUtil.getTemplate('_content')
......@@ -49,7 +50,7 @@ class @Content extends Backbone.Model
@resetComments(@get('children'))
class @ContentView extends Backbone.View
class @ContentView extends Backbone.View
$: (selector) ->
@$local.find(selector)
......@@ -256,7 +257,7 @@ class @ContentView extends Backbone.View
else
view.body = @$(".comment-raw-body").html()
@$discussionContent().append Mustache.render DiscussionUtil.getTemplate("_edit_#{@model.get('type')}"), view
Discussion.makeWmdEditor @$el, $.proxy(@$, @), "#{@model.get('type')}-body-edit"
DiscussionUtil.makeWmdEditor @$el, $.proxy(@$, @), "#{@model.get('type')}-body-edit"
@$(".thread-tags-edit").tagsInput DiscussionUtil.tagsInputOptions()
@$(".discussion-submit-update").unbind("click").click $.proxy(@submitEdit, @)
@$(".discussion-cancel-update").unbind("click").click $.proxy(@cancelEdit, @)
......@@ -352,7 +353,7 @@ class @ContentView extends Backbone.View
@initBody()
@initCommentViews()
class @Thread extends @Content
class @Thread extends @Content
urlMappers:
'retrieve' : -> DiscussionUtil.urlFor('retrieve_single_thread', @discussion.id, @id)
'reply' : -> DiscussionUtil.urlFor('create_comment', @id)
......@@ -373,9 +374,9 @@ class @Thread extends @Content
discussion_id = @get('commentable_id')
return Discussion.urlFor("permanent_link_thread", discussion_id, @id)
class @ThreadView extends @ContentView
class @ThreadView extends @ContentView
class @Comment extends @Content
class @Comment extends @Content
urlMappers:
'reply': -> DiscussionUtil.urlFor('create_sub_comment', @id)
'unvote': -> DiscussionUtil.urlFor("undo_vote_for_#{@get('type')}", @id)
......@@ -396,9 +397,9 @@ class @Comment extends @Content
count += comment.getCommentsCount() + 1
count
class @CommentView extends @ContentView
class @CommentView extends @ContentView
class @Comments extends Backbone.Collection
class @Comments extends Backbone.Collection
model: Comment
......
class @Discussion extends Backbone.Collection
if Backbone?
class @Discussion extends Backbone.Collection
model: Thread
initialize: ->
......@@ -15,7 +16,7 @@ class @Discussion extends Backbone.Collection
@add model
model
class @DiscussionView extends Backbone.View
class @DiscussionView extends Backbone.View
$: (selector) ->
@$local.find(selector)
......@@ -45,6 +46,7 @@ class @DiscussionView extends Backbone.View
@model.reset(response.discussionData, { silent: false })
view = new DiscussionView el: $discussion[0], model: @model
DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info)
$("html, body").animate({ scrollTop: 0 }, 0)
loadSimilarPost: (event) ->
$title = @$(".new-post-title")
......
class @DiscussionModuleView extends Backbone.View
if Backbone?
class @DiscussionModuleView extends Backbone.View
events:
"click .discussion-show": "toggleDiscussion"
toggleDiscussion: (event) ->
......
......@@ -12,4 +12,10 @@ $ ->
discussion.reset(discussionData, {silent: false})
view = new DiscussionView(el: elem, model: discussion)
if window.$$annotated_content_info?
DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info)
$userProfile = $(".discussion-sidebar>.user-profile")
if $userProfile.length
console.log "initialize user profile"
view = new DiscussionUserProfileView(el: $userProfile[0])
if not @Discussion?
@Discussion = {}
Discussion = @Discussion
@Discussion = $.extend @Discussion,
initializeUserProfile: ($userProfile) ->
$local = Discussion.generateLocal $userProfile
handleUpdateModeratorStatus = (elem, isModerator) ->
class @DiscussionUserProfileView extends Backbone.View
toggleModeratorStatus: (event) ->
confirmValue = confirm("Are you sure?")
if not confirmValue then return
url = Discussion.urlFor('update_moderator_status', $$profiled_user_id)
Discussion.safeAjax
$elem: $(elem)
$elem = $(event.target)
if $elem.hasClass("sidebar-promote-moderator-button")
isModerator = true
else if $elem.hasClass("sidebar-revoke-moderator-button")
isModerator = false
else
console.error "unrecognized moderator status"
return
url = DiscussionUtil.urlFor('update_moderator_status', $$profiled_user_id)
DiscussionUtil.safeAjax
$elem: $elem
url: url
type: "POST"
dataType: 'json'
......@@ -20,15 +20,10 @@ Discussion = @Discussion
is_moderator: isModerator
error: (response, textStatus, e) ->
console.log e
success: (response, textStatus) ->
parent = $userProfile.parent()
$userProfile.replaceWith(response.html)
Discussion.initializeUserProfile parent.children(".user-profile")
Discussion.bindLocalEvents $local,
"click .sidebar-revoke-moderator-button": (event) ->
handleUpdateModeratorStatus(this, false)
"click .sidebar-promote-moderator-button": (event) ->
handleUpdateModeratorStatus(this, true)
success: (response, textStatus) =>
parent = @$el.parent()
@$el.replaceWith(response.html)
view = new DiscussionUserProfileView el: parent.children(".user-profile")
initializeUserActiveDiscussion: ($discussion) ->
events:
"click .sidebar-toggle-moderator-button": "toggleModeratorStatus"
<%! import django_comment_client.helpers as helpers %>
<%def name="render_content(content)">
${helpers.render_content(content)}
<%def name="render_content(content, *args, **kwargs)">
${helpers.render_content(content, *args, **kwargs)}
</%def>
<%def name="render_content_with_comments(content)">
<%def name="render_content_with_comments(content, *args, **kwargs)">
<div class="${content['type']}${helpers.show_if(' endorsed', content.get('endorsed'))}" _id="${content['id']}" _discussion_id="${content.get('commentable_id', '')}" _author_id="${helpers.show_if(content['user_id'], not content.get('anonymous'))}">
${render_content(content)}
${render_comments(content.get('children', []))}
${render_content(content, *args, **kwargs)}
${render_comments(content.get('children', []), *args, **kwargs)}
</div>
</%def>
<%def name="render_comments(comments)">
<%def name="render_comments(comments, *args, **kwargs)">
<div class="comments">
% for comment in comments:
${render_content_with_comments(comment)}
${render_content_with_comments(comment, *args, **kwargs)}
% endfor
</div>
</%def>
<%namespace name="renderer" file="_thread.html"/>
<%namespace name="renderer" file="_content_renderer.html"/>
<section class="discussion user-active-discussion">
<section class="discussion user-active-discussion" _id="${user_id}">
<div class="discussion-non-content discussion-local"></div>
<div class="discussion-non-content local"></div>
<div class="threads">
% for thread in threads:
${renderer.render_thread(course_id, thread, show_comments=True)}
${renderer.render_content_with_comments(thread, {'partial_comments': True})}
% endfor
</div>
......
<%! from django_comment_client.utils import pluralize %>
<%! from django_comment_client.helpers import pluralize %>
<%! from django_comment_client.permissions import has_permission, check_permissions_by_view %>
<%! from operator import attrgetter %>
......@@ -15,9 +15,9 @@
<div class="sidebar-comments-count"><span>${profiled_user['comments_count']}</span> ${pluralize('comment', profiled_user['comments_count'])}</div>
% if check_permissions_by_view(user, course.id, content=None, name='update_moderator_status'):
% if "Moderator" in role_names:
<a href="javascript:void(0)" class="sidebar-revoke-moderator-button">Revoke Moderator provileges</a>
<a href="javascript:void(0)" class="sidebar-toggle-moderator-button sidebar-revoke-moderator-button">Revoke Moderator provileges</a>
% else:
<a href="javascript:void(0)" class="sidebar-promote-moderator-button">Promote to Moderator</a>
<a href="javascript:void(0)" class="sidebar-toggle-moderator-button sidebar-promote-moderator-button">Promote to Moderator</a>
% endif
% endif
</div>
<%inherit file="../main.html" />
<%namespace name='static' file='../static_content.html'/>
<%block name="bodyclass">discussion</%block>
<%block name="title"><title>Discussion – MITx 6.002x</title></%block>
<%block name="title"><title>Discussion – ${course.number}</title></%block>
<%block name="headextra">
<%static:css group='course'/>
......
......@@ -37,7 +37,7 @@
anonymous
{{/content.anonymous}}
{{^content.anonymous}}
{{content.username}}
<a href="{{##url_for_user}}{{content.user_id}}{{/url_for_user}}">{{content.username}}</a>
{{/content.anonymous}}
</div>
<div class="show-comments-wrapper">
......
<%inherit file="../main.html" />
<%namespace name='static' file='../static_content.html'/>
<%block name="bodyclass">discussion</%block>
<%block name="title"><title>Discussion – MITx 6.002x</title></%block>
<%block name="title"><title>Discussion – ${course.number}</title></%block>
<%block name="headextra">
<%static:css group='course'/>
......
<%! from django.template.defaultfilters import escapejs %>
<%namespace name="renderer" file="_thread.html"/>
<%inherit file="../main.html" />
<%namespace name='static' file='../static_content.html'/>
<%block name="bodyclass">discussion</%block>
<%block name="title"><title>Discussion – MITx 6.002x</title></%block>
<%block name="title"><title>Discussion – ${course.number}</title></%block>
<%block name="headextra">
<%static:css group='course'/>
<%include file="_js_head_dependencies.html" />
</%block>
<%block name="js_extra">
<%include file="_js_dependencies.html" />
<%include file="_js_body_dependencies.html" />
<%static:js group='discussion'/>
</%block>
<%include file="/courseware/course_navigation.html" args="active_page='discussion'" />
<%include file="../courseware/course_navigation.html" args="active_page='discussion'" />
<section class="container">
<div class="course-wrapper">
......
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