added title & tag for new post & fixed error handling; reply button in generated thread doesn't work
This commit is contained in:
@@ -113,7 +113,7 @@ class JsonError(HttpResponse):
|
||||
indent=2,
|
||||
ensure_ascii=False)
|
||||
super(JsonError, self).__init__(content,
|
||||
mimetype='application/json; charset=utf8', status=500)
|
||||
mimetype='application/json; charset=utf8', status=400)
|
||||
|
||||
class HtmlResponse(HttpResponse):
|
||||
def __init__(self, html=''):
|
||||
|
||||
@@ -74,7 +74,8 @@ initializeFollowThread = (thread) ->
|
||||
body: body
|
||||
anonymous: anonymous
|
||||
autowatch: autowatch
|
||||
success: Discussion.formErrorHandler($local(".discussion-errors"), (response, textStatus) ->
|
||||
error: Discussion.formErrorHandler($local(".discussion-errors"))
|
||||
success: (response, textStatus) ->
|
||||
$comment = $(response.html)
|
||||
$content.children(".comments").prepend($comment)
|
||||
Discussion.setWmdContent $content, $local, "reply-body", ""
|
||||
@@ -86,7 +87,6 @@ initializeFollowThread = (thread) ->
|
||||
$local(".discussion-reply").show()
|
||||
$local(".discussion-edit").show()
|
||||
$discussionContent.attr("status", "normal")
|
||||
)
|
||||
|
||||
handleVote = (elem, value) ->
|
||||
contentType = if $content.hasClass("thread") then "thread" else "comment"
|
||||
@@ -148,11 +148,11 @@ initializeFollowThread = (thread) ->
|
||||
type: "POST"
|
||||
dataType: 'json'
|
||||
data: {title: title, body: body, tags: tags},
|
||||
success: Discussion.formErrorHandler($local(".discussion-update-errors"), (response, textStatus) ->
|
||||
error: Discussion.formErrorHandler($local(".discussion-update-errors"))
|
||||
success: (response, textStatus) ->
|
||||
$discussionContent.replaceWith(response.html)
|
||||
Discussion.initializeContent($content)
|
||||
Discussion.bindContentEvents($content)
|
||||
)
|
||||
|
||||
handleEditComment = (elem) ->
|
||||
$local(".discussion-content-wrapper").hide()
|
||||
@@ -175,11 +175,11 @@ initializeFollowThread = (thread) ->
|
||||
type: "POST"
|
||||
dataType: "json"
|
||||
data: {body: body}
|
||||
success: Discussion.formErrorHandler($local(".discussion-update-errors"), (response, textStatus) ->
|
||||
error: Discussion.formErrorHandler($local(".discussion-update-errors"))
|
||||
success: (response, textStatus) ->
|
||||
$discussionContent.replaceWith(response.html)
|
||||
Discussion.initializeContent($content)
|
||||
Discussion.bindContentEvents($content)
|
||||
)
|
||||
|
||||
handleEndorse = (elem, endorsed) ->
|
||||
url = Discussion.urlFor('endorse_comment', id)
|
||||
|
||||
@@ -46,7 +46,8 @@ initializeFollowDiscussion = (discussion) ->
|
||||
title: title
|
||||
body: body
|
||||
tags: tags
|
||||
success: Discussion.formErrorHandler($local(".new-post-form-error"), (response, textStatus) ->
|
||||
error: Discussion.formErrorHandler($local(".new-post-form-errors"))
|
||||
success: (response, textStatus) ->
|
||||
$thread = $(response.html)
|
||||
$discussion.children(".threads").prepend($thread)
|
||||
Discussion.setWmdContent $discussion, $local, "new-post-body", ""
|
||||
@@ -55,7 +56,6 @@ initializeFollowDiscussion = (discussion) ->
|
||||
Discussion.bindContentEvents($thread)
|
||||
$(".new-post-form").hide()
|
||||
$local(".discussion-new-post").show()
|
||||
)
|
||||
|
||||
handleCancelNewPost = (elem) ->
|
||||
$local(".new-post-form").hide()
|
||||
@@ -96,9 +96,11 @@ initializeFollowDiscussion = (discussion) ->
|
||||
|
||||
initializeNewPost = (elem) ->
|
||||
#newPostForm = $local(".new-post-form")
|
||||
#view = { discussion_id: id }
|
||||
#$newPostButton = $local(".discussion-new-post")
|
||||
#$newPostButton.after Mustache.render Discussion.newPostTemplate, view
|
||||
view = { discussion_id: id }
|
||||
$discussionNonContent = $discussion.children(".discussion-non-content")
|
||||
|
||||
$discussionNonContent.append Mustache.render Discussion.newPostTemplate, view
|
||||
newPostBody = $discussion.find(".new-post-body")
|
||||
if newPostBody.length
|
||||
Discussion.makeWmdEditor $discussion, $local, "new-post-body"
|
||||
|
||||
@@ -7,18 +7,18 @@ Discussion = @Discussion
|
||||
@Discussion = $.extend @Discussion,
|
||||
|
||||
newPostTemplate: """
|
||||
<form class="new-post-form" _id="{{discussion_id}}">
|
||||
<ul class="discussion-errors new-post-form-error"></ul>
|
||||
<input type="text" class="new-post-title title-input" placeholder="Title"/>
|
||||
<div class="new-post-similar-posts-wrapper" style="display: none">
|
||||
Similar Posts:
|
||||
<a class="hide-similar-posts" href="javascript:void(0)">Hide</a>
|
||||
<div class="new-post-similar-posts"></div>
|
||||
<form class="new-post-form collapsed" id="new-post-form" style="display: block; ">
|
||||
<ul class="new-post-form-errors discussion-errors"></ul>
|
||||
<input type="text" class="new-post-title title-input" placeholder="Title" />
|
||||
<div class="new-post-body reply-body"></div>
|
||||
<input class="new-post-tags" placeholder="Tags" />
|
||||
<div class="post-options">
|
||||
<input type="checkbox" class="discussion-post-anonymously" id="discussion-post-anonymously-${discussion_id}">
|
||||
<label for="discussion-post-anonymously-${discussion_id}">post anonymously</label>
|
||||
<input type="checkbox" class="discussion-auto-watch" id="discussion-autowatch-${discussion_id}" checked="">
|
||||
<label for="discussion-auto-watch-${discussion_id}">follow this thread</label>
|
||||
</div>
|
||||
<div class="new-post-body body-input"></div>
|
||||
<input class="new-post-tags" placeholder="Tags"/>
|
||||
<div class = "new-post-control">
|
||||
<a class="discussion-cancel-post" href="javascript:void(0)">Cancel</a>
|
||||
<div class="reply-post-control">
|
||||
<a class="discussion-submit-post control-button" href="javascript:void(0)">Submit</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -67,9 +67,9 @@ wmdEditors = {}
|
||||
autocomplete:
|
||||
remoteDataType: 'json'
|
||||
interactive: true
|
||||
height: '30px'
|
||||
width: '100%'
|
||||
defaultText: "Tag your post: press enter after each tag"
|
||||
height: "30px"
|
||||
width: "100%"
|
||||
removeWithBackspace: true
|
||||
|
||||
isSubscribed: (id, type) ->
|
||||
@@ -88,14 +88,13 @@ wmdEditors = {}
|
||||
isDownvoted: (id) ->
|
||||
$$user_info? and (id in $$user_info.downvoted_ids)
|
||||
|
||||
formErrorHandler: (errorsField, success) ->
|
||||
(response, textStatus, xhr) ->
|
||||
formErrorHandler: (errorsField) ->
|
||||
(xhr, textStatus, error) ->
|
||||
response = JSON.parse(xhr.responseText)
|
||||
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)
|
||||
|
||||
postMathJaxProcessor: (text) ->
|
||||
RE_INLINEMATH = /^\$([^\$]*)\$/g
|
||||
@@ -135,7 +134,7 @@ wmdEditors = {}
|
||||
|
||||
setWmdContent: ($content, $local, cls_identifier, text) ->
|
||||
Discussion.getWmdInput($content, $local, cls_identifier).val(text)
|
||||
wmdEditors["#{cls_identifier}-#{id}"].refreshPreview()
|
||||
Discussion.getWmdEditor($content, $local, cls_identifier).refreshPreview()
|
||||
|
||||
getContentInfo: (id, attr) ->
|
||||
if not window.$$annotated_content_info?
|
||||
|
||||
@@ -622,9 +622,21 @@ $tag-text-color: #5b614f;
|
||||
a:hover {
|
||||
color: #1C71DD;
|
||||
text-decoration: none;
|
||||
};
|
||||
}
|
||||
|
||||
.new-post-title {
|
||||
height: 35px;
|
||||
padding: 5px 12px;
|
||||
border-width: 1px;
|
||||
}
|
||||
|
||||
&.collapsed {
|
||||
.new-post-title {
|
||||
height: 0;
|
||||
padding: 0;
|
||||
border-width: 0;
|
||||
}
|
||||
|
||||
.wmd-button-row {
|
||||
height: 0;
|
||||
}
|
||||
@@ -647,6 +659,10 @@ $tag-text-color: #5b614f;
|
||||
.reply-post-control {
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.tagsinput {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.new-post-control {
|
||||
|
||||
@@ -4,19 +4,6 @@
|
||||
<section class="discussion inline-discussion" _id="${discussion_id}">
|
||||
|
||||
<div class="discussion-non-content discussion-local">
|
||||
<form class="new-post-form collapsed" id="new-post-form" style="display: block; ">
|
||||
<ul class="discussion-errors"></ul>
|
||||
<div class="new-post-body reply-body"></div>
|
||||
<div class="post-options">
|
||||
<input type="checkbox" class="discussion-post-anonymously" id="discussion-post-anonymously-${discussion_id}">
|
||||
<label for="discussion-post-anonymously-${discussion_id}">post anonymously</label>
|
||||
<input type="checkbox" class="discussion-auto-watch" id="discussion-autowatch-${discussion_id}" checked="">
|
||||
<label for="discussion-auto-watch-${discussion_id}">follow this thread</label>
|
||||
</div>
|
||||
<div class="reply-post-control">
|
||||
<a class="discussion-submit-post control-button" href="javascript:void(0)">Submit</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="threads">
|
||||
|
||||
Reference in New Issue
Block a user