<!-- DataTales Example -->
{% extends "index.html"%} {% block content%}
<div class="container-fluid">
  <div class="card shadow mb-4">
    <div class="card-header py-3">
      <h2    class="m-0 font-weight-bold text-primary">Data Buku</h2   >
      <br />
      {% if messages %} 
        {% for message in messages %}
        <div
            class="alert alert-{{ message.tags }} alert-dismissible fade show"
            role="alert"
        >
            <button
            type="button"
            class="close"
            data-dismiss="alert"
            aria-label="Close"
            >
            <span aria-hidden="true">&times;</span>
            </button>
            {{ message | safe }}
        </div>
        {% endfor %} 
      {% endif %}
      {% if request.user.is_authenticated and request.user.role == 'librarian'%}
      <a href="{% url 'book-create'%}" type="button" class="btn btn-primary"><i class="fas fa-fw fa-save"></i> Tambah Data Buku</a>
      {% endif %}
    </div>
    <div class="card-body ">
      <div class="table-responsive ">
        <table
          class="table table-bordered "
          id="dataTable"
          width="100%"
          cellspacing="0"
        >
          <thead>
            <tr>
              <th>No</th>
              <th>Cover Buku</th>
              <th>Judul Buku</th>
              <th>Nama Penerbit</th>
              <th>Nama Penulis</th>
              <th>Tahun Rilis</th>
              <th>Category Buku</th>
              <th>Aksi</th>
            </tr>
          </thead>
          <tbody>
            {% for books in buku %}
            <tr>
              <td>{{books.id}}</td>
              <td>{%if books.cover %}
                <img src="{{books.cover.url}}" width="50px" height="80px" alt="">
                {% endif %}
              </td>
              <td>{{books.judul}}</td>
              <td>{{books.penerbit}}</td>
              <td>{{books.penulis}}</td>
              <td>{{books.tahun_terbit}}</td>
              <td>{{books.categorybook.namaCategory}}</td>
              <td>
                <a href="detail/{{books.id}}" class="btn btn-info ">
                  <i class="fas fa-fw fa-info"></i><span class="text"> Detail</span>
                </a>
                {% if request.user.is_authenticated and request.user.role == 'librarian'%}
                <a href="edit/{{books.id}}" class="btn btn-warning ">
                  <i class="fas fa-fw fa-edit"></i><span class="text"> Edit</span>
                </a>
                <a href="delete/{{books.id}}" onclick="return confirm('aapakah anda yakin?')" class="btn btn-danger ">
                  <i class="fas fa-fw fa-trash"></i><span class="text"> Delete</span>
                </a>
                {%else%}
                <a href="peminjaman/{{books.id}}" class="btn btn-success ">
                  <i class="fas fa-fw fa-save"></i><span class="text"> peminjaman</span>
                </a>
                {% endif %}
              </td>
            </tr>
            {%endfor%}
          </tbody>
        </table>
      </div>
    </div>
  </div>
  
</div>
{% endblock content%}
