
	<!-- Page header -->
	{capture name="buttons"}
{*		<form action="{$adminUrl}/lowerrors" method="post">*}
			<button type="button" name="action" value="clear" class="btn btn-sm btn-primary clear_log"><i class="ph-trash me-2"></i> Очистить лог</button>
{*		</form>*}
	{/capture}
	{capture name="breadcrumb"}
		<a href="{$adminUrl}/lowerrors" class="breadcrumb-item">{if isset($title)}{$title}{/if}</a>
	{/capture}

	{capture name="showBy"}
	{/capture}

	{include file="components/page-header.tpl" buttons=$smarty.capture.buttons breadcrumb=$smarty.capture.breadcrumb showBy=$smarty.capture.showBy}
	<!-- /page header -->


	<div class="content">
	    <div class="row">
	        <div class="col-md-12">
	            <div class="card">
		            <div class="">
		                <table class="table table-togglable table-striped table-hover error-archive" id="errors">
	                    <thead>
	                        <tr>
	                            <th data-hide="phone" class="text-center" width="60" nowrap="nowrap">Дата</th>
		                        <th data-hide="phone" class="text-center" nowrap="nowrap">Тип</th>
	{*	                        <th data-hide="phone" class="text-center" nowrap="nowrap">Строка</th>*}
		                        <th data-toggle="true" nowrap="nowrap">Ошибка</th>
	                        </tr>
	                    </thead>
	{*                    {if !empty($error)}*}
	{*						<tbody>*}
	{*							{foreach from=$error item=e}*}
	{*							<tr>*}
	{*								<td nowrap="nowrap" class="text-center">{$e[0]} </td>*}
	{*								<td nowrap="nowrap" class="text-center">{$e[3]}</td>*}
	{*								<td nowrap="nowrap" class="text-center">{$e[8]}</td>*}
	{*								<td>*}
	{*									<div class="card-body context-deactivate">*}
	{*										<b>Строка:</b> {$e[6]} <b>, в файле:</b> {$e[7]}<br />*}
	{*										<code>{$e[5]}</code><br />*}
	{*										<span class="small text-gray">*}
	{*											IP: <b class="text-info">{$e[1]}</b> | URI: <b>{$e[2]}</b>*}
	{*										</span>*}
	{*									</div>*}
	{*								</td>*}
	{*							</tr>*}
	{*							{/foreach}*}
	{*						</tbody>*}
	{*						{else}*}
	{*						<tbody>*}
	{*							<tr>*}
	{*								<td colspan="4" class="text-center">В Логе нет записей.</td>*}
	{*							</tr>*}
	{*						</tbody>*}
	{*						{/if}*}
	                </table>
		            </div>
	            </div>
	        </div>

	    </div>
	</div>

	<script>

        $(document).on('click', '.clear_log', function () {
            $.post( "{$adminUrl}/lowerrors", { action : "clear" }, function( response ) {
                new Noty({ text: response.message, type: response.type, timeout: 1500 }).show();
                if (response.status == 200) {
                    var myTable = document.getElementById("errors");
                    for (var a = myTable.rows.length - 1; a > 0; a--) {
	                    myTable.deleteRow(a)
                    }
                }
            });
        })

	    var ErrorList = function() {

	        var _componentDatatable = function() {
	            if (!$().DataTable) {
	                console.warn('Warning - datatables.min.js is not loaded.');
	                return;
	            }

	            // Initialize
	            $.extend( $.fn.dataTable.defaults, {
	                searching: false,
	                lengthChange: false,
	                autoWidth: false,
	                paging: false,
	                processing: true,
	                serverSide: true,
	                deferRender: false,
	                stateSave: true,
	                ordering: false,
	                ajax: {
	                    "url": "{$adminUrl}/lowerrors?action=read",
	                    "type": 'POST',
	                    // success: function (data) {
	                    //     // console.log(data);
	                    // },
	                },
	                'createdRow': function( row, data, dataIndex ) {
	                    $(row).attr("data-error", dataIndex).attr("id", 'error-'+dataIndex);
	                },
	                columns: [
	                    { data: "date",
	                        render: function (dataField, type, row) {
	                            return '<span class="font-weight-semibold">'  + row[0] + '</span>';
	                        }
	                    },
	                    { data: "text",
	                        render: function (dataField, type, row) {
	                            return '<span>'  + row[3] + '</span>';
	                        }
	                    },
	                    { data: "info",
	                        render: function (dataField, type, row) {
	                            return '<b>Строка:</b> ' + row[6] + ' <b>, <b>в файле:</b> ' + row[7] + '<br />' +
	                                '<code class="p-0">' + row[5] + '</code><br />' +
	                                '<span class="small text-gray">IP: <b class="text-info">' + row[1] + '</b> | URI: <b>' + row[2] + '</b> </span>';
	                        }
	                    },
	                ],
	                columnDefs: [
	                    { orderable: false, width: '10%',  targets: 0, className: "text-left text-nowrap"},
	                    { orderable: false, width: '20%', targets: 1, className: "text-center text-nowrap" },
	                    { orderable: false, width: '70%', targets: 2, className: "text-left"},

	                ],
	                order: [[0, 'asc']],
	                dom: '<"datatable-header"fl><"datatable-scroll-lg"t><"datatable-footer"ip>',
	                language: { "url": "{$GLOBAL_URL}/admin/assets/js/vendor/tables/datatables/lang/{$config.admin_language}.json" },
	                lengthMenu: [10, 25, 50, 75, 100],
	                displayLength: 10,
	                drawCallback: function (settings) {
	                    $(".datatable-header").remove();
	                    $(".datatable-footer").remove();
	                }
	            });

	            $('.error-archive').DataTable({ });
	        };

	        function plural(number, titles) {
	            cases = [2, 0, 1, 1, 1, 2];
	            return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
	        }

	        // Select2 for length menu styling
	        var _componentSelect2 = function() {
	            if (!$().select2) {
	                console.warn('Warning - select2.min.js is not loaded.');
	                return;
	            }

	            // Initialize
	            $('.dataTables_length select').select2({
	                minimumResultsForSearch: Infinity,
	                dropdownAutoWidth: true,
	                width: 'auto'
	            });
	        };



	        return {
	            init: function() {
	                _componentDatatable();
	                _componentSelect2();
	            }
	        }
	    }();

	    document.addEventListener('DOMContentLoaded', function() {
	        ErrorList.init();
	    });

	</script>





