@extends('layouts.app')
@section('title', __('meddocuments::lang.access_audit'))
@section('content')
<section class="content-header"><h1>@lang('meddocuments::lang.access_audit')</h1></section>
<section class="content">
    @component('components.widget', ['class' => 'box-primary'])
        <div class="row" style="margin-bottom:12px;">
            <div class="col-md-2">
                {!! Form::label('f_action', __('meddocuments::lang.action') . ':') !!}
                <select id="meddoc_f_action" class="form-control input-sm">
                    <option value="">@lang('meddocuments::lang.all')</option>
                    @foreach($actions as $a)<option value="{{ $a }}">{{ $a }}</option>@endforeach
                </select>
            </div>
            <div class="col-md-2">
                {!! Form::label('f_document', __('meddocuments::lang.document_id') . ':') !!}
                <input type="number" id="meddoc_f_document" class="form-control input-sm" min="1">
            </div>
            <div class="col-md-2">
                {!! Form::label('f_from', __('meddocuments::lang.date_from') . ':') !!}
                <input type="date" id="meddoc_f_from" class="form-control input-sm">
            </div>
            <div class="col-md-2">
                {!! Form::label('f_to', __('meddocuments::lang.date_to') . ':') !!}
                <input type="date" id="meddoc_f_to" class="form-control input-sm">
            </div>
        </div>
        <div class="table-responsive">
            <table class="table table-bordered table-striped" id="meddoc_audit_table" style="width:100%">
                <thead><tr>
                    <th>@lang('meddocuments::lang.when')</th>
                    <th>@lang('meddocuments::lang.document')</th>
                    <th>@lang('meddocuments::lang.action')</th>
                    <th>@lang('meddocuments::lang.actor')</th>
                    <th>@lang('meddocuments::lang.ip')</th>
                    <th>@lang('meddocuments::lang.user_agent')</th>
                </tr></thead>
            </table>
        </div>
    @endcomponent
</section>
@endsection
@section('javascript')
<script>
$(function () {
    var table = $('#meddoc_audit_table').DataTable({
        processing: true, serverSide: true,
        ajax: {
            url: '{{ route('meddoc.audit.data') }}',
            data: function (d) {
                d.action = $('#meddoc_f_action').val();
                d.document_id = $('#meddoc_f_document').val();
                d.date_from = $('#meddoc_f_from').val();
                d.date_to = $('#meddoc_f_to').val();
            }
        },
        columns: [
            { data: 'created_at', name: 'created_at' },
            { data: 'document_title', name: 'document_title' },
            { data: 'action', name: 'action' },
            { data: 'actor', name: 'actor', orderable: false },
            { data: 'ip', name: 'ip' },
            { data: 'user_agent', name: 'user_agent', orderable: false },
        ],
        order: [[0, 'desc']],
    });
    $('#meddoc_f_action, #meddoc_f_document, #meddoc_f_from, #meddoc_f_to').on('change', function () { table.ajax.reload(); });
});
</script>
@endsection
