ildar-shaymukhametov_grandnode-refactorings/Plugins/Grand.Plugin.Shipping.ByWeight/Views/Configure.cshtml
@model ShippingByWeightListModel
@inject AdminAreaSettings adminAreaSettings
@using Grand.Plugin.Shipping.ByWeight.Models;
@using Grand.Domain.Common;
@{
    Layout = "_ConfigurePlugin";
}
<form asp-controller="ShippingByWeight" asp-action="Configure" method="post" id="shipping-byweight-form">
    
    <div class="note note-info">
        <strong>@T("Plugins.Shipping.ByWeight.Formula"):</strong>
        @T("Plugins.Shipping.ByWeight.Formula.Value")
    </div>

    @{
        var addNewUrl = Url.Action("AddPopup", "ShippingByWeight", new { btnId = "btnRefresh", formId = "shipping-byweight-form" });
    }

    <div class="panel panel-default">
        <div class="panel-body">
            <div id="shipping-byweight-grid"></div>
        </div>
        <div class="panel-footer">
            <input type="submit" id="btnAddNewOption" value="@T("Plugins.Shipping.ByWeight.AddRecord")" onclick="javascript:OpenWindow('@(addNewUrl)', 800, 550, true); return false;" class="btn default" />
            <input type="submit" id="btnRefresh" style="display: none" />
        </div>
    </div>
    <script>
        $(document).ready(function () {
            $("#shipping-byweight-grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            url: "@Html.Raw(Url.Action("RatesList", "ShippingByWeight"))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        },
                        destroy: {
                            url: "@Html.Raw(Url.Action("RateDelete", "ShippingByWeight"))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        }
                    },
                    schema: {
                        data: "Data",
                        total: "Total",
                        errors: "Errors",
                        model: {
                            id: "Id"
                        }
                    },
                    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: "StoreName",
                    title: "@T("Plugins.Shipping.ByWeight.Fields.Store")",
                    width: 300
                }, {
                    field: "WarehouseName",
                    title: "@T("Plugins.Shipping.ByWeight.Fields.Warehouse")",
                    width: 300
                }, {
                    field: "CountryName",
                    title: "@T("Plugins.Shipping.ByWeight.Fields.Country")",
                    width: 200
                }, {
                    field: "StateProvinceName",
                    title: "@T("Plugins.Shipping.ByWeight.Fields.StateProvince")",
                    width: 200
                }, {
                    field: "Zip",
                    title: "@T("Plugins.Shipping.ByWeight.Fields.Zip")",
                    width: 200
                }, {
                    field: "ShippingMethodName",
                    title: "@T("Plugins.Shipping.ByWeight.Fields.ShippingMethod")",
                    width: 200
                }, {
                    field: "DataHtml",
                    title: "@T("Plugins.Shipping.ByWeight.Fields.DataHtml")",
                    width: 200,
                    encoded: false
                }, {
                    field: "Id",
                    title: "@T("Admin.Common.Edit")",
                    width: 100,
                    template: "<input type='submit' value='@T("Admin.Common.Edit")' onclick=\"javascript:OpenWindow('@Url.Action("EditPopup","ShippingByWeight")?id=#=Id#&btnId=btnRefresh&formId=shipping-byweight-form', 800, 400, true); return false;\" class='k-button k-button-icontext' />"
                },  {
                    command: { name: "destroy", text: "@T("Admin.Common.Delete")" },
                    title: "@T("Admin.Common.Delete")",
                    width: 100
                }]
            });
        });
    </script>

    <script>
        $(document).ready(function () {
            $('#btnRefresh').click(function () {
                //refresh grid
                var grid = $("#shipping-byweight-grid").data('kendoGrid');
                //grid.dataSource.page(1); //new search. Set page size to 1
                grid.dataSource.read();

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

    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="form-body">
                    <div class="form-group">
                        <admin-label asp-for="LimitMethodsToCreated" />
                        <div class="col-md-9 col-sm-9">
                            <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                                <admin-input asp-for="LimitMethodsToCreated" />
                                 <div class="control__indicator"></div>
                            </label>
                            <span asp-validation-for="LimitMethodsToCreated"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <input type="button" id="savegeneralsettings" class="btn default" value="@T("Admin.Common.Save")" />
                        <script>
                    $(function () {
                        $('#savegeneralsettings').click(function () {

                            var postData = $(this.form).serialize();
                            addAntiForgeryToken(postData);

                            $.ajax({
                                cache: false,
                                type: 'POST',
                                url: '@Url.Action("SaveGeneralSettings", "ShippingByWeight")',
                                data: postData,
                                dataType: 'json',
                                success: function (data) {
                                    alert('Saved');
                                },
                                error: function (xhr, ajaxOptions, thrownError) {
                                    alert('Failed to add record.');
                                }
                            });
                            return false;
                        });
                    });
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
