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

{% block body_class %}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 action">
	<h1>{% trans "Category management" %}</h1>
</div>
{% endblock header %}

{% block dashboard_content %}

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

<table class="table table-striped table-bordered">
	<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>{{ category.name }}</td>
			<td>{{ category.description|default:""|striptags|cut:"&nbsp;"|truncatewords:6 }}</td>
			<td>{{ category.get_num_children }}</td>
            <td>
				<a class="btn btn-primary" href="{% url dashboard:catalogue-category-update category.id %}">{% trans "Edit category" %}</a>
				<a class="btn btn-primary {% if not category.has_children %}disabled{% endif %}" href="{% url dashboard:catalogue-category-detail-list pk=category.pk %}">{% trans "Edit children" %}</a>
				<a class="btn btn-info" href="{{ category.get_absolute_url }}">{% trans "View on site" %}</a>
				<a class="btn btn-danger" href="{% url dashboard:catalogue-category-delete category.id %}">{% trans "Delete" %}</a>
            </td>
        </tr>
    {% endfor %}
	</tbody>
</table>

<a class="btn btn-large btn-primary" href="{% url dashboard:catalogue-category-create %}">{% trans "Create a new category" %}</a>

{% endblock dashboard_content %}
