{% extends 'dashboard/layout.html' %}
{% load category_tags %}
{% load i18n %}

{% block body_class %}{{ block.super }} catalogue{% endblock %}

{% block title %}
    {% trans "Category management" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
    <ul class="breadcrumb">
        <li>
            <a href="{% url 'dashboard:index' %}">{% trans "Dashboard" %}</a>
            <span class="divider">/</span>
        </li>
        <li class="active">{% trans "Categories" %}</li>
    </ul>
{% endblock %}

{% block header %}
    <div class="page-header">
        <a href="{% url 'dashboard:catalogue-category-create' %}" class="btn btn-primary btn-large pull-right"><i class="icon-plus"></i> {% trans "Create new category" %}</a>
        <h1>{% trans "Category management" %}</h1>
    </div>
{% endblock header %}

{% block dashboard_content %}
    <div class="alert alert-info">
        <p>{% trans "You are editing:" %}
            <strong><a href="{% url 'dashboard:catalogue-category-list' %}">{% trans "Home" %}</a></strong>
            {% if ancestors %}
                &gt;
                {% for ancestor in ancestors %}
                    <strong><a href="{% url 'dashboard:catalogue-category-detail-list' pk=ancestor.pk %}">{{ ancestor.name }}</a></strong>{% if not forloop.last %} > {% endif %}
                {% endfor %}
            {% endif %}
        </p>
    </div>

    {% if child_categories %}
        <table class="table table-striped table-bordered table-hover">
            <caption><i class="icon-sitemap icon-large"></i>{% trans 'Categories' %}</caption>
            <thead>
                <tr>
                    <th>{% trans "Name" %}</th>
                    <th>{% trans "Description" %}</th>
                    <th>{% trans "Number of child categories" %}</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                {% for category in child_categories %}
                    <tr>
                        <td><a href="{% url 'dashboard:catalogue-category-update' category.id %}">{{ category.name }}</a></td>
                        <td>{{ category.description|default:""|striptags|cut:"&nbsp;"|truncatewords:6 }}</td>
                        <td><a href="{% url 'dashboard:catalogue-category-detail-list' pk=category.pk %}">{{ category.get_num_children }}</a></td>
                        <td>
                            <div class="btn-toolbar">
                                <div class="btn-group">
                                    <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                                        {% trans "Actions" %}
                                        <span class="caret"></span>
                                    </a>
                                    <ul class="nav dropdown-menu pull-right">
                                        <li>
                                            <a href="{% url 'dashboard:catalogue-category-update' pk=category.id %}">
                                                {% trans "Edit category" %}
                                            </a>
                                        </li>
                                        <li>
                                            <a href="{% url 'dashboard:catalogue-category-create-child' parent=category.pk %}">
                                                {% trans "Add child category" %}
                                            </a>
                                        </li>
                                        <li{% if not category.has_children %} class="disabled"{% endif %}>
                                            <a href="{% url 'dashboard:catalogue-category-detail-list' pk=category.pk %}">
                                                {% trans "Edit children" %}
                                            </a>
                                        </li>
                                        <li>
                                            <a href="{{ category.get_absolute_url }}">
                                                {% trans "View on site" %}
                                            </a>
                                        </li>
                                        <li>
                                            <a href="{% url 'dashboard:catalogue-category-delete' pk=category.id %}">
                                                {% trans "Delete" %}
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>{% trans "There are no categories." %}</p>
    {% endif %}
{% endblock dashboard_content %}
