diff --git a/lms/static/coffee/src/discussion.coffee b/lms/static/coffee/src/discussion.coffee index 7aea3507c7..b3ee41203c 100644 --- a/lms/static/coffee/src/discussion.coffee +++ b/lms/static/coffee/src/discussion.coffee @@ -9,6 +9,7 @@ $ -> $('#open_close_accordion a').click @toggle $('#accordion').show() + $("section.discussion").each (index, discussion) -> Discussion.bindDiscussionEvents(discussion) @@ -32,7 +33,7 @@ Discussion = }[name] handleAnchorAndReload: (response) -> - window.location = window.location.pathname + "#" + response['id'] + #window.location = window.location.pathname + "#" + response['id'] window.location.reload() bindContentEvents: (content) -> @@ -100,12 +101,26 @@ Discussion = Discussion.handleAnchorAndReload(response) , 'json' + handleVote = (elem, value) -> + contentType = if $content.hasClass("thread") then "thread" else "comment" + url = Discussion.urlFor("#{value}vote_#{contentType}", $content.attr("_id")) + $.post url, {}, (response, textStatus) -> + if textStatus == "success" + Discussion.handleAnchorAndReload(response) + , 'json' + $local(".discussion-reply").click -> handleReply(this) $local(".discussion-cancel-reply").click -> handleCancelReply(this) + $local(".discussion-vote-up").click -> + handleVote(this, "up") + + $local(".discussion-vote-down").click -> + handleVote(this, "down") + bindDiscussionEvents: (discussion) -> $discussion = $(discussion) $discussionNonContent = $discussion.children(".discussion-non-content") diff --git a/lms/static/sass/_discussion.scss b/lms/static/sass/_discussion.scss index b7820ff4a9..a5c2b5ed4f 100644 --- a/lms/static/sass/_discussion.scss +++ b/lms/static/sass/_discussion.scss @@ -1,4 +1,4 @@ -$comment_margin_left: 20px; +$comment_margin_left: 30px; $discussion_title_size: 1.6em; $comment_title_size: 1.2em; $comment_body_size: 1.0em; @@ -45,6 +45,33 @@ $discussion_input_width: 60%; margin-bottom: 20px; display: block; } + .discussion-votes { + margin-right: 8px; + margin-top: 5px; + text-align: center; + height: 40px; + float: left; + .discussion-vote-count { + font-size: $comment_body_size; + @include discussion-font; + } + a.discussion-vote { + display: block; + color: black; + font-weight: bold; + font-size: 15px; + &.discussion-vote-up { + margin-bottom: 3px; + } + &.discussion-vote-down { + margin-top: 3px; + } + } + } + .discussion-right-wrapper { + min-height: 40px; + float: left; + } .new-post-form { .new-post-title, .new-post-body { @include discussion-font; @@ -105,6 +132,8 @@ $discussion_input_width: 60%; } } .discussion-content { + margin-top: 10px; + overflow: hidden; .discussion-content-edit { .comment-edit { @include discussion-font; @@ -118,16 +147,20 @@ $discussion_input_width: 60%; .comments { //display: none; margin-left: $comment_margin_left; - + overflow: hidden; .comment { .comment-body { @include discussion-font; font-size: $comment_body_size; - margin-top: 10px; + margin-top: 3px; display: block; color: black; } } + .discussion-votes { + margin-right: 6px; + margin-top: 6px; + } } } diff --git a/lms/templates/discussion/inline.html b/lms/templates/discussion/inline.html index 91c905bf1a..e4f0ca43d3 100644 --- a/lms/templates/discussion/inline.html +++ b/lms/templates/discussion/inline.html @@ -1,11 +1,4 @@ -<%! from django.core.urlresolvers import reverse %> - -<% -def url_for(thread_id): - return reverse('django_comment_client.forum.views.single_thread', args=[thread_id]) -%> - - +<%namespace name="renderer" file="thread.html"/>
@@ -18,61 +11,6 @@ def url_for(thread_id):
% for thread in threads: - ${render_thread(thread)} + ${renderer.render_thread(thread, edit_thread=False, show_comments=False)} % endfor
- -<%def name="render_thread(thread, edit_thread=False, show_comments=False)"> -
-
- ${thread['title']} -
-
${thread['body']}
-
- ${render_info(thread)} - % if edit_thread: - ${render_reply('')} - ${render_edit('')} - % endif -
-
-
- % if show_comments: -
- ${render_comments(thread['children'])} -
- % endif -
- - -<%def name="render_comments(comments)"> - % for comment in comments: -
-
-
- ${comment['body']} -
- ${render_info(comment)} - ${render_reply('')} - ${render_edit('')} -
-
-
-
- ${render_comments(comment['children'])} -
-
- % endfor - - -<%def name="render_info(content)"> - ${time_ago_in_words(parse(content['updated_at']))} ago by user No.${content['user_id']} - - -<%def name="render_reply(url)"> - Reply - - -<%def name="render_edit(url)"> - Edit - diff --git a/lms/templates/discussion/single_thread.html b/lms/templates/discussion/single_thread.html index 4a009c10cb..28b17ff477 100644 --- a/lms/templates/discussion/single_thread.html +++ b/lms/templates/discussion/single_thread.html @@ -1,61 +1,6 @@ -<%! from django.core.urlresolvers import reverse %> +<%namespace name="renderer" file="thread.html"/>
Discussion - ${render_thread(thread, edit_thread=True, show_comments=True)} + ${renderer.render_thread(thread, edit_thread=True, show_comments=True)}
- -<%def name="render_thread(thread, edit_thread=False, show_comments=False)"> -
-
- ${thread['title']} -
-
${thread['body']}
-
- ${render_info(thread)} - % if edit_thread: - ${render_reply('')} - ${render_edit('')} - % endif -
-
-
- % if show_comments: -
- ${render_comments(thread['children'])} -
- % endif -
- - -<%def name="render_comments(comments)"> - % for comment in comments: -
-
-
- ${comment['body']} -
- ${render_info(comment)} - ${render_reply('')} - ${render_edit('')} -
-
-
-
- ${render_comments(comment['children'])} -
-
- % endfor - - -<%def name="render_info(content)"> - ${time_ago_in_words(parse(content['updated_at']))} ago by user No.${content['user_id']} - - -<%def name="render_reply(url)"> - Reply - - -<%def name="render_edit(url)"> - Edit - diff --git a/lms/templates/discussion/thread.html b/lms/templates/discussion/thread.html new file mode 100644 index 0000000000..daaffb2939 --- /dev/null +++ b/lms/templates/discussion/thread.html @@ -0,0 +1,90 @@ +<%! from django.core.urlresolvers import reverse %> +<%! from datehelper import time_ago_in_words %> +<%! from dateutil.parser import parse %> + + + +<%def name="render_thread(thread, edit_thread=False, show_comments=False)"> + <% + if show_comments: + url_for_thread = "" + else: + thread_id = thread['id'] + url_for_thread = reverse('django_comment_client.forum.views.single_thread', args=[thread_id]) + %> +
+
+ ${render_vote(thread)} +
+ ${thread['title']} +
+
${thread['body']}
+
+ ${render_info(thread)} + % if edit_thread: + ${render_reply()} + ${render_edit()} + ${render_watch_thread()} + % endif +
+
+
+
+ % if show_comments: +
+ ${render_comments(thread['children'])} +
+ % endif +
+ + +<%def name="render_comments(comments)"> + % for comment in comments: +
+
+ ${render_vote(comment)} +
+
+ ${comment['body']} +
+ ${render_info(comment)} + ${render_reply()} + ${render_edit()} +
+
+
+
+
+ ${render_comments(comment['children'])} +
+
+ % endfor + + +<%def name="render_info(content)"> + ${time_ago_in_words(parse(content['updated_at']))} ago by user No.${content['user_id']} + + +<%def name="render_reply()"> + Reply + + +<%def name="render_edit()"> + Edit + + +<%def name="render_watch_thread()"> + Watch + + + +<%def name="render_vote(content)"> + <% + upvote = "˄" + downvote = "˅" + %> +
+ ${upvote} + ${downvote} +
+