@extends('layouts.admin')
@section('content')
@can('checklist_report_create')
    <div style="margin-bottom: 10px;" class="row">
        <div class="col-lg-12">
            <a class="btn btn-success" href="{{ route('admin.checklist-reports.create') }}">
                {{ trans('global.add') }} {{ trans('cruds.checklistReport.title_singular') }}
            </a>
            <button class="btn btn-warning" data-toggle="modal" data-target="#csvImportModal">
                {{ trans('global.app_csvImport') }}
            </button>
            @include('csvImport.modal', ['model' => 'ChecklistReport', 'route' => 'admin.checklist-reports.parseCsvImport'])
        </div>
    </div>
@endcan
<div class="card">
    <div class="card-header">
        {{ trans('cruds.checklistReport.title_singular') }} {{ trans('global.list') }}
    </div>

    <div class="card-body">
        <table class=" table table-bordered table-striped table-hover ajaxTable datatable datatable-ChecklistReport">
            <thead>
                <tr>
                    <th width="10">

                    </th>
                    <th>
                        {{ trans('cruds.checklistReport.fields.id') }}
                    </th>
                    <th>
                        {{ trans('cruds.checklistReport.fields.complaint') }}
                    </th>
                    <th>
                        {{ trans('cruds.checklistReport.fields.checklist_name') }}
                    </th>
                    <th>
                        {{ trans('cruds.checklistReport.fields.checklist_status') }}
                    </th>
                    <th>
                        {{ trans('cruds.checklistReport.fields.checklist_value_text_1') }}
                    </th>
                    <th>
                        {{ trans('cruds.checklistReport.fields.checklist_value_text_2') }}
                    </th>
                    <th>
                        {{ trans('cruds.checklistReport.fields.checklist_status_fusion_types_1') }}
                    </th>
                    <th>
                        {{ trans('cruds.checklistReport.fields.checklist_status_fusion_types_2') }}
                    </th>
                    <th>
                        &nbsp;
                    </th>
                </tr>
            </thead>
        </table>
    </div>
</div>



@endsection
@section('scripts')
@parent
<script>
    $(function () {
  let dtButtons = $.extend(true, [], $.fn.dataTable.defaults.buttons)
@can('checklist_report_delete')
  let deleteButtonTrans = '{{ trans('global.datatables.delete') }}';
  let deleteButton = {
    text: deleteButtonTrans,
    url: "{{ route('admin.checklist-reports.massDestroy') }}",
    className: 'btn-danger',
    action: function (e, dt, node, config) {
      var ids = $.map(dt.rows({ selected: true }).data(), function (entry) {
          return entry.id
      });

      if (ids.length === 0) {
        alert('{{ trans('global.datatables.zero_selected') }}')

        return
      }

      if (confirm('{{ trans('global.areYouSure') }}')) {
        $.ajax({
          headers: {'x-csrf-token': _token},
          method: 'POST',
          url: config.url,
          data: { ids: ids, _method: 'DELETE' }})
          .done(function () { location.reload() })
      }
    }
  }
  dtButtons.push(deleteButton)
@endcan

  let dtOverrideGlobals = {
    buttons: dtButtons,
    processing: true,
    serverSide: true,
    retrieve: true,
    aaSorting: [],
    ajax: "{{ route('admin.checklist-reports.index') }}",
    columns: [
      { data: 'placeholder', name: 'placeholder' },
{ data: 'id', name: 'id' },
{ data: 'complaint_complaint', name: 'complaint.complaint' },
{ data: 'checklist_name_name', name: 'checklist_name.name' },
{ data: 'checklist_status', name: 'checklist_status' },
{ data: 'checklist_value_text_1', name: 'checklist_value_text_1' },
{ data: 'checklist_value_text_2', name: 'checklist_value_text_2' },
{ data: 'checklist_status_fusion_types_1_name', name: 'checklist_status_fusion_types_1.name' },
{ data: 'checklist_status_fusion_types_2_name', name: 'checklist_status_fusion_types_2.name' },
{ data: 'actions', name: '{{ trans('global.actions') }}' }
    ],
    orderCellsTop: true,
    order: [[ 1, 'desc' ]],
    pageLength: 100,
  };
  let table = $('.datatable-ChecklistReport').DataTable(dtOverrideGlobals);
  $('a[data-toggle="tab"]').on('shown.bs.tab click', function(e){
      $($.fn.dataTable.tables(true)).DataTable()
          .columns.adjust();
  });
  
});

</script>
@endsection