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

{% block page_title %}{% translate "Dashboard" %}{% 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>
            <h4>
                {% if msg.0 == 'danger' %}
                    {% translate "Oh No!" %}
                {% elif msg.0 == 'success' %}
                    {% translate "Success!" %}
                {% endif %}
            </h4>
            <p>{{ msg.1 }}</p>
        </div>
    {% endif %}
    <div class="container col-sm-12">
        <h2>
            {% translate "Doctrine List" %}
        </h2>
        <div class="panel panel-default">
            <div class="panel-heading">
                {% translate "Doctrines" %}
            </div>
            <div class="panel-body">
                {% if not docs %}
                    <div class="alert alert-warning text-center">{% translate "No Doctrines Found" %} </div>
                {% else %}
                    <table class="table table-hover dataTable" id="docTable">
                        <thead>
                            <tr>
                                <th> </th>
                                <th>{% translate "Name" %}</th>
                                <th>{% translate "Categories" %}</th>
                                <th>{% translate "Description" %}</th>
                                <th>{% translate "Ships" %}</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for doc in docs %}
                                <tr>
                                    <td> <a href="{% url 'fittings:view_doctrine' doc.pk %}"><img src="{{ doc.icon_url }}" class="img-circle" style="display: block; margin: auto;"> </a></td>
                                    <td> <a href="{% url 'fittings:view_doctrine' doc.pk %}">{{ doc.name }}</a> </td>
                                    <td>
                                        {% for cat in doc.category.all %}
                                            <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> {{ doc.description|linebreaks }} </td>
                                    <td>
                                        {% for fitting in doc_dict|get_item:doc.pk %}
                                            <img src="{{ fitting.ship_type_type_id|type_render_url:32 }}" class="img-circle" data-toggle="tooltip" data-placement="bottom" title="{{ fitting.ship_type.name }}">
                                        {% endfor %}
                                    </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(){
        $('#docTable').DataTable({
            language: { url: '{% static LANG_PATH %}' },
            "order": [[ 1, "asc" ]],
        });
        $('[data-toggle="tooltip"]').tooltip();
    })
{% endblock %}
