move reply to comment view to z3cform.
svn path=/plone.app.discussion/trunk/; revision=28349
This commit is contained in:
parent
a5c8fe33ed
commit
ddd8596dbd
@ -154,7 +154,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div tal:replace="structure view/contents" />
|
<div tal:replace="structure view/contents" />
|
||||||
|
<!--
|
||||||
<form name="reply"
|
<form name="reply"
|
||||||
action=""
|
action=""
|
||||||
method="get"
|
method="get"
|
||||||
@ -218,6 +218,7 @@
|
|||||||
<input type="hidden" name="form.submitted" value="1" />
|
<input type="hidden" name="form.submitted" value="1" />
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
-->
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -77,7 +77,6 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
|
|||||||
'__parent__',
|
'__parent__',
|
||||||
'__name__',
|
'__name__',
|
||||||
'comment_id',
|
'comment_id',
|
||||||
'in_reply_to',
|
|
||||||
'mime_type',
|
'mime_type',
|
||||||
'creator',
|
'creator',
|
||||||
'creation_date',
|
'creation_date',
|
||||||
@ -86,51 +85,106 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
|
|||||||
'author_name',
|
'author_name',
|
||||||
'author_email',)
|
'author_email',)
|
||||||
|
|
||||||
@button.buttonAndHandler(u'Post comment')
|
@button.buttonAndHandler(u'Comment')
|
||||||
def handleApply(self, action):
|
def handleApply(self, action):
|
||||||
data, errors = self.extractData()
|
data, errors = self.extractData()
|
||||||
|
|
||||||
if data.has_key('title'):
|
if data.has_key('title') and data.has_key('text'):
|
||||||
subject = data['title']
|
|
||||||
if data.has_key('text'):
|
title = data['title']
|
||||||
text = data['text']
|
text = data['text']
|
||||||
if data.has_key('author_username'):
|
|
||||||
author_username = data['author_username']
|
|
||||||
if data.has_key('author_email'):
|
|
||||||
author_email = data['author_email']
|
|
||||||
|
|
||||||
# The add-comment view is called on the conversation object
|
# The add-comment view is called on the conversation object
|
||||||
conversation = IConversation(self.__parent__)
|
conversation = IConversation(self.__parent__)
|
||||||
|
|
||||||
# Create the comment
|
# Create the comment
|
||||||
comment = CommentFactory()
|
comment = CommentFactory()
|
||||||
comment.title = subject
|
comment.title = title
|
||||||
comment.text = text
|
comment.text = text
|
||||||
|
|
||||||
portal_membership = getToolByName(self.context, 'portal_membership')
|
portal_membership = getToolByName(self.context, 'portal_membership')
|
||||||
|
|
||||||
if portal_membership.isAnonymousUser():
|
if portal_membership.isAnonymousUser():
|
||||||
comment.creator = author_username
|
comment.creator = author_username
|
||||||
comment.author_name = author_username
|
comment.author_name = author_username
|
||||||
comment.author_email = author_email
|
comment.author_email = author_email
|
||||||
comment.creation_date = comment.modification_date = datetime.now()
|
comment.creation_date = comment.modification_date = datetime.now()
|
||||||
else:
|
|
||||||
member = portal_membership.getAuthenticatedMember()
|
|
||||||
fullname = member.getProperty('fullname')
|
|
||||||
if fullname == '' or None:
|
|
||||||
comment.creator = member.id
|
|
||||||
else:
|
else:
|
||||||
comment.creator = fullname
|
member = portal_membership.getAuthenticatedMember()
|
||||||
comment.author_username = member.getUserName()
|
fullname = member.getProperty('fullname')
|
||||||
comment.author_name = member.getProperty('fullname')
|
if fullname == '' or None:
|
||||||
comment.author_email = member.getProperty('email')
|
comment.creator = member.id
|
||||||
comment.creation_date = comment.modification_date = datetime.now()
|
else:
|
||||||
|
comment.creator = fullname
|
||||||
|
comment.author_username = member.getUserName()
|
||||||
|
comment.author_name = member.getProperty('fullname')
|
||||||
|
comment.author_email = member.getProperty('email')
|
||||||
|
comment.creation_date = comment.modification_date = datetime.now()
|
||||||
|
|
||||||
# Add comment to the conversation
|
# Add comment to the conversation
|
||||||
comment_id = conversation.addComment(comment)
|
comment_id = conversation.addComment(comment)
|
||||||
|
|
||||||
|
# Redirect to comment (inside a content object page)
|
||||||
|
self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url() + '#' + str(comment_id))
|
||||||
|
|
||||||
|
@button.buttonAndHandler(u'Reply')
|
||||||
|
def handleReply(self, action):
|
||||||
|
|
||||||
|
data, errors = self.extractData()
|
||||||
|
|
||||||
|
if data.has_key('title') and data.has_key('text') and data.has_key('in_reply_to'):
|
||||||
|
|
||||||
|
title = data['title']
|
||||||
|
text = data['text']
|
||||||
|
reply_to_comment_id = data['in_reply_to']
|
||||||
|
|
||||||
|
if data.has_key('author_username'):
|
||||||
|
author_username = data['author_username']
|
||||||
|
if data.has_key('author_email'):
|
||||||
|
author_email = data['author_email']
|
||||||
|
|
||||||
|
# The add-comment view is called on the conversation object
|
||||||
|
conversation = IConversation(self.__parent__)
|
||||||
|
|
||||||
|
# Fetch the comment we want to reply to
|
||||||
|
comment_to_reply_to = conversation.get(reply_to_comment_id)
|
||||||
|
|
||||||
|
replies = IReplies(comment_to_reply_to)
|
||||||
|
|
||||||
|
# Create the comment
|
||||||
|
comment = CommentFactory()
|
||||||
|
comment.title = title
|
||||||
|
comment.text = text
|
||||||
|
|
||||||
|
portal_membership = getToolByName(self.context, 'portal_membership')
|
||||||
|
|
||||||
|
if portal_membership.isAnonymousUser():
|
||||||
|
comment.creator = author_username
|
||||||
|
comment.author_name = author_username
|
||||||
|
comment.author_email = author_email
|
||||||
|
comment.creation_date = comment.modification_date = datetime.now()
|
||||||
|
else:
|
||||||
|
member = portal_membership.getAuthenticatedMember()
|
||||||
|
fullname = member.getProperty('fullname')
|
||||||
|
if fullname == '' or None:
|
||||||
|
comment.creator = member.id
|
||||||
|
else:
|
||||||
|
comment.creator = fullname
|
||||||
|
comment.author_username = member.getUserName()
|
||||||
|
comment.author_name = member.getProperty('fullname')
|
||||||
|
comment.author_email = member.getProperty('email')
|
||||||
|
comment.creation_date = comment.modification_date = datetime.now()
|
||||||
|
|
||||||
|
# Add the reply to the comment
|
||||||
|
new_re_id = replies.addComment(comment)
|
||||||
|
|
||||||
|
#IStatusMessage(self.request).addStatusMessage(\
|
||||||
|
# _("Comment field is empty."),
|
||||||
|
# type="info")
|
||||||
|
|
||||||
|
# Redirect to comment (inside a content object page)
|
||||||
|
self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url() + '#' + str(reply_to_comment_id))
|
||||||
|
|
||||||
# Redirect to comment (inside a content object page)
|
|
||||||
self.request.response.redirect(aq_parent(aq_inner(self.context)).absolute_url() + '#' + str(comment_id))
|
|
||||||
|
|
||||||
class ViewletFormWrapper(ViewletBase, layout.FormWrapper):
|
class ViewletFormWrapper(ViewletBase, layout.FormWrapper):
|
||||||
|
|
||||||
@ -237,83 +291,3 @@ class ViewletFormWrapper(ViewletBase, layout.FormWrapper):
|
|||||||
return util.toLocalizedTime(zope_time, long_format=True)
|
return util.toLocalizedTime(zope_time, long_format=True)
|
||||||
|
|
||||||
CommentsViewlet = layout.wrap_form(CommentForm, __wrapper_class=ViewletFormWrapper)
|
CommentsViewlet = layout.wrap_form(CommentForm, __wrapper_class=ViewletFormWrapper)
|
||||||
|
|
||||||
class ReplyToComment(BrowserView):
|
|
||||||
"""Reply to a comment
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __call__(self):
|
|
||||||
|
|
||||||
context = aq_inner(self.context)
|
|
||||||
|
|
||||||
if self.request.has_key('form.button.AddComment'):
|
|
||||||
|
|
||||||
reply_to_comment_id = self.request.get('form.reply_to_comment_id')
|
|
||||||
|
|
||||||
subject = self.request.get('subject')
|
|
||||||
text = self.request.get('body_text')
|
|
||||||
author_username = self.request.get('author_username')
|
|
||||||
author_email = self.request.get('author_email')
|
|
||||||
|
|
||||||
# Check the form input
|
|
||||||
if author_username == '':
|
|
||||||
IStatusMessage(self.request).addStatusMessage(\
|
|
||||||
_("Username field is empty."),
|
|
||||||
type="info")
|
|
||||||
return self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url())
|
|
||||||
if author_email == '':
|
|
||||||
IStatusMessage(self.request).addStatusMessage(\
|
|
||||||
_("Email field is empty."),
|
|
||||||
type="info")
|
|
||||||
return self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url())
|
|
||||||
if subject == '':
|
|
||||||
IStatusMessage(self.request).addStatusMessage(\
|
|
||||||
_("Subject field is empty."),
|
|
||||||
type="info")
|
|
||||||
return self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url())
|
|
||||||
if text == '':
|
|
||||||
IStatusMessage(self.request).addStatusMessage(\
|
|
||||||
_("Comment field is empty."),
|
|
||||||
type="info")
|
|
||||||
return self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url())
|
|
||||||
|
|
||||||
# The add-comment view is called on the conversation object
|
|
||||||
conversation = context
|
|
||||||
|
|
||||||
# Fetch the comment we want to reply to
|
|
||||||
comment_to_reply_to = conversation.get(reply_to_comment_id)
|
|
||||||
|
|
||||||
replies = IReplies(comment_to_reply_to)
|
|
||||||
|
|
||||||
# Create the comment
|
|
||||||
comment = CommentFactory()
|
|
||||||
comment.title = subject
|
|
||||||
comment.text = text
|
|
||||||
|
|
||||||
portal_membership = getToolByName(context, 'portal_membership')
|
|
||||||
|
|
||||||
if portal_membership.isAnonymousUser():
|
|
||||||
comment.creator = author_username
|
|
||||||
comment.author_name = author_username
|
|
||||||
comment.author_email = author_email
|
|
||||||
comment.creation_date = comment.modification_date = datetime.now()
|
|
||||||
else:
|
|
||||||
member = portal_membership.getAuthenticatedMember()
|
|
||||||
fullname = member.getProperty('fullname')
|
|
||||||
if fullname == '' or None:
|
|
||||||
comment.creator = member.id
|
|
||||||
else:
|
|
||||||
comment.creator = fullname
|
|
||||||
comment.author_username = member.getUserName()
|
|
||||||
comment.author_name = member.getProperty('fullname')
|
|
||||||
comment.author_email = member.getProperty('email')
|
|
||||||
comment.creation_date = comment.modification_date = datetime.now()
|
|
||||||
|
|
||||||
# Add the reply to the comment
|
|
||||||
new_re_id = replies.addComment(comment)
|
|
||||||
|
|
||||||
# Redirect to comment (inside a content object page)
|
|
||||||
#self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url() + '#comment-' + str(reply_to_comment_id))
|
|
||||||
# Todo: Temporarily remove the "#comment-" to fix a bug
|
|
||||||
# in CMFPlone/skins/plone_ecmascript/form_tabbing.js
|
|
||||||
self.request.response.redirect(aq_parent(aq_inner(context)).absolute_url() + '#' + str(reply_to_comment_id))
|
|
@ -73,15 +73,6 @@
|
|||||||
permission="zope2.View"
|
permission="zope2.View"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Reply to comment view -->
|
|
||||||
<browser:view
|
|
||||||
name="reply-to-comment"
|
|
||||||
for="plone.app.discussion.interfaces.IConversation"
|
|
||||||
layer="..interfaces.IDiscussionLayer"
|
|
||||||
class=".comments.ReplyToComment"
|
|
||||||
permission="zope2.View"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- Resource directory for javascripts -->
|
<!-- Resource directory for javascripts -->
|
||||||
<browser:resourceDirectory
|
<browser:resourceDirectory
|
||||||
name="plone.app.discussion.javascripts"
|
name="plone.app.discussion.javascripts"
|
||||||
|
@ -36,21 +36,19 @@ jq(document).ready(function() {
|
|||||||
/* Fetch the reply form inside the reply div */
|
/* Fetch the reply form inside the reply div */
|
||||||
var reply_form = reply_div.find("form");
|
var reply_form = reply_div.find("form");
|
||||||
|
|
||||||
/* Add a hidden field with the id of the comment */
|
/* Remove already typed in text from the reply form. */
|
||||||
reply_form.append("<input type=\"hidden\" value=\"" + comment_id + "\" name=\"form.reply_to_comment_id\" />");
|
reply_form.find(".field").find("input").attr("value", "")
|
||||||
|
reply_form.find(".field").find("textarea").attr("value", "")
|
||||||
|
|
||||||
/* Change the form action to @@reply-to-comment */
|
/* Populate the hidden 'in_reply_to' field with the correct comment id */
|
||||||
var old_action = reply_form.attr("action");
|
reply_form.find("input[name='form.widgets.in_reply_to']").val(comment_id);
|
||||||
var new_action = old_action.replace("@@add-comment", "@@reply-to-comment");
|
|
||||||
reply_form.attr("action", new_action);
|
|
||||||
|
|
||||||
/* Add a remove-reply-to-comment Javascript function to remove the form */
|
/* Add a remove-reply-to-comment Javascript function to remove the form */
|
||||||
var cancel_reply_button = reply_div.find(".cancelreplytocomment");
|
var cancel_reply_button = reply_div.find(".cancelreplytocomment");
|
||||||
cancel_reply_button.attr("id", comment_id);
|
cancel_reply_button.attr("id", comment_id);
|
||||||
|
|
||||||
/* Remove already typed in text from the reply form. */
|
/* Hide the comment button */
|
||||||
reply_form.find(".field").find("input").attr("value", "")
|
reply_form.find("input[name='form.buttons.comment'").css("background", "red");
|
||||||
reply_form.find(".field").find("textarea").attr("value", "")
|
|
||||||
|
|
||||||
/* Show the reply layer with a slide down effect */
|
/* Show the reply layer with a slide down effect */
|
||||||
reply_div.slideDown("slow");
|
reply_div.slideDown("slow");
|
||||||
|
Loading…
Reference in New Issue
Block a user