ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/Manufacturer/List.cshtml
@model ManufacturerListModel
@inject AdminAreaSettings adminAreaSettings
@{
    //page title
    ViewBag.Title = T("Admin.Catalog.Manufacturers").Text;
}

<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-building-o"></i>
                    @T("Admin.Catalog.Manufacturers")
                </div>
                <div class="actions btn-group btn-group-devided util-btn-margin-bottom-5">
                    <a href="@Url.Action("Create")" class="btn green"><i class="fa fa-plus"></i><span class="d-none d-sm-inline"> @T("Admin.Common.AddNew") </span></a>
                    <a href="@Url.Action("ExportXml")" class="btn default">
                        <i class="fa fa-file-code-o"></i> @T("Admin.Common.ExportToXml")
                    </a>
                    <a href="@Url.Action("ExportXlsx")" class="btn default">
                        <i class="fa fa-file-excel-o"></i> @T("Admin.Common.ExportToExcel")
                    </a>
                    <button type="button" id="importexcel" name="importexcel" class="btn blue">
                        <i class="fa fa-upload"></i>
                        @T("Admin.Common.ImportFromExcel")
                    </button>
                    <vc:admin-widget widget-zone="manufacturer_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="SearchManufacturerName" />
                            <div class="col-md-4 col-sm-6">
                                <admin-input asp-for="SearchManufacturerName" />
                            </div>
                        </div>
                        <div class="form-group">
                            <admin-label asp-for="SearchStoreId" />
                            <div class="col-md-4 col-sm-6">
                                <admin-select asp-for="SearchStoreId" 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-manufacturers">
                                    <i class="fa fa-search"></i> @T("Admin.Common.Search")
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="x_content">
                <div id="manufacturers-grid"></div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        $("#manufacturers-grid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("List", "Manufacturer"))",
                        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: "Name",
                title: "@T("Admin.Catalog.Manufacturers.Fields.Name")",
                template: '<a class="k-link" href="Edit/#=Id#">#=kendo.htmlEncode(Name)#</a>',
            },
            {
                field: "ShowOnHomePage",
                title: "@T("Admin.Catalog.Manufacturers.Fields.ShowOnHomePage")",
                width: 175,
                minScreenWidth: 750,
                headerAttributes: { style: "text-align:center" },
                attributes: { style: "text-align:center" },
                template: '# if(ShowOnHomePage) {# <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: "IncludeInTopMenu",
                title: "@T("Admin.Catalog.Manufacturers.Fields.IncludeInTopMenu")",
                width: 175,
                minScreenWidth: 750,
                headerAttributes: { style: "text-align:center" },
                attributes: { style: "text-align:center" },
                template: '# if(IncludeInTopMenu) {# <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: "Published",
                title: "@T("Admin.Catalog.Manufacturers.Fields.Published")",
                width: 100,
                minScreenWidth: 500,
                headerAttributes: { style: "text-align:center" },
                attributes: { style: "text-align:center" },
                template: '# if(Published) {# <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",
                headerAttributes: { style: "text-align:center" },
                attributes: { style: "text-align:center" },
                title: "@T("Admin.Catalog.Manufacturers.Fields.DisplayOrder")",
                width: 125,
                minScreenWidth: 750,
            }]
        });
    });
</script>
<script>
    $(document).ready(function () {
        //search button
        $('#search-manufacturers').click(function () {
            //search
            var grid = $('#manufacturers-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.SearchManufacturerName)").keydown(function (event) {
            if (event.keyCode == 13) {
                $("#search-manufacturers").click();
                return false;
            }
        });
    });

    function additionalData() {
        var data = {
            SearchManufacturerName: $('#@Html.FieldIdFor(model => model.SearchManufacturerName)').val(),
            SearchStoreId: $('#SearchStoreId').val()
        };
        addAntiForgeryToken(data);
        return data;
    }
</script>
@*import manufacturers form*@
<div class="modal-dialog" id="importexcel-window" style="display:none; padding: 0 10px;">
    <form asp-area="@Constants.AreaAdmin" asp-controller="Manufacturer" asp-action="ImportFromXlsx" method="post" enctype="multipart/form-data">
        
        <em>@T("Admin.Catalog.Manufacturer.List.ImportFromExcelTip")</em>
        <div class="form-group">
            &nbsp;
        </div>
        <div class="form-group">
            <div class="col-md-3" style="margin-top: 2px; height: 34px; padding-left: 25px;">
                <label class="control-label">
                    @T("Admin.Common.ExcelFile"):
                </label>
            </div>
            <div class="col-md-9">
                <input type="file" id="importexcelfile" name="importexcelfile" />
            </div>
        </div>
        <div class="form-group">
            &nbsp;
        </div>
        <div class="form-group">
            <div class="col-md-2">
                &nbsp;
            </div>
            <div class="col-md-10 text-right mt-10">
                <input type="submit" class="k-button" value="@T("Admin.Common.ImportFromExcel")" />
            </div>
        </div>
    </form>
</div>
<script>
    $(document).ready(function () {
        $("#importexcel").click(function (e) {
            e.preventDefault();
            var window = $("#importexcel-window");
            if (!window.data("kendoWindow")) {
                window.kendoWindow({
                    modal: true,
                    title: "@T("Admin.Common.ImportFromExcel")",
                    actions: ["Close"]
                });
            }
            window.data('kendoWindow').center().open();
        });
    });
</script>
