Commit 12897fff by Rocky Duan

added title & tag for new post & fixed error handling; reply button in generated…

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