From 6b8e2c78abc75ae1ec2466dd1c88e5c5548ee255 Mon Sep 17 00:00:00 2001 From: Arjun Singh Date: Thu, 13 Sep 2012 21:58:59 -0700 Subject: [PATCH] Allow students to delete threads / respones; prepare for edit view for response comments (but not complete) --- .../django_comment_client/permissions.py | 4 +- .../views/response_comment_view.coffee | 49 +++++++++---------- .../discussion/_underscore_templates.html | 2 +- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/lms/djangoapps/django_comment_client/permissions.py b/lms/djangoapps/django_comment_client/permissions.py index 352d4cc187..bc51b14eb5 100644 --- a/lms/djangoapps/django_comment_client/permissions.py +++ b/lms/djangoapps/django_comment_client/permissions.py @@ -76,12 +76,12 @@ def check_conditions_permissions(user, permissions, course_id, **kwargs): VIEW_PERMISSIONS = { 'update_thread' : ['edit_content', ['update_thread', 'is_open', 'is_author']], 'create_comment' : [["create_comment", "is_open"]], - 'delete_thread' : ['delete_thread'], + 'delete_thread' : ['delete_thread', ['update_thread', 'is_author']], 'update_comment' : ['edit_content', ['update_comment', 'is_open', 'is_author']], 'endorse_comment' : ['endorse_comment'], 'openclose_thread' : ['openclose_thread'], 'create_sub_comment': [['create_sub_comment', 'is_open']], - 'delete_comment' : ['delete_comment'], + 'delete_comment' : ['delete_comment', ['update_comment', 'is_open', 'is_author']], 'vote_for_comment' : [['vote', 'is_open']], 'undo_vote_for_comment': [['unvote', 'is_open']], 'vote_for_thread' : [['vote', 'is_open']], diff --git a/lms/static/coffee/src/discussion/views/response_comment_view.coffee b/lms/static/coffee/src/discussion/views/response_comment_view.coffee index 3de715692b..f0bb9757d8 100644 --- a/lms/static/coffee/src/discussion/views/response_comment_view.coffee +++ b/lms/static/coffee/src/discussion/views/response_comment_view.coffee @@ -2,35 +2,30 @@ if Backbone? class @ResponseCommentView extends DiscussionContentView tagName: "li" - initLocal: -> - # TODO .response-local is the parent of the comments so @$local is null, not sure what was intended here... - @$local = @$el.find(".response-local") - @$delegateElement = @$local + $: (selector) -> + @$el.find(selector) + + initialize: -> + super() + @createShowView() render: -> - @template = _.template($("#response-comment-template").html()) - params = @model.toJSON() - params['deep'] = @model.hasOwnProperty('parent') - if @model.hasOwnProperty('parent') - params['parent_id'] = @model.parent.id - params['parent_username'] = @model.parent.get('username') - @$el.html(@template(params)) - @initLocal() - @delegateEvents() - @renderAttrs() - @markAsStaff() - @$el.find(".timeago").timeago() - @convertMath() + @renderShowView() @ - convertMath: -> - body = @$el.find(".response-body") - body.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight body.html() - # This removes paragraphs so that comments are more compact - body.children("p").each (index, elem) -> - $(elem).replaceWith($(elem).html()) - MathJax.Hub.Queue ["Typeset", MathJax.Hub, body[0]] + createShowView: () -> - markAsStaff: -> - if DiscussionUtil.isStaff(@model.get("user_id")) - @$el.find("a.profile-link").after('staff') + if @editView? + @editView.undelegateEvents() + @editView.$el.empty() + @editView = null + + @showView = new ResponseCommentShowView(model: @model) + + renderSubView: (view) -> + view.setElement(@$el) + view.render() + view.delegateEvents() + + renderShowView: () -> + @renderSubView(@showView) diff --git a/lms/templates/discussion/_underscore_templates.html b/lms/templates/discussion/_underscore_templates.html index d6011e75c0..5fc84c6676 100644 --- a/lms/templates/discussion/_underscore_templates.html +++ b/lms/templates/discussion/_underscore_templates.html @@ -93,7 +93,7 @@ -