diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 1743d49d49..0de42a1e82 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -133,6 +133,7 @@ def get_annotated_content_info(content, user, is_thread): 'editable': check_permissions_by_view(user, content, "update_thread" if is_thread else "update_comment"), 'can_reply': check_permissions_by_view(user, content, "create_comment" if is_thread else "create_sub_comment"), 'can_endorse': check_permissions_by_view(user, content, "endorse_comment") if not is_thread else False, + 'can_delete': check_permissions_by_view(user, content, "delete_thread" if is_thread else "delete_comment"), } def get_annotated_content_infos(thread, user): diff --git a/lms/static/coffee/src/discussion/content.coffee b/lms/static/coffee/src/discussion/content.coffee index 6141ad2351..69255b4c82 100644 --- a/lms/static/coffee/src/discussion/content.coffee +++ b/lms/static/coffee/src/discussion/content.coffee @@ -223,6 +223,24 @@ initializeFollowThread = (thread) -> error: (response, textStatus, e) -> console.log e + handleDelete = (elem) -> + if $content.hasClass("thread") + url = Discussion.urlFor('delete_thread', id) + else + url = Discussion.urlFor('delete_comment', id) + + Discussion.safeAjax + $elem: $(elem) + url: url + type: "POST" + dataType: "json" + data: {} + success: (response, textStatus) => + if textStatus == "success" + $(content).remove() + error: (response, textStatus, e) -> + console.log e + handleHideSingleThread = (elem) -> $threadTitle = $local(".thread-title") $showComments = $local(".discussion-show-comments") @@ -308,6 +326,9 @@ initializeFollowThread = (thread) -> else handleEditComment(this) + "click .discussion-delete": -> + handleDelete(this) + initializeContent: (content) -> $content = $(content) initializeVote $content @@ -326,3 +347,5 @@ initializeFollowThread = (thread) -> $local(".discussion-reply").remove() if not Discussion.getContentInfo id, 'can_endorse' $local(".discussion-endorse-control").remove() + if not Discussion.getContentInfo id, 'can_delete' + $local(".discussion-delete").remove() diff --git a/lms/templates/discussion/_thread.html b/lms/templates/discussion/_thread.html index 776596dd4d..a7865604cb 100644 --- a/lms/templates/discussion/_thread.html +++ b/lms/templates/discussion/_thread.html @@ -95,6 +95,9 @@ Close thread % endif % endif + + ${render_link("discussion-link discussion-delete", "Delete")} +