Commit db94cc42 by Ibrahim Awwal

Allows replying to comments at any level of nesting, and removes the nesting limit.

Nested comments are displayed inline with an @reference.
parent be27907a
...@@ -39,7 +39,7 @@ GENERATE_RANDOM_USER_CREDENTIALS = False ...@@ -39,7 +39,7 @@ GENERATE_RANDOM_USER_CREDENTIALS = False
PERFSTATS = False PERFSTATS = False
DISCUSSION_SETTINGS = { DISCUSSION_SETTINGS = {
'MAX_COMMENT_DEPTH': 2, 'MAX_COMMENT_DEPTH': None, # Don't force a max comment depth
} }
# Features # Features
...@@ -128,7 +128,7 @@ NODE_PATH = ':'.join(node_paths) ...@@ -128,7 +128,7 @@ NODE_PATH = ':'.join(node_paths)
############################ OpenID Provider ################################## ############################ OpenID Provider ##################################
OPENID_PROVIDER_TRUSTED_ROOTS = ['cs50.net', '*.cs50.net'] OPENID_PROVIDER_TRUSTED_ROOTS = ['cs50.net', '*.cs50.net']
################################## MITXWEB ##################################### ################################## MITXWEB #####################################
# This is where we stick our compiled template files. Most of the app uses Mako # This is where we stick our compiled template files. Most of the app uses Mako
...@@ -158,7 +158,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( ...@@ -158,7 +158,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'askbot.user_messages.context_processors.user_messages',#must be before auth 'askbot.user_messages.context_processors.user_messages',#must be before auth
'django.contrib.auth.context_processors.auth', #this is required for admin 'django.contrib.auth.context_processors.auth', #this is required for admin
'django.core.context_processors.csrf', #necessary for csrf protection 'django.core.context_processors.csrf', #necessary for csrf protection
# Added for django-wiki # Added for django-wiki
'django.core.context_processors.media', 'django.core.context_processors.media',
'django.core.context_processors.tz', 'django.core.context_processors.tz',
...@@ -355,7 +355,7 @@ WIKI_CAN_ASSIGN = lambda article, user: user.is_staff or user.is_superuser ...@@ -355,7 +355,7 @@ WIKI_CAN_ASSIGN = lambda article, user: user.is_staff or user.is_superuser
WIKI_USE_BOOTSTRAP_SELECT_WIDGET = False WIKI_USE_BOOTSTRAP_SELECT_WIDGET = False
WIKI_LINK_LIVE_LOOKUPS = False WIKI_LINK_LIVE_LOOKUPS = False
WIKI_LINK_DEFAULT_LEVEL = 2 WIKI_LINK_DEFAULT_LEVEL = 2
################################# Jasmine ################################### ################################# Jasmine ###################################
JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee' JASMINE_TEST_DIRECTORY = PROJECT_ROOT + '/static/coffee'
...@@ -372,10 +372,10 @@ STATICFILES_FINDERS = ( ...@@ -372,10 +372,10 @@ STATICFILES_FINDERS = (
TEMPLATE_LOADERS = ( TEMPLATE_LOADERS = (
'mitxmako.makoloader.MakoFilesystemLoader', 'mitxmako.makoloader.MakoFilesystemLoader',
'mitxmako.makoloader.MakoAppDirectoriesLoader', 'mitxmako.makoloader.MakoAppDirectoriesLoader',
# 'django.template.loaders.filesystem.Loader', # 'django.template.loaders.filesystem.Loader',
# 'django.template.loaders.app_directories.Loader', # 'django.template.loaders.app_directories.Loader',
#'askbot.skins.loaders.filesystem_load_template_source', #'askbot.skins.loaders.filesystem_load_template_source',
# 'django.template.loaders.eggs.Loader', # 'django.template.loaders.eggs.Loader',
) )
...@@ -393,7 +393,7 @@ MIDDLEWARE_CLASSES = ( ...@@ -393,7 +393,7 @@ MIDDLEWARE_CLASSES = (
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'track.middleware.TrackMiddleware', 'track.middleware.TrackMiddleware',
'mitxmako.middleware.MakoMiddleware', 'mitxmako.middleware.MakoMiddleware',
'course_wiki.course_nav.Middleware', 'course_wiki.course_nav.Middleware',
'askbot.middleware.anon_user.ConnectToSessionMessagesMiddleware', 'askbot.middleware.anon_user.ConnectToSessionMessagesMiddleware',
...@@ -624,7 +624,7 @@ INSTALLED_APPS = ( ...@@ -624,7 +624,7 @@ INSTALLED_APPS = (
'certificates', 'certificates',
'instructor', 'instructor',
'psychometrics', 'psychometrics',
#For the wiki #For the wiki
'wiki', # The new django-wiki from benjaoming 'wiki', # The new django-wiki from benjaoming
'django_notify', 'django_notify',
......
...@@ -5,6 +5,7 @@ if Backbone? ...@@ -5,6 +5,7 @@ if Backbone?
events: events:
"click .discussion-submit-comment": "submitComment" "click .discussion-submit-comment": "submitComment"
"focus .wmd-input": "showEditorChrome" "focus .wmd-input": "showEditorChrome"
"click .comment-reply-link": "replyToComment"
$: (selector) -> $: (selector) ->
@$el.find(selector) @$el.find(selector)
...@@ -52,17 +53,17 @@ if Backbone? ...@@ -52,17 +53,17 @@ if Backbone?
}) })
renderComments: -> renderComments: ->
comments = new Comments() @comments = new Comments()
comments.comparator = (comment) -> @comments.comparator = (comment) ->
comment.get('created_at') comment.get('created_at')
collectComments = (comment) -> collectComments = (comment) =>
comments.add(comment) @comments.add(comment)
children = new Comments(comment.get('children')) children = new Comments(comment.get('children'))
children.each (child) -> children.each (child) ->
child.parent = comment child.parent = comment
collectComments(child) collectComments(child)
@model.get('comments').each collectComments @model.get('comments').each collectComments
comments.each (comment) => @renderComment(comment, false, null) @comments.each (comment) => @renderComment(comment, false, null)
renderComment: (comment) => renderComment: (comment) =>
comment.set('thread', @model.get('thread')) comment.set('thread', @model.get('thread'))
...@@ -73,11 +74,16 @@ if Backbone? ...@@ -73,11 +74,16 @@ if Backbone?
submitComment: (event) -> submitComment: (event) ->
event.preventDefault() event.preventDefault()
url = @model.urlFor('reply')
body = @getWmdContent("comment-body") body = @getWmdContent("comment-body")
return if not body.trim().length return if not body.trim().length
@setWmdContent("comment-body", "") @setWmdContent("comment-body", "")
comment = new Comment(body: body, created_at: (new Date()).toISOString(), username: window.user.get("username"), user_id: window.user.get("id"), id:"unsaved") comment = new Comment(body: body, created_at: (new Date()).toISOString(), username: window.user.get("username"), user_id: window.user.get("id"), id:"unsaved")
if @parentComment
url = @parentComment.urlFor('reply')
comment.parent = @parentComment
delete @parentComment # Remove reference so future comments aren't incorrectly parented
else
url = @model.urlFor('reply')
view = @renderComment(comment) view = @renderComment(comment)
@hideEditorChrome() @hideEditorChrome()
@trigger "comment:add", comment @trigger "comment:add", comment
...@@ -89,9 +95,10 @@ if Backbone? ...@@ -89,9 +95,10 @@ if Backbone?
dataType: 'json' dataType: 'json'
data: data:
body: body body: body
success: (response, textStatus) -> success: (response, textStatus) =>
comment.set(response.content) comment.set(response.content)
view.render() # This is just to update the id for the most part, but might be useful in general @comments.add(comment)
view.render()
delete: (event) => delete: (event) =>
event.preventDefault() event.preventDefault()
...@@ -186,3 +193,8 @@ if Backbone? ...@@ -186,3 +193,8 @@ if Backbone?
@renderShowView() @renderShowView()
@showCommentForm() @showCommentForm()
replyToComment: (event)=>
event.preventDefault()
elem = $(event.target)
@parentComment = @comments.get(elem.data('comment-id'))
@$('.wmd-input').focus()
...@@ -123,6 +123,7 @@ ...@@ -123,6 +123,7 @@
${"<% if (obj.username) { %>"} ${"<% if (obj.username) { %>"}
<a href="${'<%- user_url %>'}" class="profile-link">${'<%- username %>'}</a> <a href="${'<%- user_url %>'}" class="profile-link">${'<%- username %>'}</a>
${"<% } else {print('anonymous');} %>"} ${"<% } else {print('anonymous');} %>"}
<a class="comment-reply-link" href="#comment_${'<%- id %>'}" data-comment-id="${'<%- id %>'}">Reply</a>
</p> </p>
</div> </div>
</script> </script>
......
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