{% extends "layout.html" %}
{% block content %}
  <article class="media content-section">

      <!-- <h4>Team Management</h4> -->
      <div class='team_management_div'>
      <table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>DOB</th>
                <th>Location</th>
                <th>Team</th>
                <th>QR Code</th>
                <th>Swab Date</th>
                <th>Result</th>
            </tr>
        </thead>
        </table>
      </div>

  </article>

  <!-- Modal -->
  <div class="modal fade" id="qrModal" tabindex="-1" role="dialog" aria-labelledby="qrModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="qrModalLabel">Copy or Save QR Code</h5>
          <!-- <div class="modal_jotform_form_id"></div> -->
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-footer">
          <!-- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> -->
          <img src="">
        </div>
      </div>
    </div>
  </div>

<script>

  $(document).ajaxError(function (event, jqxhr, settings, thrownError) {
     console.log(jqxhr.status);
     console.log(thrownError);
     console.log(event);
     if (jqxhr.status === 302) {
        document.location.href = "{{ url_for('users.reauthenticate', next='team_management/table', message='To protect your data and your account, you must reauthenticate.')  | safe}}";
     } else if (jqxhr.status === 577) {
        document.location.href = "{{ url_for('main.home', message='The system is refreshing your database, please check in after ~15 minutes') }}";
     }
  });

  $(document).ready(function() {
      var table = $('#example').DataTable({
        dom: '{{ dt_dom }}',
        buttons: ['copy', 'excel', 'pdf', 'csv'],
        bProcessing: true,
        bServerSide: true,
        sPaginationType: "full_numbers",
        lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
        bjQueryUI: true,
        sAjaxSource: '/serverside_table',
        sort:[],
        columns: [
          {"data": "First Name"},
          {"data": "Last Name"},
          {"data": "DOB"},
          {"data": "Location"},
          {"data": "Team"},
          {"data": "QR Code"},
          {"data": "Swab Date"},
          {"data": "Result"}
        ],
        //initComplete: function () { table.buttons().container().appendTo( '#example_wrapper' ); }
      });

  /*disable datatable warnings*/
  $.fn.dataTable.ext.errMode = 'none';

  /*display warnings in the console*/
  table.on('error.dt', function (e, settings, techNote, message) {
        console.log('An error has been reported by DataTables: ', message);
  });

  } );
</script>

{% endblock content %}
