{% extends 'fittings/base.html' %}
{% load tags %}
{% load static %}
{% load i18n %}
{% load humanize %}
{% load filters %}
{% load evelinks %}

{% block page_title %}{% translate "View All Fits" %}{% endblock %}

{% block fittings_block %}
    {% if msg %}
            <div class="alert alert-{{ msg.0 }} alert-dismissible" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="close">
                        <span aria-hidden="true">&times</span>
                    </button>
                    {% if msg.0 != 'warning' %}
                        <h4>
                            {% if msg.0 == 'danger' %}
                                {% translate "Oh No!" %}
                            {% elif msg.0 == 'success' %}
                                {% translate "Success!" %}
                            {% endif %}
                        </h4>
                    {% endif %}
                    <p>{{ msg.1 }}</p>
                </div>
        {% endif %}
    <div class="container col-sm-12">
        <h2>
            {% translate "Fit List" %}
        </h2>
        <div class="panel panel-default">
            <div class="panel-heading">
                {% translate "Fits" %}
            </div>
            <div class="panel-body">
                {% if not fits %}
                    <div class="alert alert-warning text-center">{% translate "No Fits Found" %}</div>
                {% else %}
                    <table class="table table-hover dataTable" id="fitTable">
                        <thead>
                            <tr>
                                <th>{% translate "Name" %}</th>
                                <th>{% translate "Categories" %}</th>
                                <th>{% translate "Description" %}</th>
                                <th>{% translate "Ship Type" %}</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for fit in fits %}
                                <tr>
                                    <td> <a href="{% url 'fittings:view_fit' fit.pk %}">{{ fit.name }}</a> </td>
                                    <td>
                                        {% for cat in cats|get_item:fit.pk %}
                                        <span class="label" style="background-color: {{cat.color}};"><a href="{% url 'fittings:view_category' cat.pk %}" class="nostyle">{{cat.name}}</a></span>
                                        {% endfor %}
                                    </td>
                                    <td> {{ fit.description }} </td>
                                    <td> <img class="img-circle" src="{{ fit.ship_type_type_id|type_render_url:32 }}" title="{{ fit.ship_type.name }}"> {{ fit.ship_type.name }} </td>
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                {% endif %}
            </div>
        </div>
    </div>
{% endblock %}

{% block extra_javascript %}
    {% include 'bundles/datatables-js.html' %}
{% endblock %}

{% block extra_script %}
    {% get_dt_lang LANGUAGE_CODE as LANG_PATH %}
    $(document).ready(function(){
        $('#fitTable').DataTable({
            language: { url: '{% static LANG_PATH %}' },
        });
        $('[data-toggle="tooltip"]').tooltip();
    })
{% endblock %}
