{% extends 'dashboard/dashboard_base.html' %}
{% load paginate %}
{% block stage %}
<div class="content">
  <div class="list">
    <div class="list-header">
      <label>Badges List <span class="pull-right"><a href="{% url "django_simple_forum:add_badge" %}" class=""><i class="fa fa-user-plus view"></i>New Badge</a></span></label>
    </div>
    <div class="results-slct-items row mt">
      {% paginate 10 badges_list %}
      {% show_pageitems %}
      <div class="col-md-6 col-xs-6 page-items">
        Per Page
        <select id="pagination_per_page">
        <option value="10" {% if per_page == "10" %}selected{% endif %}>10</option>
        <option value="20" {% if per_page == "20" %}selected{% endif %}>20</option>
        <option value="50" {% if per_page == "50" %}selected{% endif %}>40</option>
        <option value="100" {% if per_page == "100" %}selected{% endif %}>40</option>
        </select>
      </div>
      <form name="filter_form" id="filter_form" method='post'>
        {% csrf_token %}
        <input type="text" name="search_text" id="search_text" value="{{ request.POST.search_text }}"/>
        <input type="hidden" name="filter_per_page" id="filter_per_page" value="{{ filter_per_page }}"/>
        <button type="submit">Submit</button>
      </form>
    </div>
    {% if badges_list %}
    <div class="user_table">
      <div class="table-responsive">

    <table style="overflow:scroll;" class="sub_items table table-hover table-bordered">
                      <thead>
                        <tr>
                          <th>Id</th>
                          <th>Title</th>
                          <th>Actions</th>
                        </tr>
                      </thead>
                      <tbody class="overflow:scroll;">
                        {% for badge in badges_list %}
                        <tr class="sub_item_trs sub_item_{{ item.item_key }}">
                          <td>{{ badge.id }}</td>
                          <td>{{ badge.title }}</td>
                          <td><a href="{% url "django_simple_forum:view_badge" badge.slug %}" class=""><i class="fa fa-eye view"></i></a><a href="{% url "django_simple_forum:edit_badge" badge.slug %}" class=""><i class="fa fa-edit edit"></i></a><a href="#" data-href="{% url "django_simple_forum:delete_badge" badge.slug %}" class="delete-badge"><i class="fa fa-trash delete"></i></a></td>
                        </tr>
                        {% endfor %}
                      </tbody>
                    </table>
                    {% show_pages %}
      </div>
    </div>
    <nav class="overview-paging">
    </nav>
        {% else %}
    No Badge Available in database
    {% endif %}

  </div>
</div>
{% endblock %}
{% block extra_js %}
<script type="text/javascript">
  $('.delete-badge').click(function(e){
  e.preventDefault();
  href = $(this).attr('data-href');
  if (!confirm('Do you want to delete Badge?'))
    return;
  $.post(href, $("form#jobform").serialize(), function(data) {
      if (data.error) {
        alert(data.response);
      } else {
        alert("Badge Deleted Successfully")
        window.location = '.';
      }
    }, 'json');
  });

</script>
{% endblock %}