ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/Manufacturer/_CreateOrUpdate.TabProducts.cshtml
@model ManufacturerModel
@inject AdminAreaSettings adminAreaSettings
@if (!String.IsNullOrEmpty(Model.Id))
{
<div class="panel panel-default">
    <vc:admin-widget widget-zone="manufacturer_details_products_top" additional-data="Model" />
    <div class="panel-body">
        <div id="products-grid"></div>
    </div>
    <div class="panel-footer">
        <button type="submit" id="btnAddNewProduct" onclick="javascript:OpenWindow('@(Url.Action("ProductAddPopup", "Manufacturer", new { manufacturerId = Model.Id, btnId = "btnRefreshProducts", formId = "manufacturer-form" }))', 800, 800, true); return false;" class="k-button"><i class="fa fa-plus"></i>&nbsp;@T("Admin.Catalog.Manufacturers.Products.AddNew")</button>
        <input type="submit" id="btnRefreshProducts" style="display: none" />
    </div>
    <vc:admin-widget widget-zone="manufacturer_details_products_bottom" additional-data="Model" />
</div>
    <script>
        $(document).ready(function () {
            $("#products-grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            url: "@Html.Raw(Url.Action("ProductList", "Manufacturer", new { manufacturerId = Model.Id }))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        },
                        update: {
                            url:"@Html.Raw(Url.Action("ProductUpdate", "Manufacturer"))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        },
                        destroy: {
                            url: "@Html.Raw(Url.Action("ProductDelete", "Manufacturer"))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        }
                    },
                    schema: {
                        data: "Data",
                        total: "Total",
                        errors: "Errors",
                        model: {
                            id: "Id",
                            fields: {
                                ProductName: {editable: false, type: "string" },
                                IsFeaturedProduct: {editable: true, type: "boolean" },
                                DisplayOrder: {editable: true, type: "number" },
                                ProductId: {editable: false, type: "string" }
                            }
                        }
                    },
                    requestEnd: function(e) {
                        if(e.type=="update") {
                            this.read();
                        }
                    },
                    error: function(e) {
                        display_kendoui_grid_error(e);
                        // Cancel the changes
                        this.cancelChanges();
                    },
                    pageSize: @(adminAreaSettings.DefaultGridPageSize),
                    serverPaging: true,
                    serverFiltering: true,
                    serverSorting: true
                },
                pageable: {
                    refresh: true,
                    pageSizes: [@(adminAreaSettings.GridPageSizes)]
                },
                editable: {
                    confirmation: false,
                    mode: "inline"
                },
                scrollable: false,
                columns: [{
                    field: "ProductName",
                    editable: false,
                    type: "string",
                    title: "@T("Admin.Catalog.Manufacturers.Products.Fields.Product")",
                    template: '<a href="@Url.Action("Edit", "Product")/#=ProductId#">#=kendo.htmlEncode(ProductName)#</a>'
                }, {
                    field: "IsFeaturedProduct",
                    title: "@T("Admin.Catalog.Manufacturers.Products.Fields.IsFeaturedProduct")",
                    width: 100,
                    minScreenWidth: 750,
                    headerAttributes: { style: "text-align:center" },
                    attributes: { style: "text-align:center" },
                    template: '# if(IsFeaturedProduct) {# <i class="fa fa-check" aria-hidden="true" style="color:green"></i> #} else {# <i class="fa fa-times" aria-hidden="true" style="color:red"></i> #} #'
                }, {
                    field: "DisplayOrder",
                    title: "@T("Admin.Catalog.Manufacturers.Products.Fields.DisplayOrder")",
                    minScreenWidth: 750,
                    headerAttributes: { style: "text-align:center" },
                    attributes: { style: "text-align:center" },
                    format: "{0:0}",
                    width: 120
                }, {
                    command: [{
                        name: "edit",
                        text: {
                            edit: "@T("Admin.Common.Edit")",
                            update: "@T("Admin.Common.Update")",
                            cancel: "@T("Admin.Common.Cancel")"
                        }
                    }, {
                        name: "destroy",
                        text: "@T("Admin.Common.Delete")"
                    }],
                }]
            });
        });
    </script>
    <script>
        $(document).ready(function () {
            $('#btnRefreshProducts').click(function () {
                //refresh grid
                var grid = $("#products-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.Catalog.Manufacturers.Products.SaveBeforeEdit")
    </div>
}
