Commit 7030d1f1 by Rocky Duan

fixed endorse&edit&delete

parent 2f469f0f
......@@ -183,6 +183,8 @@ initializeFollowThread = (thread) ->
handleEndorse = (elem, endorsed) ->
url = Discussion.urlFor('endorse_comment', id)
console.log endorsed
console.log url
Discussion.safeAjax
$elem: $(elem)
url: url
......@@ -196,6 +198,9 @@ initializeFollowThread = (thread) ->
else
$(content).removeClass("endorsed")
$(elem).unbind('click').click ->
handleEndorse(elem, !endorsed)
handleOpenClose = (elem, text) ->
url = Discussion.urlFor('openclose_thread', id)
closed = undefined
......@@ -314,19 +319,19 @@ initializeFollowThread = (thread) ->
else
handleVote($elem, "down")
"click .discussion-endorse": ->
handleEndorse(this, $(this).is(":checked"))
"click .admin-endorse": ->
handleEndorse(this, true)#, $(this).is(":checked"))
"click .discussion-openclose": ->
handleOpenClose(this, $(this).text())
"click .discussion-edit": ->
"click .admin-edit": ->
if $content.hasClass("thread")
handleEditThread(this)
else
handleEditComment(this)
"click .discussion-delete": ->
"click .admin-delete": ->
handleDelete(this)
initializeContent: (content) ->
......
......@@ -36,7 +36,7 @@ initializeFollowDiscussion = (discussion) ->
title = $local(".new-post-title").val()
body = Discussion.getWmdContent $discussion, $local, "new-post-body"
tags = $local(".new-post-tags").val()
url = Discussion.urlFor('create_thread', $local(".new-post-form").attr("_id"))
url = Discussion.urlFor('create_thread', id)
Discussion.safeAjax
$elem: $(elem)
url: url
......@@ -95,33 +95,33 @@ initializeFollowDiscussion = (discussion) ->
$wrapper.hide()
$title.attr("prev-text", text)
handleNewPost = (elem) ->
newPostForm = $local(".new-post-form")
if newPostForm.length
newPostForm.show()
$(elem).hide()
else
view = { discussion_id: id }
$newPostButton = $local(".discussion-new-post")
$newPostButton.after Mustache.render Discussion.newPostTemplate, view
newPostBody = $discussion.find(".new-post-body")
if newPostBody.length
Discussion.makeWmdEditor $discussion, $local, "new-post-body"
initializeNewPost = (elem) ->
#newPostForm = $local(".new-post-form")
#view = { discussion_id: id }
#$newPostButton = $local(".discussion-new-post")
#$newPostButton.after Mustache.render Discussion.newPostTemplate, view
newPostBody = $discussion.find(".new-post-body")
if newPostBody.length
Discussion.makeWmdEditor $discussion, $local, "new-post-body"
$input = Discussion.getWmdInput($discussion, $local, "new-post-body")
$input.attr("placeholder", "post a new topic...").bind 'focus', (e) ->
$local(".new-post-form").removeClass('collapsed')
$local(".new-post-tags").tagsInput Discussion.tagsInputOptions()
$local(".new-post-tags").tagsInput Discussion.tagsInputOptions()
$local(".new-post-title").blur ->
handleSimilarPost(this)
$local(".new-post-title").blur ->
handleSimilarPost(this)
$local(".hide-similar-posts").click ->
$local(".new-post-similar-posts-wrapper").hide()
$local(".hide-similar-posts").click ->
$local(".new-post-similar-posts-wrapper").hide()
$local(".discussion-submit-post").click ->
handleSubmitNewPost(this)
$local(".discussion-cancel-post").click ->
handleCancelNewPost(this)
$local(".discussion-submit-post").click ->
handleSubmitNewPost(this)
$local(".discussion-cancel-post").click ->
handleCancelNewPost(this)
$(elem).hide()
#$(elem).hide()
handleAjaxReloadDiscussion = (elem, url) ->
$elem = $(elem)
......@@ -151,6 +151,8 @@ initializeFollowDiscussion = (discussion) ->
$elem = $(elem)
url = $elem.attr("page-url")
handleAjaxReloadDiscussion($elem, url)
initializeNewPost()
Discussion.bindLocalEvents $local,
......@@ -158,8 +160,8 @@ initializeFollowDiscussion = (discussion) ->
event.preventDefault()
handleAjaxSearch(this)
"click .discussion-new-post": ->
handleNewPost(this)
#"click .discussion-new-post": ->
# handleNewPost(this)
"click .discussion-search-link": ->
handleAjaxSearch($local(".search-wrapper>.discussion-search-form"))
......
......@@ -116,20 +116,26 @@ wmdEditors = {}
appended_id = "-#{cls_identifier}-#{id}"
imageUploadUrl = Discussion.urlFor('upload')
editor = Markdown.makeWmdEditor elem, appended_id, imageUploadUrl, Discussion.postMathJaxProcessor
console.log editor
wmdEditors["#{cls_identifier}-#{id}"] = editor
$input = $("#wmd-input-#{cls_identifier}-#{id}")
$input.attr("placeholder", "post a new topic...").bind 'focus', (e) ->
$('.new-post-form').removeClass('collapsed')
editor
getWmdEditor: ($content, $local, cls_identifier) ->
id = $content.attr("_id")
wmdEditors["#{cls_identifier}-#{id}"]
getWmdContent: ($content, $local, cls_identifier) ->
getWmdInput: ($content, $local, cls_identifier) ->
id = $content.attr("_id")
$local("#wmd-input-#{cls_identifier}-#{id}").val()
$local("#wmd-input-#{cls_identifier}-#{id}")
getWmdContent: ($content, $local, cls_identifier) ->
Discussion.getWmdInput($content, $local, cls_identifier).val()
setWmdContent: ($content, $local, cls_identifier, text) ->
id = $content.attr("_id")
$local("#wmd-input-#{cls_identifier}-#{id}").val(text)
Discussion.getWmdInput($content, $local, cls_identifier).val(text)
wmdEditors["#{cls_identifier}-#{id}"].refreshPreview()
getContentInfo: (id, attr) ->
......
<%namespace name="renderer" file="_thread.html"/>
<script type="text/javascript">
$('#wmd-input-reply-body').bind('focus', function(e) {
$('.new-post-form').removeClass('collapsed');
});
</script>
<section class="discussion inline-discussion" _id="${discussion_id}">
<div class="discussion-non-content">
<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="reply-body">
<div class="wmd-panel">
<div id="wmd-button-bar-reply-body-502021ba30e78e7d4d00031d">
<ul id="wmd-button-row-reply-body-502021ba30e78e7d4d00031d" class="wmd-button-row">
<li class="wmd-button" style="left: 0px; " id="wmd-bold-button-reply-body-502021ba30e78e7d4d00031d" title="Strong &lt;strong&gt; Ctrl+B"><span style="background-position: 0px 0px; "></span></li>
<li class="wmd-button" style="left: 25px; " id="wmd-italic-button-reply-body-502021ba30e78e7d4d00031d" title="Emphasis &lt;em&gt; Ctrl+I"><span style="background-position: -20px 0px; "></span></li>
<li class="wmd-spacer wmd-spacer1" id="wmd-spacer1-reply-body-502021ba30e78e7d4d00031d"></li>
<li class="wmd-button" style="left: 75px; " id="wmd-link-button-reply-body-502021ba30e78e7d4d00031d" title="Hyperlink &lt;a&gt; Ctrl+L"><span style="background-position: -40px 0px; "></span></li>
<li class="wmd-button" style="left: 100px; " id="wmd-quote-button-reply-body-502021ba30e78e7d4d00031d" title="Blockquote &lt;blockquote&gt; Ctrl+Q"><span style="background-position: -60px 0px; "></span></li>
<li class="wmd-button" style="left: 125px; " id="wmd-code-button-reply-body-502021ba30e78e7d4d00031d" title="Code Sample &lt;pre&gt;&lt;code&gt; Ctrl+K"><span style="background-position: -80px 0px; "></span></li>
<li class="wmd-button" style="left: 150px; " id="wmd-image-button-reply-body-502021ba30e78e7d4d00031d" title="Image &lt;img&gt; Ctrl+G"><span style="background-position: -100px 0px; "></span></li>
<li class="wmd-spacer wmd-spacer2" id="wmd-spacer2-reply-body-502021ba30e78e7d4d00031d"></li>
<li class="wmd-button" style="left: 200px; " id="wmd-olist-button-reply-body-502021ba30e78e7d4d00031d" title="Numbered List &lt;ol&gt; Ctrl+O"><span style="background-position: -120px 0px; "></span></li>
<li class="wmd-button" style="left: 225px; " id="wmd-ulist-button-reply-body-502021ba30e78e7d4d00031d" title="Bulleted List &lt;ul&gt; Ctrl+U"><span style="background-position: -140px 0px; "></span></li>
<li class="wmd-button" style="left: 250px; " id="wmd-heading-button-reply-body-502021ba30e78e7d4d00031d" title="Heading &lt;h1&gt;/&lt;h2&gt; Ctrl+H"><span style="background-position: -160px 0px; "></span></li>
<li class="wmd-button" style="left: 275px; " id="wmd-hr-button-reply-body-502021ba30e78e7d4d00031d" title="Horizontal Rule &lt;hr&gt; Ctrl+R"><span style="background-position: -180px 0px; "></span></li>
<li class="wmd-spacer wmd-spacer3" id="wmd-spacer3-reply-body-502021ba30e78e7d4d00031d"></li>
<li class="wmd-button" style="left: 325px; " id="wmd-undo-button-reply-body-502021ba30e78e7d4d00031d" title="Undo - Ctrl+Z"><span style="background-position: -200px -20px; "></span></li>
<li class="wmd-button" style="left: 350px; " id="wmd-redo-button-reply-body-502021ba30e78e7d4d00031d" title="Redo - Ctrl+Shift+Z"><span style="background-position: -220px -20px; "></span></li>
</ul>
</div>
<textarea class="wmd-input" id="wmd-input-reply-body" placeholder="Post a question or comment&hellip;"></textarea>
<div id="wmd-preview-reply-body-502021ba30e78e7d4d00031d" class="wmd-panel wmd-preview"></div>
</div>
</div>
<div class="new-post-body reply-body"></div>
<div class="post-options">
<input type="checkbox" class="discussion-post-anonymously" id="discussion-post-anonymously-502021ba30e78e7d4d00031d">
<label for="discussion-post-anonymously-502021ba30e78e7d4d00031d">post anonymously</label>
<input type="checkbox" class="discussion-auto-watch" id="discussion-autowatch-502021ba30e78e7d4d00031d" checked="">
<label for="discussion-auto-watch-502021ba30e78e7d4d00031d">follow this thread</label>
<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>
......
......@@ -40,9 +40,11 @@
${render_vote(content)}
<div class="discussion-right-wrapper clearfix">
<ul class="admin-actions">
<li><a href="#" class="admin-endorse">Endorse</a></li>
<li><a href="#" class="admin-edit">Edit</a></li>
<li><a href="#" class="admin-delete">Delete</a></li>
% if type == 'comment':
<li><a href="javascript:void(0)" class="admin-endorse">Endorse</a></li>
% endif
<li><a href="javascript:void(0)" class="admin-edit">Edit</a></li>
<li><a href="javascript:void(0)" class="admin-delete">Delete</a></li>
</ul>
${render_title(content, type, **kwargs)}
......
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