diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index dc3c834d92..37afe981d0 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -164,9 +164,9 @@ def forum_form_discussion(request, course_id): def render_single_thread(request, discussion_id, course_id, thread_id): - thread = cc.Thread.find(thread_id).retrieve(recursive=True) + thread = cc.Thread.find(thread_id).retrieve(recursive=True).to_dict() - annotated_content_info = utils.get_annotated_content_infos(course_id, thread=thread.to_dict(), user=request.user) + annotated_content_info = utils.get_annotated_content_infos(course_id, thread=thread, user=request.user) context = { 'discussion_id': discussion_id, @@ -175,6 +175,7 @@ def render_single_thread(request, discussion_id, course_id, thread_id): 'annotated_content_info': json.dumps(annotated_content_info), 'course_id': course_id, 'request': request, + 'discussion_data': json.dumps({ discussion_id: [thread] }), } return render_to_string('discussion/_single_thread.html', context) @@ -201,7 +202,6 @@ def single_thread(request, course_id, discussion_id, thread_id): 'csrf': csrf(request)['csrf_token'], 'init': '', 'content': render_single_thread(request, discussion_id, course_id, thread_id), - 'accordion': render_accordion(request, course, discussion_id), 'course': course, 'course_id': course.id, } diff --git a/lms/djangoapps/django_comment_client/middleware.py b/lms/djangoapps/django_comment_client/middleware.py index 08e20b0296..e79eaf51d4 100644 --- a/lms/djangoapps/django_comment_client/middleware.py +++ b/lms/djangoapps/django_comment_client/middleware.py @@ -4,6 +4,7 @@ import json class AjaxExceptionMiddleware(object): def process_exception(self, request, exception): + import pdb; pdb.set_trace() if isinstance(exception, CommentClientError) and request.is_ajax(): return JsonError(json.loads(exception.message)) return None diff --git a/lms/lib/comment_client/models.py b/lms/lib/comment_client/models.py index 905f244783..3ce3858d2d 100644 --- a/lms/lib/comment_client/models.py +++ b/lms/lib/comment_client/models.py @@ -43,6 +43,9 @@ class Model(object): raise KeyError("Field {0} does not exist".format(key)) self.attributes.__setitem__(key, value) + def items(self, *args, **kwargs): + return self.attributes.items(*args, **kwargs) + def get(self, *args, **kwargs): return self.attributes.get(*args, **kwargs) diff --git a/lms/static/coffee/src/backbone_discussion/content.coffee b/lms/static/coffee/src/backbone_discussion/content.coffee index 1348494e86..5812c35e87 100644 --- a/lms/static/coffee/src/backbone_discussion/content.coffee +++ b/lms/static/coffee/src/backbone_discussion/content.coffee @@ -29,6 +29,32 @@ class @ContentView extends Backbone.View @$local.find(selector) showSingleThread: (event) -> + if @showed + @$el.children(".comments").hide() + @showed = false + $showComments = @$(".discussion-show-comments") + prevHtml = $showComments.html() + $showComments.html prevHtml.replace "Hide", "Show" + else + if @retrieved + @$el.children(".comments").show() + @showed = true + else + discussion_id = @model.discussion.id + url = DiscussionUtil.urlFor('retrieve_single_thread', discussion_id, @model.id) + DiscussionUtil.safeAjax + $elem: $.merge @$(".thread-title"), @$(".discussion-show-comments") + url: url + type: "GET" + dataType: 'json' + success: (response, textStatus) => + DiscussionUtil.bulkExtendContentInfo response['annotated_content_info'] + @retrieved = true + @showed = true + @$el.append(response['html']) + @model.get('comments').reset response.content.children, {silent: false} + @initCommentViews() + return $threadTitle = @$(".thread-title") $showComments = @$(".discussion-show-comments") @@ -133,15 +159,15 @@ class @ContentView extends Backbone.View @$(".discussion-votes-point").html response.votes.point endorse: (event) -> - url = DiscussionUtil.urlFor('endorse_comment', id) - endorsed = not @model.get('endorsed') + url = DiscussionUtil.urlFor('endorse_comment', @model.id) + endorsed = not @$el.hasClass("endorsed") Discussion.safeAjax $elem: $(event.target) url: url type: "POST" dataType: "json" data: {endorsed: endorsed} - success: (response, textStatus) -> + success: (response, textStatus) => if textStatus == "success" if endorsed @$el.addClass("endorsed") @@ -211,6 +237,7 @@ class @ContentView extends Backbone.View Discussion.extendContentInfo response.content['id'], response['annotated_content_info'] Discussion.initializeContent($content) Discussion.bindContentEvents($content) + delete: -> if $content.hasClass("thread") url = Discussion.urlFor('delete_thread', id) @@ -274,12 +301,25 @@ class @ContentView extends Backbone.View initTimeago: -> @$("span.timeago").timeago() + initPermalink: -> + + if @model.get('type') == 'thread' + discussion_id = @model.get('commentable_id') + permalink = Discussion.urlFor("permanent_link_thread", discussion_id, @model.id) + else + thread_id = @model.get('thread_id') + discussion_id = @$el.parents(".thread").attr("_discussion_id") + permalink = Discussion.urlFor("permanent_link_comment", discussion_id, thread_id, @model.id) + + @$(".discussion-permanent-link").attr "href", permalink + initialize: -> @model.view = @ @initLocal() @initVote() @initTimeago() @initBody() + @initPermalink() @initActions() @initCommentViews() diff --git a/lms/templates/discussion/_content.mustache b/lms/templates/discussion/_content.mustache index 95e95a8c4b..24be67ec91 100644 --- a/lms/templates/discussion/_content.mustache +++ b/lms/templates/discussion/_content.mustache @@ -1,4 +1,4 @@ -