ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/ContactForm/List.cshtml
@model ContactFormListModel
@inject AdminAreaSettings adminAreaSettings
@{
    //page title
    ViewBag.Title = T("Admin.System.ContactForm").Text;
}
<form asp-controller="ContactForm" asp-action="List">
    
    <div class="row">
        <div class="col-md-12">
            <div class="x_panel light form-fit">
                <div class="x_title">
                    <div class="caption">
                        <i class="fa fa-envelope-o"></i>
                        @T("Admin.System.ContactForm")
                    </div>
                    <div class="actions btn-group btn-group-devided">
                        <input type="submit" name="delete-all" class="btn red" value="@T("Admin.System.ContactForm.DeleteAll")" onclick="return confirm('@T("Admin.Common.AreYouSure")'); " />
                        <vc:admin-widget widget-zone="contact_form_list_buttons" additional-data="null" />
                    </div>
                </div>
                <div class="x_content form">
                    <div class="form-horizontal">
                        <div class="form-body">
                            <div class="form-group">
                                <admin-label asp-for="SearchStartDate" />
                                <div class="col-md-4 col-sm-6">
                                    <admin-input asp-for="SearchStartDate" />
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="SearchEndDate" />
                                <div class="col-md-4 col-sm-6">
                                    <admin-input asp-for="SearchEndDate" />
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="SearchEmail" />
                                <div class="col-md-4 col-sm-6">
                                    <admin-input asp-for="SearchEmail" />
                                </div>
                            </div>
                            <div class="form-group">
                                <admin-label asp-for="StoreId" />
                                <div class="col-md-4 col-sm-6">
                                    <admin-select asp-for="StoreId" asp-items="Model.AvailableStores" />
                                </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-contactform">
                                        <i class="fa fa-search"></i> @T("Admin.Common.Search")
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="x_content">
                    <div id="contactform-grid"></div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
$(document).ready(function () {
    $("#contactform-grid").kendoGrid({
        dataSource: {
            transport: {
                read: {
                    url: "@Html.Raw(Url.Action("ContactFormList", "ContactForm"))",
                    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)]
        },
        scrollable: false,
        columns: [{
            field: "CreatedOn",
            title: "@T("Admin.System.ContactForm.Fields.CreatedOn")",
            width: 100,
            type: "date",
            format: "{0:G}"
        }, {
            field: "Store",
            title: "@T("Admin.System.ContactForm.Fields.Store")",
            width: 100
        }, {
            field: "Email",
            title: "@T("Admin.System.ContactForm.Fields.FullName")",
            width: 150
        }, {
            field: "IpAddress",
            title: "@T("Admin.System.ContactForm.Fields.IpAddress")",
            width: 50
        }, {
            field: "Subject",
            title: "@T("Admin.System.ContactForm.Fields.Subject")",
            width: 300,
                template: '<a class="k-link" href="Details/#=Id#">#=kendo.htmlEncode(Subject)#</a>',
        }]
    });
});
</script>
<script>
$(document).ready(function () {

    //search button
    $('#search-contactform').click(function () {
        //search
        var grid = $('#contactform-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.SearchEmail)").keydown(function (event) {
        if (event.keyCode == 13) {
            $("#search-contactform").click();
            return false;
        }
    });

});

function additionalData() {
    var data = {
        SearchStartDate: $('#@Html.FieldIdFor(model => model.SearchStartDate)').val(),
        SearchEndDate: $('#@Html.FieldIdFor(model => model.SearchEndDate)').val(),
        SearchEmail: $('#@Html.FieldIdFor(model => model.SearchEmail)').val(),
        StoreId: $('#@Html.FieldIdFor(model => model.StoreId)').val(),
    };
    addAntiForgeryToken(data);
    return data;
}

</script>
