Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

Topic.cshtml

@using Nop.Core
@using Nop.Core.Domain.Forums
@using Nop.Core.Domain.Seo
@using Nop.Services.Localization

@model ForumTopicPageModel

@inject ILocalizationService localizationService
@inject IWebHelper webHelper
@inject SeoSettings seoSettings

@{
    Layout = "_ColumnsOne";

    //title
    NopHtml.AddTitleParts(Model.MetaTitle);

    //meta
    NopHtml.AddMetaDescriptionParts(Model.MetaDescription);

    //page class
    NopHtml.AppendPageCssClassParts("html-forum-topic-page");

    if (seoSettings.CanonicalUrlsEnabled)
    {
        var topicUrl = string.Empty;
        if (Model.PostsPageIndex > 0)
        {
            topicUrl = Url.RouteUrl(NopRouteNames.Standard.TOPIC_SLUG_PAGED, 
                new { id = Model.Id, slug = Model.SeName, pageNumber = Model.PostsPageIndex + 1 }, webHelper.GetCurrentRequestProtocol()).ToLowerInvariant();
        }
        else
        {
            topicUrl = Url.RouteUrl(NopRouteNames.Standard.TOPIC_SLUG, 
                new { id = Model.Id, slug = Model.SeName }, webHelper.GetCurrentRequestProtocol()).ToLowerInvariant();
        }

        NopHtml.AddCanonicalUrlParts(topicUrl, seoSettings.QueryStringInCanonicalUrlsEnabled);
    }

    NopHtml.AddJsonLdParts(Model.JsonLd);
}
<div class="page forum-topic-page">
    @await Component.InvokeAsync(typeof(ForumBreadcrumbViewComponent), new { forumTopicId = Model.Id })
    @await Html.PartialAsync("_ForumHeader")
    @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.BoardsTopicAfterHeader, additionalData = Model })
    <div class="topic-name">
        <h1>@Model.Subject</h1>
    </div>
    <div class="topic-actions upper">
        <div class="actions">
            @if (Model.IsCustomerAllowedToEditTopic)
            {
                @Html.RouteLink(T("Forum.EditTopic").Text, NopRouteNames.Standard.TOPIC_EDIT, new { id = Model.Id }, new { @class = "edit-topic-button" })
            }
            @if (Model.IsCustomerAllowedToDeleteTopic)
            {
                <a href="#" class="delete-topic-button" onclick="return deletetopic(@(Model.Id))">@T("Forum.DeleteTopic").Text</a>
                <script asp-location="Footer">
                    function deletetopic(topicId) {
                        if (confirm('@T("Common.AreYouSure")')) {
                            var postData = {
                                id: topicId
                            };
                            addAntiForgeryToken(postData);
                            $.ajax({
                                cache: false,
                                type: "POST",
                                url: "@Url.RouteUrl(NopRouteNames.Standard.TOPIC_DELETE)",
                                data: postData,
                                dataType: "json",
                                success: function (data, textStatus, jqXHR) {
                                    location.href = data.redirect;
                                },
                                error: function (jqXHR, textStatus, errorThrown) {
                                    alert('Failed to delete');
                                }
                            });
                        }
                        return false;
                    }
                </script>
            }
            @if (Model.IsCustomerAllowedToMoveTopic)
            {
                @Html.RouteLink(T("Forum.MoveTopic").Text, NopRouteNames.Standard.TOPIC_MOVE, new { id = Model.Id }, new { @class = "move-topic-button" })
            }
            @Html.RouteLink(T("Forum.Reply").Text, NopRouteNames.Standard.POST_CREATE, new { id = Model.Id }, new { @class = "reply-topic-button" })
            @if (Model.IsCustomerAllowedToSubscribe)
            {
                <a class="watch-topic-button" href="#" id="watch-topic-top">@Model.WatchTopicText</a>
                <script asp-location="Footer">
                    $(function() {
                        $('#watch-topic-top').on('click', function () {
                            var postData = {};
                            addAntiForgeryToken(postData);
                            $.ajax({
                                cache: false,
                                type: "POST",
                                data: postData,
                                url: "@Url.RouteUrl(NopRouteNames.Ajax.TOPIC_WATCH, new { id = Model.Id })",
                                dataType: "json",
                                success: function (data, textStatus, jqXHR) {
                                    $('#watch-topic-top').text(data.Text);
                                    $('#watch-topic-bottom').text(data.Text);
                                },
                                error: function (jqXHR, textStatus, errorThrown) {
                                    alert('Failed to watch');
                                }
                            });
                        });
                    });
                </script>
            }
        </div>
        @{
            var pager = await Html.PagerAsync(new PagerModel(localizationService)
            {
                PageSize = Model.PostsPageSize,
                TotalRecords = Model.PostsTotalRecords,
                PageIndex = Model.PostsPageIndex,
                ShowTotalSummary = false,
                RouteActionName = NopRouteNames.Standard.TOPIC_SLUG_PAGED,
                UseRouteLinks = true,
                RouteValues = new SlugRouteValues { Id = Model.Id, Slug = Model.SeName }
            });
        }
        @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.BoardsTopicTop, additionalData = Model })
        @if (!string.IsNullOrEmpty(await pager.RenderHtmlContentAsync()))
        {
            <div class="pager upper">
                @pager
            </div>
        }
    </div>

    <div class="topic-posts">
        @if (Model.ForumEditor == EditorType.MarkdownEditor)
        {
            <script asp-location="Footer" src="~/lib_npm/marked/marked.umd.js"></script>
            <script asp-location="Footer">
                document.addEventListener('DOMContentLoaded', function() {
                    @foreach (var post in @Model.ForumPostModels)
                    {
                        <Text>
                            document.querySelector('[data-post-content="@post.Id"]').innerHTML = marked.parse(@Html.Raw(Json.Serialize(post.FormattedText)), { gfm: true, breaks: true });
                        </Text>
                    }                    
                });
            </script>            
        }
        @foreach (var post in @Model.ForumPostModels)
        {
            await Html.RenderPartialAsync("_ForumPost", post);
        }
    </div>

    <div class="topic-actions lower">
        <div class="actions">
            @Html.RouteLink(T("Forum.Reply").Text, NopRouteNames.Standard.POST_CREATE, new { id = Model.Id }, new { @class = "reply-topic-button" })
            @if (Model.IsCustomerAllowedToSubscribe)
            {
                <a class="watch-topic-button" href="#" id="watch-topic-bottom">@Model.WatchTopicText</a>
                <script asp-location="Footer">
                    $(function() {
                        $('#watch-topic-bottom').on('click', function() {
                            var postData = {};
                            addAntiForgeryToken(postData);

                            $.ajax({
                                cache: false,
                                type: "POST",
                                url: "@Url.RouteUrl(NopRouteNames.Ajax.TOPIC_WATCH, new { Model.Id })",
                                data: postData,
                                dataType: "json",
                                success: function (data, textStatus, jqXHR) {
                                    $('#watch-topic-top').text(data.Text);
                                    $('#watch-topic-bottom').text(data.Text);
                                },
                                error: function (jqXHR, textStatus, errorThrown) {
                                    alert('Failed to watch');
                                }
                            });
                        });
                    });
                </script>
            }
        </div>
        @if (!string.IsNullOrEmpty(await pager.RenderHtmlContentAsync()))
        {
            <div class="pager lower">
                @pager
            </div>
        }
    </div>
    @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.BoardsTopicBottom, additionalData = Model })
</div>
<script asp-location="Footer">
    function deletepost(postId) {
        if (confirm('@T("Common.AreYouSure")')) {
            var postData = {
                id: postId
            };
            addAntiForgeryToken(postData);
            $.ajax({
                cache: false,
                type: "POST",
                url: "@Url.RouteUrl(NopRouteNames.Standard.POST_DELETE)",
                data: postData,
                dataType: "json",
                success: function (data, textStatus, jqXHR) {
                    location.href = data.redirect;
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert('Failed to delete');
                }
            });
        }
        return false;
    }
</script>