Commit 51961c1c by Rocky Duan

Merge branch 'master' into discussion2

parents 4749f3a5 cc477138
......@@ -10,8 +10,8 @@ urlpatterns = patterns('django_comment_client.base.views',
url(r'threads/(?P<thread_id>[\w\-]+)/delete', 'delete_thread', name='delete_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/upvote$', 'vote_for_thread', {'value': 'up'}, name='upvote_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/downvote$', 'vote_for_thread', {'value': 'down'}, name='downvote_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/watch$', 'watch_thread', name='watch_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/unwatch$', 'unwatch_thread', name='unwatch_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/follow$', 'follow_thread', name='follow_thread'),
url(r'threads/(?P<thread_id>[\w\-]+)/unfollow$', 'unfollow_thread', name='unfollow_thread'),
url(r'comments/(?P<comment_id>[\w\-]+)/update$', 'update_comment', name='update_comment'),
url(r'comments/(?P<comment_id>[\w\-]+)/endorse$', 'endorse_comment', name='endorse_comment'),
......@@ -21,8 +21,8 @@ urlpatterns = patterns('django_comment_client.base.views',
url(r'comments/(?P<comment_id>[\w\-]+)/downvote$', 'vote_for_comment', {'value': 'down'}, name='downvote_comment'),
url(r'(?P<commentable_id>[\w\-]+)/threads/create$', 'create_thread', name='create_thread'),
url(r'(?P<commentable_id>[\w\-]+)/watch$', 'watch_commentable', name='watch_commentable'),
url(r'(?P<commentable_id>[\w\-]+)/unwatch$', 'unwatch_commentable', name='unwatch_commentable'),
url(r'(?P<commentable_id>[\w\-]+)/follow$', 'follow_commentable', name='follow_commentable'),
url(r'(?P<commentable_id>[\w\-]+)/unfollow$', 'unfollow_commentable', name='unfollow_commentable'),
url(r'search$', 'search', name='search'),
)
......@@ -140,42 +140,42 @@ def vote_for_thread(request, course_id, thread_id, value):
@login_required
@require_POST
def watch_thread(request, course_id, thread_id):
def follow_thread(request, course_id, thread_id):
user_id = request.user.id
response = comment_client.subscribe_thread(user_id, thread_id)
return JsonResponse(response)
@login_required
@require_POST
def watch_commentable(request, course_id, commentable_id):
def follow_commentable(request, course_id, commentable_id):
user_id = request.user.id
response = comment_client.subscribe_commentable(user_id, commentable_id)
return JsonResponse(response)
@login_required
@require_POST
def follow(request, course_id, followed_user_id):
def follow_user(request, course_id, followed_user_id):
user_id = request.user.id
response = comment_client.follow(user_id, followed_user_id)
return JsonResponse(response)
@login_required
@require_POST
def unwatch_thread(request, course_id, thread_id):
def unfollow_thread(request, course_id, thread_id):
user_id = request.user.id
response = comment_client.unsubscribe_thread(user_id, thread_id)
return JsonResponse(response)
@login_required
@require_POST
def unwatch_commentable(request, course_id, commentable_id):
def unfollow_commentable(request, course_id, commentable_id):
user_id = request.user.id
response = comment_client.unsubscribe_commentable(user_id, commentable_id)
return JsonResponse(response)
@login_required
@require_POST
def unfollow(request, course_id, followed_user_id):
def unfollow_user(request, course_id, followed_user_id):
user_id = request.user.id
response = comment_client.unfollow(user_id, followed_user_id)
return JsonResponse(response)
......
......@@ -28,9 +28,10 @@ Discussion = @Discussion
if $replyView.length
$replyView.show()
else
thread_id = $discussionContent.parents(".thread").attr("_id")
view = {
id: id
showWatchCheckbox: $discussionContent.parents(".thread").attr("_id") not in $$user_info.subscribed_thread_ids
showWatchCheckbox: not Discussion.isSubscribed(thread_id, "thread")
}
$discussionContent.append Mustache.render Discussion.replyTemplate, view
Markdown.makeWmdEditor $local(".reply-body"), "-reply-body-#{id}", Discussion.urlFor('upload')
......@@ -61,19 +62,15 @@ Discussion = @Discussion
autowatch = false || $local(".discussion-auto-watch").is(":checked")
Discussion.safeAjax
$elem: $(elem)
url: url
type: "POST"
data:
body: body
anonymous: anonymous
autowatch: autowatch
success: (response, textStatus) ->
if response.errors? and response.errors.length > 0
errorsField = $local(".discussion-errors").empty()
for error in response.errors
errorsField.append($("<li>").addClass("new-post-form-error").html(error))
else
Discussion.handleAnchorAndReload(response)
success: Discussion.formErrorHandler $local(".discussion-errors"), (response, textStatus) ->
Discussion.handleAnchorAndReload(response)
dataType: 'json'
handleVote = (elem, value) ->
......@@ -119,14 +116,13 @@ Discussion = @Discussion
title = $local(".thread-title-edit").val()
body = $local("#wmd-input-thread-body-edit-#{id}").val()
tags = $local(".thread-tags-edit").val()
$.post url, {title: title, body: body, tags: tags}, (response, textStatus) ->
if response.errors
errorsField = $local(".discussion-update-errors").empty()
for error in response.errors
errorsField.append($("<li>").addClass("new-post-form-error").html(error))
else
$.ajax
url: url
type: "POST"
data: {title: title, body: body, tags: tags},
success: Discussion.formErrorHandler $local(".discussion-update-errors"), (response, textStatus) ->
Discussion.handleAnchorAndReload(response)
, 'json'
dataType: 'json'
handleEditComment = (elem) ->
$local(".discussion-content-wrapper").hide()
......@@ -134,10 +130,7 @@ Discussion = @Discussion
if $editView.length
$editView.show()
else
view = {
id: id
body: $local(".comment-raw-body").html()
}
view = { id: id, body: $local(".comment-raw-body").html() }
$discussionContent.append Mustache.render Discussion.editCommentTemplate, view
Markdown.makeWmdEditor $local(".comment-body-edit"), "-comment-body-edit-#{id}", Discussion.urlFor('update_comment', id)
$local(".discussion-submit-update").unbind("click").click -> handleSubmitEditComment(this)
......@@ -146,14 +139,13 @@ Discussion = @Discussion
handleSubmitEditComment= (elem) ->
url = Discussion.urlFor('update_comment', id)
body = $local("#wmd-input-comment-body-edit-#{id}").val()
$.post url, {body: body}, (response, textStatus) ->
if response.errors
errorsField = $local(".discussion-update-errors").empty()
for error in response.errors
errorsField.append($("<li>").addClass("new-post-form-error").html(error))
else
$.ajax
url: url
data: {body: body}
type: "POST"
success: Discussion.formErrorHandler $local(".discussion-update-errors"), (response, textStatus) ->
Discussion.handleAnchorAndReload(response)
, 'json'
dataType: "json"
handleEndorse = (elem) ->
url = Discussion.urlFor('endorse_comment', id)
......@@ -203,35 +195,38 @@ Discussion = @Discussion
rebindHideEvents()
dataType: 'json'
$local(".thread-title").click handleShowSingleThread
Discussion.bindLocalEvents $local,
$local(".discussion-show-comments").click handleShowSingleThread
"click .thread-title": ->
handleShowSingleThread(this)
$local(".discussion-reply-thread").click ->
handleShowSingleThread($local(".thread-title"))
handleReply(this)
"click .discussion-show-comments": ->
handleShowSingleThread(this)
$local(".discussion-reply-comment").click ->
handleReply(this)
"click .discussion-reply-thread": ->
handleShowSingleThread($local(".thread-title"))
handleReply(this)
$local(".discussion-cancel-reply").click ->
handleCancelReply(this)
"click .discussion-reply-comment": ->
handleReply(this)
$local(".discussion-vote-up").click ->
handleVote(this, "up")
"click .discussion-cancel-reply": ->
handleCancelReply(this)
$local(".discussion-vote-down").click ->
handleVote(this, "down")
"click .discussion-vote-up": ->
handleVote(this, "up")
$local(".discussion-endorse").click ->
handleEndorse(this)
"click .discussion-vote-down": ->
handleVote(this, "down")
$local(".discussion-edit").click ->
if $content.hasClass("thread")
handleEditThread(this)
else
handleEditComment(this)
"click .discussion-endorse": ->
handleEndorse(this)
"click .discussion-edit": ->
if $content.hasClass("thread")
handleEditThread(this)
else
handleEditComment(this)
initializeContent: (content) ->
$content = $(content)
......
$ ->
Discussion = window.Discussion
console.log "here"
if $('#accordion').length
active = $('#accordion ul:has(li.active)').index('#accordion ul')
$('#accordion').bind('accordionchange', @log).accordion
......
......@@ -9,23 +9,23 @@ Discussion = @Discussion
(selector) -> $(elem).find(selector)
generateDiscussionLink: (cls, txt, handler) ->
$("<a>").addClass("discussion-link").
attr("href", "javascript:void(0)").
addClass(cls).html(txt).
click(-> handler(this))
$("<a>").addClass("discussion-link")
.attr("href", "javascript:void(0)")
.addClass(cls).html(txt)
.click -> handler(this)
urlFor: (name, param, param1) ->
{
watch_commentable : "/courses/#{$$course_id}/discussion/#{param}/watch"
unwatch_commentable : "/courses/#{$$course_id}/discussion/#{param}/unwatch"
follow_discussion : "/courses/#{$$course_id}/discussion/#{param}/follow"
unfollow_discussion : "/courses/#{$$course_id}/discussion/#{param}/unfollow"
create_thread : "/courses/#{$$course_id}/discussion/#{param}/threads/create"
update_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/update"
create_comment : "/courses/#{$$course_id}/discussion/threads/#{param}/reply"
delete_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/delete"
upvote_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/upvote"
downvote_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/downvote"
watch_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/watch"
unwatch_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unwatch"
follow_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/follow"
unfollow_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unfollow"
update_comment : "/courses/#{$$course_id}/discussion/comments/#{param}/update"
endorse_comment : "/courses/#{$$course_id}/discussion/comments/#{param}/endorse"
create_sub_comment : "/courses/#{$$course_id}/discussion/comments/#{param}/reply"
......@@ -50,3 +50,35 @@ Discussion = @Discussion
handleAnchorAndReload: (response) ->
#window.location = window.location.pathname + "#" + response['id']
window.location.reload()
bindLocalEvents: ($local, eventsHandler) ->
for eventSelector, handler of eventsHandler
[event, selector] = eventSelector.split(' ')
$local(selector)[event] handler
tagsInputOptions: ->
autocomplete_url: Discussion.urlFor('tags_autocomplete')
autocomplete:
remoteDataType: 'json'
interactive: true
defaultText: "Tag your post: press enter after each tag"
height: "30px"
width: "100%"
removeWithBackspace: true
isSubscribed: (id, type) ->
if type == "thread"
id in $$user_info.subscribed_thread_ids
else if type == "commentable" or type == "discussion"
id in $$user_info.subscribed_commentable_ids
else
id in $$user_info.subscribed_user_ids
formErrorHandler: (errorsField, success) ->
(response, textStatus, xhr) ->
if response.errors? and response.errors.length > 0
errorsField.empty()
for error in response.errors
errorsField.append($("<li>").addClass("new-post-form-error").html(error))
else
success(response, textStatus, xhr)
......@@ -3,16 +3,16 @@
<%def name="link_to_sort(key, title)">
% if key == sort_key:
% if sort_order.lower() == 'desc':
${_link_to_sort(key, 'asc', title + ' [v]')}
${_link_to_sort(key, 'asc', title + ' [v]', 'sorted')}
% else:
${_link_to_sort(key, 'desc', title + ' [^]')}
${_link_to_sort(key, 'desc', title + ' [^]', 'sorted')}
% endif
% else:
${_link_to_sort(key, 'desc', title)}
% endif
</%def>
<%def name="_link_to_sort(key, order, title)">
<%def name="_link_to_sort(key, order, title, cls='')">
<%
def merge(dic1, dic2):
return dict(dic1.items() + dic2.items())
......@@ -21,9 +21,9 @@
return base_url + '?' + urlencode(merge(query_params, {'page': 1, 'sort_key': key, 'sort_order': order}))
%>
% if discussion_type == 'inline':
<a class="discussion-sort-link discussion-inline-sort-link" href="javascript:void(0)" sort-url="${url_for_sort(key, order)}">${title}</a>
<a class="discussion-sort-link discussion-inline-sort-link ${cls}" href="javascript:void(0)" sort-url="${url_for_sort(key, order)}">${title}</a>
% else:
<a class="discussion-sort-link" href="${url_for_sort(key, order)}">${title}</a>
<a class="discussion-sort-link ${cls}" href="${url_for_sort(key, order)}">${title}</a>
% endif
</%def>
......
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