Commit b2821c53 by Rocky Duan

Merge branch 'feature/tomg/new-discussions' of github.com:MITx/mitx into…

Merge branch 'feature/tomg/new-discussions' of github.com:MITx/mitx into feature/tomg/new-discussions
parents d39e3de5 e8ac5860
......@@ -30,7 +30,7 @@ def _general_discussion_id(course_id):
def _should_perform_search(request):
return bool(request.GET.get('text', False) or \
request.GET.get('tags', False))
def render_accordion(request, course, discussion_id):
......@@ -59,7 +59,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs):
}[discussion_type]
base_url = {
'inline': (lambda: reverse('django_comment_client.forum.views.inline_discussion', args=[course_id, discussion_id])),
'inline': (lambda: reverse('django_comment_client.forum.views.inline_discussion', args=[course_id, discussion_id])),
'forum': (lambda: reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id])),
'user': (lambda: reverse('django_comment_client.forum.views.user_profile', args=[course_id, user_id])),
}[discussion_type]()
......@@ -123,12 +123,14 @@ def get_threads(request, course_id, discussion_id=None):
# discussion per page is fixed for now
def inline_discussion(request, course_id, discussion_id):
threads, query_params = get_threads(request, course_id, discussion_id)
html = render_inline_discussion(request, course_id, threads, discussion_id=discussion_id, \
query_params=query_params)
# TODO: Remove all of this stuff or switch back to server side rendering once templates are mustache again
# html = render_inline_discussion(request, course_id, threads, discussion_id=discussion_id, \
# query_params=query_params)
user_info = cc.User.from_django_user(request.user).to_dict()
return utils.JsonResponse({
'html': html,
# 'html': html,
'discussion_data': map(utils.safe_content, threads),
'user_info': user_info,
})
def render_search_bar(request, course_id, discussion_id=None, text=''):
......@@ -215,6 +217,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
thread = cc.Thread.find(thread_id).retrieve(recursive=True)
annotated_content_info = utils.get_annotated_content_infos(course_id, thread, request.user, user_info=user_info)
context = {'thread': thread.to_dict(), 'course_id': course_id}
# TODO: Remove completely or switch back to server side rendering
html = render_to_string('discussion/_ajax_single_thread.html', context)
return utils.JsonResponse({
......@@ -287,7 +290,7 @@ def user_profile(request, course_id, user_id):
})
else:
context = {
'course': course,
'course': course,
'user': request.user,
'django_user': User.objects.get(id=user_id),
'profiled_user': profiled_user.to_dict(),
......
......@@ -23,12 +23,17 @@ if Backbone?
type: "GET"
dataType: 'json'
success: (response, textStatus) =>
@$el.append(response.html)
$discussion = @$el.find("section.discussion")
#@$el.append(response.html)
window.user = new DiscussionUser(response.user_info)
$(event.target).html("Hide Discussion")
discussion = new Discussion()
discussion.reset(response.discussion_data, {silent: false})
view = new DiscussionView(el: $discussion[0], model: discussion)
$discussion = $(Mustache.render $("script#_inline_discussion").html(), {'threads':response.discussion_data})
$(".discussion-module").append($discussion)
discussion.each (thread) ->
element = $("article#thread_#{thread.id}")
dtv = new DiscussionThreadView el: element, model: thread
dtv.render()
DiscussionUtil.bulkUpdateContentInfo(window.$$annotated_content_info)
@retrieved = true
@showed = true
$ ->
if !window.$$contents
window.$$contents = {}
$.fn.extend
loading: ->
@$_loading = $("<span class='discussion-loading'></span>")
......
......@@ -46,7 +46,7 @@ class @DiscussionThreadView extends DiscussionContentView
renderResponses: ->
DiscussionUtil.safeAjax
url: @model.id
url: "/courses/#{$$course_id}/discussion/forum/#{@model.get('commentable_id')}/threads/#{@model.id}"
success: (data, textStatus, xhr) =>
@$(".loading").remove()
Content.loadContentInfos(data['annotated_content_info'])
......
......@@ -1393,13 +1393,6 @@ body.discussion {
.global-discussion-actions {
height: 60px;
@include linear-gradient(top, #ebebeb, #d9d9d9);
......@@ -1407,21 +1400,13 @@ body.discussion {
border-bottom: 1px solid #bcbcbc;
}
.discussion-module {
@extend .discussion-body
}
/* For some reason I have to do this to get the SCSS to compile, can't stick it under the above .discussion-module */
.discussion-module {
.discussion-reply-new {
display:none
}
}
<%include file="_underscore_templates.html" />
<div class="discussion-module">
<a class="discussion-show control-button" href="javascript:void(0)" discussion_id="${discussion_id | h}">Show Discussion</a>
</div>
......@@ -6,7 +6,7 @@
<a href="#" class="vote-btn discussion-vote discussion-vote-up"><span class="plus-icon">+</span> <span class='votes-count-number'>${'<%- votes["up_count"] %>'}</span></a>
<h1>${'<%- title %>'}</h1>
<p class="posted-details">
<span class="timeago" title="${'<%- created_at %>'}">sometime</span> by
<span class="timeago" title="${'<%- created_at %>'}">${'<%- created_at %>'}</span> by
<a href="${'<%- user_url %>'}">${'<%- username %>'}</a>
</p>
</header>
......@@ -26,7 +26,7 @@
<ol class="responses">
<li class="loading"><div class="loading-animation"></div></li>
</ol>
<form class="discussion-reply-new">
<form class="discussion-reply-new" data-id="${'<%- id %>'}">
<h4>Post a response:</h4>
<ul class="discussion-errors"></ul>
<div class="reply-body"></div>
......@@ -48,14 +48,14 @@
<ol class="comments">
<li>
<form class="comment-form">
<input type="text" placeholder="Comment" class="comment-form-input">
<input type="text" placeholder="Comment..." class="comment-form-input">
</form>
</li>
</ol>
</script>
<script type="text/template" id="response-comment-template">
<p><span class="response-body">${'<%- body %>'}</span><span class="posted-details">posted <span class="timeago" title="${'<%- created_at %>'}">sometime</span> by <a href="${'<%- user_url %>'}">${'<%- username %>'}</a></span></p>
<p><span class="response-body">${'<%- body %>'}</span><span class="posted-details">--posted <span class="timeago" title="${'<%- created_at %>'}">sometime</span> by <a href="${'<%- user_url %>'}">${'<%- username %>'}</a></span></p>
</script>
<script type="text/template" id="thread-list-item-template">
......
<section class="discussion">
{{#threads}}
<article class="discussion-article" data-id="{{id}}" id="thread_{{id}}">
</article>
{{/threads}}
</section>
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