Commit 007de179 by Rocky Duan

add user profile page back

parent 4dae36cd
...@@ -282,7 +282,7 @@ def update_moderator_status(request, course_id, user_id): ...@@ -282,7 +282,7 @@ def update_moderator_status(request, course_id, user_id):
'course_id': course_id, 'course_id': course_id,
'user': request.user, 'user': request.user,
'django_user': user, 'django_user': user,
'discussion_user': discussion_user.to_dict(), 'profiled_user': discussion_user.to_dict(),
} }
return JsonResponse({ return JsonResponse({
'html': render_to_string('discussion/ajax_user_profile.html', context) 'html': render_to_string('discussion/ajax_user_profile.html', context)
......
...@@ -83,7 +83,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs): ...@@ -83,7 +83,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs):
'base_url': base_url, 'base_url': base_url,
'query_params': strip_blank(strip_none(extract(query_params, ['page', 'sort_key', 'sort_order', 'tags', 'text']))), 'query_params': strip_blank(strip_none(extract(query_params, ['page', 'sort_key', 'sort_order', 'tags', 'text']))),
'annotated_content_info': json.dumps(annotated_content_info), '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()) context = dict(context.items() + query_params.items())
return render_to_string(template, context) return render_to_string(template, context)
...@@ -250,7 +250,10 @@ def user_profile(request, course_id, user_id): ...@@ -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) content = render_user_discussion(request, course_id, threads, user_id=user_id, query_params=query_params)
if request.is_ajax(): if request.is_ajax():
return utils.HtmlResponse(content) return utils.JsonResponse({
'html': content,
'discussionData': threads,
})
else: else:
context = { context = {
'course': course, 'course': course,
......
...@@ -257,7 +257,7 @@ if Backbone? ...@@ -257,7 +257,7 @@ if Backbone?
else else
view.body = @$(".comment-raw-body").html() view.body = @$(".comment-raw-body").html()
@$discussionContent().append Mustache.render DiscussionUtil.getTemplate("_edit_#{@model.get('type')}"), view @$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() @$(".thread-tags-edit").tagsInput DiscussionUtil.tagsInputOptions()
@$(".discussion-submit-update").unbind("click").click $.proxy(@submitEdit, @) @$(".discussion-submit-update").unbind("click").click $.proxy(@submitEdit, @)
@$(".discussion-cancel-update").unbind("click").click $.proxy(@cancelEdit, @) @$(".discussion-cancel-update").unbind("click").click $.proxy(@cancelEdit, @)
......
...@@ -14,3 +14,8 @@ $ -> ...@@ -14,3 +14,8 @@ $ ->
if window.$$annotated_content_info? if window.$$annotated_content_info?
DiscussionUtil.bulkUpdateContentInfo(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? class @DiscussionUserProfileView extends Backbone.View
@Discussion = {} toggleModeratorStatus: (event) ->
Discussion = @Discussion
@Discussion = $.extend @Discussion,
initializeUserProfile: ($userProfile) ->
$local = Discussion.generateLocal $userProfile
handleUpdateModeratorStatus = (elem, isModerator) ->
confirmValue = confirm("Are you sure?") confirmValue = confirm("Are you sure?")
if not confirmValue then return if not confirmValue then return
url = Discussion.urlFor('update_moderator_status', $$profiled_user_id) $elem = $(event.target)
Discussion.safeAjax if $elem.hasClass("sidebar-promote-moderator-button")
$elem: $(elem) 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 url: url
type: "POST" type: "POST"
dataType: 'json' dataType: 'json'
...@@ -20,15 +20,10 @@ Discussion = @Discussion ...@@ -20,15 +20,10 @@ Discussion = @Discussion
is_moderator: isModerator is_moderator: isModerator
error: (response, textStatus, e) -> error: (response, textStatus, e) ->
console.log e console.log e
success: (response, textStatus) -> success: (response, textStatus) =>
parent = $userProfile.parent() parent = @$el.parent()
$userProfile.replaceWith(response.html) @$el.replaceWith(response.html)
Discussion.initializeUserProfile parent.children(".user-profile") view = new DiscussionUserProfileView el: 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)
initializeUserActiveDiscussion: ($discussion) -> events:
"click .sidebar-toggle-moderator-button": "toggleModeratorStatus"
<%! import django_comment_client.helpers as helpers %> <%! import django_comment_client.helpers as helpers %>
<%def name="render_content(content)"> <%def name="render_content(content, *args, **kwargs)">
${helpers.render_content(content)} ${helpers.render_content(content, *args, **kwargs)}
</%def> </%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'))}"> <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_content(content, *args, **kwargs)}
${render_comments(content.get('children', []))} ${render_comments(content.get('children', []), *args, **kwargs)}
</div> </div>
</%def> </%def>
<%def name="render_comments(comments)"> <%def name="render_comments(comments, *args, **kwargs)">
<div class="comments"> <div class="comments">
% for comment in comments: % for comment in comments:
${render_content_with_comments(comment)} ${render_content_with_comments(comment, *args, **kwargs)}
% endfor % endfor
</div> </div>
</%def> </%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"> <div class="threads">
% for thread in threads: % for thread in threads:
${renderer.render_thread(course_id, thread, show_comments=True)} ${renderer.render_content_with_comments(thread, {'partial_comments': True})}
% endfor % endfor
</div> </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 django_comment_client.permissions import has_permission, check_permissions_by_view %>
<%! from operator import attrgetter %> <%! from operator import attrgetter %>
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
<div class="sidebar-comments-count"><span>${profiled_user['comments_count']}</span> ${pluralize('comment', profiled_user['comments_count'])}</div> <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 check_permissions_by_view(user, course.id, content=None, name='update_moderator_status'):
% if "Moderator" in role_names: % 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: % 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
% endif % endif
</div> </div>
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
anonymous anonymous
{{/content.anonymous}} {{/content.anonymous}}
{{^content.anonymous}} {{^content.anonymous}}
{{content.username}} <a href="{{##url_for_user}}{{content.user_id}}{{/url_for_user}}">{{content.username}}</a>
{{/content.anonymous}} {{/content.anonymous}}
</div> </div>
<div class="show-comments-wrapper"> <div class="show-comments-wrapper">
......
<%! from django.template.defaultfilters import escapejs %> <%! from django.template.defaultfilters import escapejs %>
<%namespace name="renderer" file="_thread.html"/>
<%inherit file="../main.html" /> <%inherit file="../main.html" />
<%namespace name='static' file='../static_content.html'/> <%namespace name='static' file='../static_content.html'/>
...@@ -8,13 +7,14 @@ ...@@ -8,13 +7,14 @@
<%block name="headextra"> <%block name="headextra">
<%static:css group='course'/> <%static:css group='course'/>
<%include file="_js_head_dependencies.html" />
</%block> </%block>
<%block name="js_extra"> <%block name="js_extra">
<%include file="_js_dependencies.html" /> <%include file="_js_body_dependencies.html" />
</%block> </%block>
<%include file="/courseware/course_navigation.html" args="active_page='discussion'" /> <%include file="../courseware/course_navigation.html" args="active_page='discussion'" />
<section class="container"> <section class="container">
<div class="course-wrapper"> <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