ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/Discount/_CreateOrUpdate.TabAppliedToCategories.cshtml
@model DiscountModel
@{
    if (!String.IsNullOrEmpty(Model.Id))
    {

<div class="panel panel-default">
    <vc:admin-widget widget-zone="discount_details_applied_to_categories_top" additional-data="Model" />
    <div class="panel-body">
        <div id="categories-grid"></div>
    </div>
    <div class="panel-footer">
        <button type="submit" id="btnAddNewCategory" onclick="javascript:OpenWindow('@(Url.Action("CategoryAddPopup", "Discount", new { discountId = Model.Id, btnId = "btnRefreshCategories", formId = "discount-form" }))', 800, 800, true); return false;" class="k-button"><i class="fa fa-plus"></i>&nbsp;@T("Admin.Promotions.Discounts.AppliedToCategories.AddNew")</button>
        <input type="submit" id="btnRefreshCategories" style="display: none" />
    </div>
    <vc:admin-widget widget-zone="discount_details_applied_to_categories_bottom" additional-data="Model" />
</div>
        <script>
            $(document).ready(function () {
                $("#categories-grid").kendoGrid({
                    dataSource: {
                        transport: {
                            read: {
                                url: "@Html.Raw(Url.Action("CategoryList", "Discount", new { discountId = Model.Id }))",
                                type: "POST",
                                dataType: "json",
                                data: addAntiForgeryToken
                            },
                            destroy: {
                                url: "@Html.Raw(Url.Action("CategoryDelete", "Discount", new { discountId = Model.Id }))",
                                type: "POST",
                                dataType: "json",
                                data: addAntiForgeryToken
                            }
                        },
                        schema: {
                            data: "Data",
                            total: "Total",
                            errors: "Errors",
                            model: {
                                id: "CategoryId",
                                fields: {
                                    CategoryName: {editable: false, type: "string" },
                                    CategoryId: {editable: false, type: "string" }
                                }
                            }
                        },
                        error: function(e) {
                            display_kendoui_grid_error(e);
                            // Cancel the changes
                            this.cancelChanges();
                        },
                        serverPaging: true,
                        serverFiltering: true,
                        serverSorting: true
                    },
                    pageable: {
                        refresh: true,
                        numeric: false,
                        previousNext: false,
                        info: false
                    },
                    editable: {
                        confirmation: false,
                        mode: "inline"
                    },
                    scrollable: false,
                    columns: [{
                        field: "CategoryName",
                        title: "@T("Admin.Promotions.Discounts.AppliedToCategories.Category")",
                        template: '<a class="k-link" href="@Url.Action("Edit", "Category")/#=CategoryId#">#=kendo.htmlEncode(CategoryName)#</a>',
                    }, {
                        command: [{
                            name: "destroy",
                            text: "@T("Admin.Common.Delete")"
                        }],
                        width: 150
                    }]
                });
            });
        </script>

        <script>
            $(document).ready(function () {
                $('#btnRefreshCategories').click(function () {
                    //refresh grid
                    var grid = $("#categories-grid").data('kendoGrid');
                    grid.dataSource.read();

                    //return false to don't reload a page
                    return false;
                });
            });
        </script>

    }
    else
    {
        <div class="note note-info">
            @T("Admin.Promotions.Discounts.AppliedToCategories.SaveBeforeEdit")
        </div>
    }
}