@model Telerik.Web.Mvc.GridModel<NewsCommentModel>
@using Telerik.Web.Mvc.UI

@{
    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
}
@{
    int? filterByNewsItemId = ViewBag.FilterByNewsItemId;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-content.png")" alt="" />
        @T("Admin.ContentManagement.News.Comments")
    </div>
    <div class="options">
    </div>
</div>
<table class="adminContent">
    <tr>
        <td>
            @(Html.Telerik().Grid<NewsCommentModel>(Model.Data)
                    .Name("comments-grid")
                    .DataKeys(x => {
                        x.Add(y => y.Id).RouteKey("Id");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Id)
                            .Width(50);
                        columns.Bound(x => x.NewsItemTitle)
                            .Width(200)
                            .Template(x => Html.ActionLink(x.NewsItemTitle, "Edit", "News", new { id = x.NewsItemId }, new { }))
                            .ClientTemplate("<a href=\"" + @Url.Content("~/Admin/News/Edit/") + "<#= NewsItemId #>\"><#= NewsItemTitle #></a>");
                        columns.Bound(x => x.CustomerId)
                            .Width(50)
                            .Template(x => Html.ActionLink(T("Admin.Common.View").Text, "Edit", "Customer", new { id = x.CustomerId }, new { }))
                            .ClientTemplate("<a href=\""+ @Url.Content("~/Admin/Customer/Edit/") + "<#= CustomerId #>\">" + T("Admin.Common.View").Text + "</a>");
                        columns.Bound(x => x.CommentTitle)
                            .Width(150)
                            .Centered();
                        columns.Bound(x => x.CommentText)
                            .Width(350)
                            .Encoded(false)
                            .Centered();
                        columns.Bound(x => x.IpAddress)
                            .Width(100)
                            .Centered();
                        columns.Bound(x => x.CreatedOn)
                            .Width(150)
                            .Centered();
                        columns.Command(commands =>
                        {
                            commands.Delete();                            
                        }).Width(90);
                    })
                    .Pageable(settings => settings.Total(Model.Total).PageSize(gridPageSize).Position(GridPagerPosition.Both))
                    .DataBinding(dataBinding => {
                        var settingBuilder = dataBinding.Ajax();
                        if (filterByNewsItemId.HasValue)
                        {
                            settingBuilder = settingBuilder.Select("Comments", "News", new { filterByNewsItemId = filterByNewsItemId.Value });
                            settingBuilder = settingBuilder.Delete("CommentDelete", "News", new { filterByNewsItemId = filterByNewsItemId.Value });
                        }
                        else
                        {
                            settingBuilder = settingBuilder.Select("Comments", "News");
                            settingBuilder = settingBuilder.Delete("CommentDelete", "News");
                        }
                    })
                    .EnableCustomBinding(true))
        </td>
    </tr>
</table>
