mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Recovering form location when replying with invalid value
--HG-- branch : 1.x
This commit is contained in:
@@ -55,7 +55,7 @@ namespace Orchard.Comments.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// is it a response to another comment ?
|
// is it a response to another comment ?
|
||||||
if(commentPart.RepliedOn.HasValue && (commentsPart == null || !commentsPart.ThreadedComments)) {
|
if(commentPart.RepliedOn.HasValue && commentsPart != null && commentsPart.ThreadedComments) {
|
||||||
var replied = Services.ContentManager.Get(commentPart.RepliedOn.Value);
|
var replied = Services.ContentManager.Get(commentPart.RepliedOn.Value);
|
||||||
if(replied != null) {
|
if(replied != null) {
|
||||||
var repliedPart = replied.As<CommentPart>();
|
var repliedPart = replied.As<CommentPart>();
|
||||||
@@ -116,6 +116,10 @@ namespace Orchard.Comments.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TempData["Comments.InvalidCommentEditorShape"] = editorShape;
|
TempData["Comments.InvalidCommentEditorShape"] = editorShape;
|
||||||
|
var commentPart = comment.As<CommentPart>();
|
||||||
|
if(commentPart.RepliedOn.HasValue) {
|
||||||
|
TempData["Comments.RepliedOn"] = commentPart.RepliedOn.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.RedirectLocal(returnUrl, "~/");
|
return this.RedirectLocal(returnUrl, "~/");
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
@foreach (var comment in Model.CommentShapes) {
|
@foreach (var comment in Model.CommentShapes) {
|
||||||
<li>
|
<li>
|
||||||
@{
|
@{
|
||||||
comment.Id = "comment-" + comment.ContentPart.Id;
|
comment.Id = "comment-" + comment.ContentItem.Id;
|
||||||
var tag = Tag(comment, "article"); // using Tag so the comment can be altered by custom modules
|
var tag = Tag(comment, "article"); // using Tag so the comment can be altered by custom modules
|
||||||
tag.AddCssClass("comment");
|
tag.AddCssClass("comment");
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ else if (WorkContext.CurrentUser == null && !AuthorizedFor(Permissions.AddCommen
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@Html.ValidationSummary()
|
@Html.ValidationSummary()
|
||||||
|
<span id="comment-form-beacon" />
|
||||||
using (Html.BeginFormAntiForgeryPost(Url.Action("Create", "Comment", new { Area = "Orchard.Comments", ReturnUrl = Context.Request.ToUrlString() }), FormMethod.Post, new { @class = "comment-form" })) {
|
using (Html.BeginFormAntiForgeryPost(Url.Action("Create", "Comment", new { Area = "Orchard.Comments", ReturnUrl = Context.Request.ToUrlString() }), FormMethod.Post, new { @class = "comment-form" })) {
|
||||||
if (TempData.ContainsKey("Comments.InvalidCommentEditorShape")) {
|
if (TempData.ContainsKey("Comments.InvalidCommentEditorShape")) {
|
||||||
@Display(TempData["Comments.InvalidCommentEditorShape"]);
|
@Display(TempData["Comments.InvalidCommentEditorShape"]);
|
||||||
|
@@ -1,29 +1,59 @@
|
|||||||
@if (Model.CommentCount > 0) {
|
@using Orchard.Comments.Models
|
||||||
|
@{
|
||||||
|
CommentsPart commentsPart = Model.ContentPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (Model.CommentCount > 0) {
|
||||||
<div id="comments">
|
<div id="comments">
|
||||||
<h2 class="comment-count">@T.Plural("1 Comment", "{0} Comments", (int)Model.CommentCount)</h2>
|
<h2 class="comment-count">@T.Plural("1 Comment", "{0} Comments", (int)Model.CommentCount)</h2>
|
||||||
@Display.ListOfComments(CommentShapes: Model.CommentShapes)
|
@Display.ListOfComments(CommentShapes: Model.CommentShapes)
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
@using(Script.Foot()) {
|
@* render reply button if threaded comments enabled *@
|
||||||
|
@if(commentsPart.ThreadedComments) {
|
||||||
Script.Require("jQuery");
|
Script.Require("jQuery");
|
||||||
|
using (Script.Foot()) {
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
//<![CDATA[
|
//<![CDATA[
|
||||||
$(function () {
|
$(function() {
|
||||||
$('.comment-reply-button').click(function () {
|
$('.comment-reply-button').click(function() {
|
||||||
var self = $(this);
|
var self = $(this);
|
||||||
var id = self.data("id");
|
|
||||||
var reply = $('#Comments_RepliedOn');
|
|
||||||
reply.val(id);
|
|
||||||
|
|
||||||
// inject the form in the replied zone
|
var reply = $('#Comments_RepliedOn');
|
||||||
$('.comment-form').appendTo(self.parents('article').first());
|
var currentReply = reply.val();
|
||||||
|
|
||||||
// don't execute the link action
|
@* should we restore the form at its original location ? *@
|
||||||
|
if (currentReply && currentReply.length > 0) {
|
||||||
|
reply.val('');
|
||||||
|
$('#comment-form-beacon').after($('.comment-form'));
|
||||||
|
} else {
|
||||||
|
@* assign repliedOn id *@
|
||||||
|
var id = self.data('id');
|
||||||
|
reply.val(id);
|
||||||
|
|
||||||
|
@* inject the form in the replied zone *@
|
||||||
|
$('.comment-form').appendTo(self.parents('article').first());
|
||||||
|
}
|
||||||
|
|
||||||
|
@* don't execute the link action *@
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@if (TempData.ContainsKey("Comments.RepliedOn")) {
|
||||||
|
// invalid form while replying
|
||||||
|
|
||||||
|
<text>
|
||||||
|
var reply = $('#Comments_RepliedOn');
|
||||||
|
reply.val(@TempData["Comments.RepliedOn"]);
|
||||||
|
$('.comment-form').appendTo($('#comment-@TempData["Comments.RepliedOn"]'));
|
||||||
|
</text>
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
//]]>
|
//]]>
|
||||||
</script>
|
</script>
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user