Commit d6b77077 by Rocky Duan

refactored reply rendering by using mustache

parent e705bbb7
...@@ -25,6 +25,19 @@ generateDiscussionLink = (cls, txt, handler) -> ...@@ -25,6 +25,19 @@ generateDiscussionLink = (cls, txt, handler) ->
Discussion = Discussion =
replyTemplate: """
<div class="discussion-reply-new">
<ul class="discussion-errors"></ul>
<div class="reply-body"></div>
<input type="checkbox" class="discussion-post-anonymously" id="discussion-post-anonymously-{{id}}" />
<label for="discussion-post-anonymously-{{id}}">post anonymously</label>
{{#showWatchCheckbox}}
<input type="checkbox" class="discussion-auto-watch" id="discussion-autowatch-{{id}}" checked />
<label for="discussion-auto-watch-{{id}}">watch this thread</label>
{{/showWatchCheckbox}}
</div>
"""
urlFor: (name, param) -> urlFor: (name, param) ->
{ {
watch_commentable : "/courses/#{$$course_id}/discussion/#{param}/watch" watch_commentable : "/courses/#{$$course_id}/discussion/#{param}/watch"
...@@ -162,38 +175,16 @@ Discussion = ...@@ -162,38 +175,16 @@ Discussion =
$discussionContent.hover(discussionContentHoverIn, discussionContentHoverOut) $discussionContent.hover(discussionContentHoverIn, discussionContentHoverOut)
handleReply = (elem) -> handleReply = (elem) ->
editView = $local(".discussion-content-edit") editView = $local(".discussion-reply-new")
if editView.length if editView.length
editView.show() editView.show()
else else
editView = $("<div>").addClass("discussion-content-edit") view = {
id: id
errorsField = $("<ul>").addClass("discussion-errors") showWatchCheckbox: $discussionContent.parent(".thread").attr("_id") not in $$user_info.subscribed_thread_ids
editView.append(errorsField) }
$discussionContent.append Mustache.render Discussion.replyTemplate, view
textarea = $("<div>").addClass("comment-edit") Markdown.makeWmdEditor $local(".reply-body"), "-reply-body-#{id}", Discussion.urlFor('upload')
editView.append(textarea)
anonymousCheckbox = $("<input>").attr("type", "checkbox")
.addClass("discussion-post-anonymously")
.attr("id", "discussion-post-anonymously-#{id}")
anonymousLabel = $("<label>").attr("for", "discussion-post-anonymously-#{id}")
.html("post anonymously")
editView.append(anonymousCheckbox).append(anonymousLabel)
if $discussionContent.parent(".thread").attr("_id") not in $$user_info.subscribed_thread_ids
watchCheckbox = $("<input>").attr("type", "checkbox")
.addClass("discussion-auto-watch")
.attr("id", "discussion-auto-watch-#{id}")
.attr("checked", "")
watchLabel = $("<label>").attr("for", "discussion-auto-watch-#{id}")
.html("watch this thread")
editView.append(watchCheckbox).append(watchLabel)
$discussionContent.append(editView)
Markdown.makeWmdEditor $local(".comment-edit"), "-comment-edit-#{id}", Discussion.urlFor('upload')
cancelReply = generateDiscussionLink("discussion-cancel-reply", "Cancel", handleCancelReply) cancelReply = generateDiscussionLink("discussion-cancel-reply", "Cancel", handleCancelReply)
submitReply = generateDiscussionLink("discussion-submit-reply", "Submit", handleSubmitReply) submitReply = generateDiscussionLink("discussion-submit-reply", "Submit", handleSubmitReply)
$local(".discussion-link").hide() $local(".discussion-link").hide()
...@@ -201,7 +192,7 @@ Discussion = ...@@ -201,7 +192,7 @@ Discussion =
$discussionContent.attr("status", "reply") $discussionContent.attr("status", "reply")
handleCancelReply = (elem) -> handleCancelReply = (elem) ->
editView = $local(".discussion-content-edit") editView = $local(".discussion-reply-new")
if editView.length if editView.length
editView.hide() editView.hide()
$local(".discussion-submit-reply").remove() $local(".discussion-submit-reply").remove()
...@@ -218,7 +209,7 @@ Discussion = ...@@ -218,7 +209,7 @@ Discussion =
else else
return return
body = $local("#wmd-input-comment-edit-#{id}").val() body = $local("#wmd-input-reply-body-#{id}").val()
anonymous = false || $local(".discussion-post-anonymously").is(":checked") anonymous = false || $local(".discussion-post-anonymously").is(":checked")
autowatch = false || $local(".discussion-auto-watch").is(":checked") autowatch = false || $local(".discussion-auto-watch").is(":checked")
......
...@@ -193,9 +193,9 @@ $discussion_input_width: 85%; ...@@ -193,9 +193,9 @@ $discussion_input_width: 85%;
.discussion-content { .discussion-content {
margin-top: 10px; margin-top: 10px;
overflow: hidden; overflow: hidden;
.discussion-content-edit { .discussion-reply-new {
margin-left: $comment_margin_left; margin-left: $comment_margin_left;
.comment-edit { .reply-body {
@include discussion-font; @include discussion-font;
width: $discussion_input_width !important; width: $discussion_input_width !important;
font-size: $comment_body_size; font-size: $comment_body_size;
......
...@@ -26,5 +26,6 @@ ...@@ -26,5 +26,6 @@
<script type="text/javascript" src="${static.url('js/vendor/Markdown.Editor.js')}"></script> <script type="text/javascript" src="${static.url('js/vendor/Markdown.Editor.js')}"></script>
<script type="text/javascript" src="${static.url('js/vendor/jquery.autocomplete.js')}"></script> <script type="text/javascript" src="${static.url('js/vendor/jquery.autocomplete.js')}"></script>
<script type="text/javascript" src="${static.url('js/vendor/jquery.tagsinput.js')}"></script> <script type="text/javascript" src="${static.url('js/vendor/jquery.tagsinput.js')}"></script>
<script type="text/javascript" src="${static.url('js/vendor/mustache.js')}"></script>
<link href="${static.url('css/vendor/jquery.tagsinput.css')}" rel="stylesheet" type="text/css"> <link href="${static.url('css/vendor/jquery.tagsinput.css')}" rel="stylesheet" type="text/css">
<link href="${static.url('css/vendor/jquery.autocomplete.css')}" rel="stylesheet" type="text/css"> <link href="${static.url('css/vendor/jquery.autocomplete.css')}" rel="stylesheet" type="text/css">
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