-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
将话题回复页面中的脚本放到了 topic.js 中;将 cshtml 分为几个小的 Partial View
- Loading branch information
Jijie Chen
committed
Dec 2, 2018
1 parent
d9f96ff
commit 62ec073
Showing
5 changed files
with
162 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
@using Discussion.Core.Mvc | ||
@using Discussion.Web.Services.UserManagement.Avatar | ||
@inject Discussion.Web.Models.SiteSettings SiteSettings | ||
@inject IUserAvatarService AvatarService | ||
@model TopicViewModel | ||
|
||
@{ | ||
var user = Context.DiscussionUser(); | ||
var canCreateReply = user != null; | ||
if (canCreateReply && SiteSettings.RequireUserPhoneNumberVerified && !user.PhoneNumberId.HasValue) | ||
{ | ||
canCreateReply = false; | ||
} | ||
} | ||
|
||
|
||
|
||
<div class="row"> | ||
<div class="panel no-padding panel-topic-create-reply col-xs-12 col-sm-12 col-md-12 col-lg-12"> | ||
<div class="panel-heading"> | ||
添加回复 | ||
</div> | ||
|
||
<div class="panel-body"> | ||
@if (canCreateReply) | ||
{ | ||
<ul class="nav nav-tabs" role="tablist"> | ||
<li role="presentation" class="active"><a id="tab-editor" href="#editor" aria-controls="home" role="tab" data-toggle="tab">编辑</a></li> | ||
<li role="presentation"><a id="tab-preview" href="#preview" aria-controls="profile" role="tab" data-toggle="tab">预览</a></li> | ||
</ul> | ||
<div class="tab-content"> | ||
<div role="tabpanel" class="tab-pane active" id="editor"> | ||
<textarea id="content-editor" placeholder="回复话题(支持 Markdown 语法)"></textarea> | ||
</div> | ||
<div role="tabpanel" class="tab-pane" id="preview"></div> | ||
</div> | ||
<button id="submit-create" class="btn btn-default submit-create-btn">回复</button> | ||
} | ||
else | ||
{ | ||
<p>多谢登录。</p> | ||
<p>为账号验证了实名手机号之后,才可以添加回复。@Html.ActionLink("现在验证", "VerifyPhoneNumber", "User") </p> | ||
} | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@using Discussion.Web.Services.UserManagement.Avatar | ||
@inject IUserAvatarService AvatarService | ||
@model TopicViewModel | ||
|
||
<div class="row"> | ||
<div class="panel no-padding panel-topic-replies col-xs-12 col-sm-12 col-md-12 col-lg-12"> | ||
<div class="panel-heading"> | ||
共有 @Model.Topic.ReplyCount 条回复 | ||
</div> | ||
|
||
<div class="panel-body"> | ||
@foreach (var reply in Model.Replies) | ||
{ | ||
<div class="reply-item"> | ||
<dl class="reply-author"> | ||
<dd><img src="@AvatarService.GetUserAvatarUrl(reply.Author)" class="avatar"/></dd> | ||
<dd class="username">@reply.Author.DisplayName</dd> | ||
</dl> | ||
<div class="reply-content"> | ||
<div class="reply-content-body">@Html.RenderMarkdown(reply.Content, maxHeadingLevel: 3)</div> | ||
<div class="reply-content-related"> | ||
回复于 <span class="replied-at" data-replied-at="@Html.Timestamp(reply.CreatedAtUtc)"></span> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
|
||
export function submitNewReply(editorSelector, postUrl) { | ||
return function() { | ||
var editor = $(editorSelector); | ||
var replyContent = editor.val(); | ||
if (!$.trim(replyContent)) { | ||
editor.focus(); | ||
return false; | ||
} | ||
|
||
$.ajax({ | ||
url: postUrl, | ||
method: 'POST', | ||
data: { | ||
content: replyContent, | ||
__RequestVerificationToken: window.__RequestVerificationToken | ||
}, | ||
dataType: 'json', | ||
success: function() { | ||
location.reload(); | ||
}, | ||
error: function(xhr) { | ||
var errors = JSON.parse(xhr.responseText); | ||
console.log(errors); | ||
} | ||
}); | ||
}; | ||
} | ||
|
||
|
||
export function setupReplyPreview(selectors, previewApiUrl){ | ||
|
||
$(selectors.tabPreview).on('shown.bs.tab', | ||
function(e) { | ||
var editor = $(selectors.contentEditor); | ||
var replyContent = editor.val(); | ||
if (!$.trim(replyContent)) { | ||
editor.focus(); | ||
e.preventDefault(); | ||
return false; | ||
} | ||
|
||
$(selectors.contentPreview).html('正在加载预览...'); | ||
$.ajax({ | ||
url: previewApiUrl, | ||
method: 'POST', | ||
data: { | ||
markdown: replyContent, | ||
__RequestVerificationToken: window.__RequestVerificationToken }, | ||
success: function(res) { | ||
if (res.hasSucceeded) { | ||
$(selectors.contentPreview).html(res.result.html); | ||
} else { | ||
$(selectors.contentPreview).html('<span style="color:red">' + res.errorMessage + '</span>'); | ||
} | ||
}, | ||
error: function() { | ||
$(selectors.contentPreview).html('<span style="color:red">暂时无法预览</span>'); | ||
} | ||
}); | ||
}); | ||
|
||
$(selectors.tabEditor).on('shown.bs.tab', | ||
function() { | ||
$(selectors.contentEditor).focus(); | ||
$(selectors.contentPreview).empty(); | ||
}); | ||
} |