ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/Customer/_CreateOrUpdate.TabProductPrice.cshtml
@model CustomerModel
@inject AdminAreaSettings adminAreaSettings
@{
    <strong>@T("Admin.Customers.Customers.ProductPrice")</strong>
    <div class="panel panel-default">
        <vc:admin-widget widget-zone="customer_details_product_price_top" additional-data="Model" />
        <div class="panel-body">
            <div id="productprice-grid"></div>
        </div>
        <div class="panel-footer">
            <button type="submit" id="btnAddNewProduct" onclick="javascript:OpenWindow('@(Url.Action("ProductAddPopup", "Customer", new { customerId = Model.Id, btnId = "btnRefreshProducts", formId = "customer-form" }))', 800, 800, true); return false;" class="k-button"><i class="fa fa-plus"></i>&nbsp;@T("Admin.Customers.Customers.ProductPrice.AddNew")</button>
            <input type="submit" id="btnRefreshProducts" style="display: none" />
        </div>
        <vc:admin-widget widget-zone="customer_details_product_price_bottom" additional-data="Model" />
    </div>
    <script>
        $(document).ready(function () {
            $("#productprice-grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            url: "@Html.Raw(Url.Action("ProductsPrice", "Customer", new { customerId = Model.Id }))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        },
                        update: {
                            url:"@Html.Raw(Url.Action("UpdateProductPrice", "Customer"))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        },
                        destroy: {
                            url: "@Html.Raw(Url.Action("DeleteProductPrice", "Customer"))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        }
                    },
                    schema: {
                        data: "Data",
                        total: "Total",
                        errors: "Errors",
                        model: {
                            id: "Id",
                            fields: {
                                ProductName: {editable: false, type: "string" },
                                Price: {editable: true, type: "number", format:"{0:c2}" },
                            }
                        }
                    },
                    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",
                    title: "@T("Admin.Customers.Customers.ProductPrice.ProductName")",
                    width: 300,
                    template: '<a href="@Url.Action("Edit", "Product")/#=ProductId#" target="_blank">#=kendo.htmlEncode(ProductName)#</a>'
                }, {
                    field: "Price",
                    title: "@T("Admin.Customers.Customers.ProductPrice.Price")",
                    width: 100,
                    type: "number",

                }, {
                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")"
                    }],
                width: 200
                }]
            });
        });
    </script>
    <script>
            $(document).ready(function () {
                $('#btnRefreshProducts').click(function () {
                    //refresh grid
                    var grid = $("#productprice-grid").data('kendoGrid');
                    grid.dataSource.read();

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

}