ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/ReturnRequest/List.cshtml
@model ReturnReqestListModel
@inject AdminAreaSettings adminAreaSettings
@{
    //page title
    ViewBag.Title = T("Admin.ReturnRequests").Text;
}
<form asp-area="@Constants.AreaAdmin" asp-controller="ReturnRequest" asp-action="List" method="post">
    
    <div class="row">
        <div class="col-md-12">
            <div class="x_panel light form-fit">
                <div class="x_title">
                    <div class="caption level-caption">
                        <i class="fa fa-truck"></i>
                        @T("Admin.ReturnRequests")
                    </div>
                    <vc:admin-widget widget-zone="return_request_list_buttons" additional-data="null" />
                </div>
                <div class="x_content form">
                    <div class="form-horizontal">
                        <div class="form-body">
                            <div class="form-group">
                                <admin-label asp-for="SearchCustomerEmail" />
                                <div class="col-md-4 col-sm-6">
                                    <admin-input asp-for="SearchCustomerEmail" />
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="StartDate" />
                                <div class="col-md-4 col-sm-6">
                                    <admin-input asp-for="StartDate" />
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="EndDate" />
                                <div class="col-md-4 col-sm-6">
                                    <admin-input asp-for="EndDate" />
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="SearchReturnRequestStatusId" />
                                <div class="col-md-4 col-sm-6">
                                    <admin-select asp-for="SearchReturnRequestStatusId" asp-items="Model.ReturnRequestStatus" />
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="GoDirectlyToId" class="control-label col-md-3 col-sm-3" />
                                <div class="col-8 col-md-4 col-sm-4">
                                    <div class="input-group" style="text-align:left">
                                        <admin-input asp-for="GoDirectlyToId" />
                                        <span class="input-group-append">
                                            <input type="submit" id="go-to-returnrequest" name="go-to-returnrequest" class="btn default" value="@T("Admin.Common.Go")" />
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-actions">
                            <div class="row">
                                <div class="offset-md-3 offset-sm-3 col-md-9 col-sm-9">
                                    <button class="btn btn-success filter-submit" id="search-returnreqest">
                                        <i class="fa fa-search"></i> @T("Admin.Common.Search")
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="x_content form">
                    <div class="form-horizontal">
                        <div class="form-body">
                            <div class="x_content">
                                <div id="returnrequests-grid"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
    <script>
    $(document).ready(function() {
        $("#returnrequests-grid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("List", "ReturnRequest"))",
                        type: "POST",
                        dataType: "json",
                        data: additionalData
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors"
                },
                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: "ReturnNumber",
                    title: "@T("Admin.ReturnRequests.Fields.ID")",
                    width: 50,
                    template: '<a class="k-link" href="Edit/#=Id#">#=ReturnNumber#</a>'
                }, {
                    field: "Quantity",
                    title: "@T("Admin.ReturnRequests.Fields.Quantity")",
                    width: 80,
                    template: '<a class="k-link" href="Edit/#=Id#">#=Quantity#</a>'
                }, {
                    field: "Total",
                    title: "@T("Admin.ReturnRequests.Fields.Total")",
                    width: 100,
                    template: '<a class="k-link" href="Edit/#=Id#">#=Total#</a>'
                } , {
                    field: "CustomerId",
                    title: "@T("Admin.ReturnRequests.Fields.Customer")",
                    width: 200,
                    template: '<a class="k-link" href="@Url.Action("Edit", "Customer")/#=CustomerId#">#:kendo.htmlEncode(CustomerInfo)#</a>'
                }, {
                    field: "OrderId",
                    title: "@T("Admin.ReturnRequests.Fields.Order")",
                    width: 80,
                    template: '<a class="k-link" href="@Url.Action("Edit", "Order")/#=OrderId#">#:OrderNumber#</a>'
                }, {
                    field: "ReturnRequestStatusStr",
                    title: "@T("Admin.ReturnRequests.Fields.Status")",
                    width: 130,
                    template: '<a class="k-link" href="Edit/#=Id#">#=ReturnRequestStatusStr#</a>'
                }, {
                    field: "CreatedOn",
                    title: "@T("Admin.ReturnRequests.Fields.CreatedOn")",
                    width: 100,
                    type: "date",
                    format: "{0:G}"
                }
            ]
        });
    });
    </script>

    <script>
    function additionalData() {
        var data = {
            SearchReturnRequestStatusId: $('#@Html.FieldIdFor(model => model.SearchReturnRequestStatusId)').val(),
            SearchCustomerEmail: $('#@Html.FieldIdFor(model => model.SearchCustomerEmail)').val(),
            StartDate: $('#@Html.FieldIdFor(model => model.StartDate)').val(),
            EndDate: $('#@Html.FieldIdFor(model => model.EndDate)').val()
        };
        addAntiForgeryToken(data);
        return data;
    }
    $(document).ready(function () {
        $('#search-returnreqest').click(function () {
            //search
            var grid = $('#returnrequests-grid').data('kendoGrid');
            grid.dataSource.page(1); //new search. Set page size to 1
            //grid.dataSource.read(); we already loaded the grid above using "page" function
            return false;
        });

        $("#@Html.FieldIdFor(model => model.SearchCustomerEmail)").keydown(function (event) {
            if (event.keyCode == 13) {
                $("#search-returnreqest").click();
                return false;
            }
        });
        $("#@Html.FieldIdFor(model => model.GoDirectlyToId)").keydown(function (event) {
            if (event.keyCode == 13) {
                $("#go-to-returnrequest").click();
                return false;
            }
        });
    });
    </script>
