").attr("id", "wmd-preview#{_append}").addClass("wmd-panel wmd-preview"))
$elem.append($wmdPanel)
diff --git a/lms/static/coffee/src/discussion.coffee b/lms/static/coffee/src/discussion.coffee
index bb9d7a267c..479c8f69dc 100644
--- a/lms/static/coffee/src/discussion.coffee
+++ b/lms/static/coffee/src/discussion.coffee
@@ -26,7 +26,7 @@ generateDiscussionLink = (cls, txt, handler) ->
Discussion =
replyTemplate: """
-
+
+
Submit
+
Cancel
+
"""
-
+
+ editThreadTemplate: """
+
+ """
+
+ editCommentTemplate: """
+
+ """
+
urlFor: (name, param) ->
{
watch_commentable : "/courses/#{$$course_id}/discussion/#{param}/watch"
@@ -140,15 +163,14 @@ Discussion =
$local(".thread").each(initializeVote).each(initializeWatchThreads)
initializeWatchDiscussion(discussion)
- if $$tags?
- $local(".new-post-tags").tagsInput
- autocomplete_url: Discussion.urlFor('tags_autocomplete')
- autocomplete:
- remoteDataType: 'json'
- interactive: true
- defaultText: "add a tag"
- height: "30px"
- removeWithBackspace: true
+ $local(".new-post-tags").tagsInput
+ autocomplete_url: Discussion.urlFor('tags_autocomplete')
+ autocomplete:
+ remoteDataType: 'json'
+ interactive: true
+ defaultText: "add a tag"
+ height: "30px"
+ removeWithBackspace: true
bindContentEvents: (content) ->
@@ -162,12 +184,6 @@ Discussion =
status = $discussionContent.attr("status") || "normal"
if status == "normal"
$local(".discussion-link").show()
- else if status == "reply"
- $local(".discussion-cancel-reply").show()
- $local(".discussion-submit-reply").show()
- else if status == "edit"
- $local(".discussion-cancel-edit").show()
- $local(".discussion-update-edit").show()
discussionContentHoverOut = ->
$local(".discussion-link").hide()
@@ -175,9 +191,9 @@ Discussion =
$discussionContent.hover(discussionContentHoverIn, discussionContentHoverOut)
handleReply = (elem) ->
- editView = $local(".discussion-reply-new")
- if editView.length
- editView.show()
+ $replyView = $local(".discussion-reply-new")
+ if $replyView.length
+ $replyView.show()
else
view = {
id: id
@@ -185,19 +201,16 @@ Discussion =
}
$discussionContent.append Mustache.render Discussion.replyTemplate, view
Markdown.makeWmdEditor $local(".reply-body"), "-reply-body-#{id}", Discussion.urlFor('upload')
- cancelReply = generateDiscussionLink("discussion-cancel-reply", "Cancel", handleCancelReply)
- submitReply = generateDiscussionLink("discussion-submit-reply", "Submit", handleSubmitReply)
+ $local(".discussion-submit-reply").click handleSubmitReply
+ $local(".discussion-cancel-reply").click handleCancelReply
$local(".discussion-link").hide()
- $(elem).after(submitReply).replaceWith(cancelReply)
$discussionContent.attr("status", "reply")
handleCancelReply = (elem) ->
- editView = $local(".discussion-reply-new")
- if editView.length
- editView.hide()
- $local(".discussion-submit-reply").remove()
+ $replyView = $local(".discussion-reply-new")
+ if $replyView.length
+ $replyView.hide()
reply = generateDiscussionLink("discussion-reply", "Reply", handleReply)
- $local(".discussion-link").show()
$(elem).replaceWith(reply)
$discussionContent.attr("status", "normal")
@@ -231,10 +244,76 @@ Discussion =
Discussion.handleAnchorAndReload(response)
, 'json'
+ handleCancelEdit = (elem) ->
+ $local(".discussion-content-edit").hide()
+ $local(".discussion-content-wrapper").show()
+
handleEditThread = (elem) ->
+ $local(".discussion-content-wrapper").hide()
+ $editView = $local(".discussion-content-edit")
+ if $editView.length
+ $editView.show()
+ else
+ view = {
+ id: id
+ title: $local(".thread-title").html()
+ body: $local(".thread-raw-body").html()
+ tags: $local(".thread-raw-tags").html()
+ }
+ $discussionContent.append Mustache.render Discussion.editThreadTemplate, view
+ Markdown.makeWmdEditor $local(".thread-body-edit"), "-thread-body-edit-#{id}", Discussion.urlFor('update_thread', id)
+ $local(".thread-tags-edit").tagsInput
+ autocomplete_url: Discussion.urlFor('tags_autocomplete')
+ autocomplete:
+ remoteDataType: 'json'
+ interactive: true
+ defaultText: ""
+ height: "30px"
+ removeWithBackspace: true
+ $local(".discussion-submit-update").unbind("click").click -> handleSubmitEditThread(this)
+ $local(".discussion-cancel-update").unbind("click").click -> handleCancelEdit(this)
+
+ handleSubmitEditThread = (elem) ->
+ url = Discussion.urlFor('update_thread', id)
+ 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($("
").addClass("new-post-form-error").html(error))
+ else
+ Discussion.handleAnchorAndReload(response)
+ , 'json'
handleEditComment = (elem) ->
-
+ $local(".discussion-content-wrapper").hide()
+ $editView = $local(".discussion-content-edit")
+ if $editView.length
+ $editView.show()
+ else
+ 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)
+ $local(".discussion-cancel-update").unbind("click").click -> handleCancelEdit(this)
+
+ 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($("").addClass("new-post-form-error").html(error))
+ else
+ Discussion.handleAnchorAndReload(response)
+ , 'json'
+
$local(".discussion-reply").click ->
handleReply(this)
diff --git a/lms/static/sass/_discussion.scss b/lms/static/sass/_discussion.scss
index a993925a18..4f5c3dd2f1 100644
--- a/lms/static/sass/_discussion.scss
+++ b/lms/static/sass/_discussion.scss
@@ -48,7 +48,7 @@ $discussion_input_width: 85%;
margin-top: flex-gutter(8);
}
}
-
+
.discussion-title {
@include discussion-font;
@include discussion-clickable;
@@ -104,16 +104,16 @@ $discussion_input_width: 85%;
float: left;
width: 70%;
}
- .new-post-form {
- .new-post-title, .new-post-body {
+ .new-post-form, .discussion-thread-edit {
+ .title-input, .body-input {
@include discussion-font;
display: block !important;
width: $discussion_input_width !important;
}
- .new-post-body {
+ .body-input {
margin-top: 10px;
}
- .discussion-new-post {
+ .control-button {
@include discussion-font;
color: #1d9dd9;
display: block;
@@ -127,6 +127,12 @@ $discussion_input_width: 85%;
height: 100%;
}
}
+ .discussion-content-edit, .discussion-reply-new {
+ .control-button {
+ display: inline-block;
+ }
+ margin: 10px 0 10px 0;
+ }
.thread {
//display: none;
margin-top: 30px;
diff --git a/lms/templates/discussion/inline.html b/lms/templates/discussion/inline.html
index dbd34305c3..42fac4e110 100644
--- a/lms/templates/discussion/inline.html
+++ b/lms/templates/discussion/inline.html
@@ -8,10 +8,10 @@
${search_bar}
% for thread in threads:
diff --git a/lms/templates/discussion/thread.html b/lms/templates/discussion/thread.html
index c72bb5aad0..97b71b8364 100644
--- a/lms/templates/discussion/thread.html
+++ b/lms/templates/discussion/thread.html
@@ -28,12 +28,13 @@
<%def name="render_content(content, type, **kwargs)">