{% extends "dashboard/layout.html" %}
{% load currency_filters %}
{% load sorting_tags %}
{% load i18n %}

{% block body_class %}{{ block.super }} reviews{% endblock %}
{% block title %}
    {% trans "Reviews" %} | {{ 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 "Reviews" %}</li>
    </ul>
{% endblock %}

{% block header %}
    <div class="page-header">
        <h1>{% trans "Reviews" %}</h1>
    </div>
{% endblock header %}

{% block dashboard_content %}

    <div class="table-header">
        <h3><i class="icon-search icon-large"></i>{% trans "Review Search" %}</h3>
    </div>
    <div class="well">
        <form action="." method="get" class="form-inline">
            {% include 'partials/form_fields_inline.html' with form=form %}
            <button type="submit" class="btn btn-primary top-spacer">{% trans "Search" %}</button>
        </form>
    </div>

    {% if review_list %}

        <form action="." method="post">
            {% csrf_token %}
            <table class="table table-striped table-bordered table-hover">
                <caption>
                    <h3 class="pull-left"><i class="icon-thumbs-up icon-large"></i>{{ description }}</h3>
                    <div class="pull-right">
                        <div class="form-inline">
                            {% trans "Update status of selected reviews" %}
                            {{ review_form.status }}
                            <input type="hidden" name="action" value="update_selected_review_status" />
                            <button type="submit" name="update" class="btn btn-success">{% trans "Update" %}</button>
                        </div>
                    </div>
                </caption>
                <tr>
                    <th></th>
                    <th>{% trans "Title" %}</th>
                    <th>{% trans "Product" %}</th>
                    <th>{% trans "User" %}</th>
                    <th>{% anchor 'score' _("Score") %}</th>
                    <th>{% anchor 'total_votes' _("Votes") %}</th>
                    <th>{% trans "Status" %}</th>
                    <th>{% anchor 'date_created' _("Date created") %}</th>
                    <th></th>
                </tr>
                {% for review in review_list %}
                    <tr>
                        <td><input type="checkbox" name="selected_review" class="selected_review" value="{{ review.id }}"/></td>
                        <td>
                            <a href="{% url 'dashboard:reviews-update' pk=review.id %}">{{ review.title }}</a>
                        </td>
                        <td>
                            {% if review.product %}
                                <a href='{% url 'catalogue:detail' product_slug=review.product.slug pk=review.product.id %}'>{{ review.product.title }}</a> </td>
                        {% else %}
                            {% trans "[Product deleted]" %}
                        {% endif %}
                        <td>
                            {% if not review.is_anonymous %}
                                <a href="{% url 'dashboard:user-detail' pk=review.user.id %}">{{ review.reviewer_name }}</a>
                            {% else %}
                                {{ review.name }}
                            {% endif %}
                        </td>
                        <td>
                            {{ review.score|floatformat:1 }} / {{ 5.0|floatformat:1 }}
                        </td>
                        <td>{{ review.total_votes }}</td>
                        <td>
                            {% if review.status == 1 %}
                                <span class="label label-success">
                                    {% elif review.status == 2 %}
                                    <span class="label label-important">
                                    {% else %}
                                        <span class="label label-info">
                                        {% endif %}
                                        {{ review.get_status_display }}
                                    </span>
                                </td>
                                <td>{{ review.date_created }}</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="dropdown-menu pull-right">
                                                {% if review.title and review.product %}
                                                    <li><a href="{% url 'catalogue:reviews-detail' product_slug=review.product.slug product_pk=review.product.id pk=review.id %}">{% trans "View on site" %}</a></li>
                                                {% endif %}
                                                <li><a href="{% url 'dashboard:reviews-update' pk=review.id %}">{% trans "Edit" %}</a></li>
                                                <li><a href="{% url 'dashboard:reviews-delete' pk=review.id %}">{% trans "Delete" %}</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        {% endfor %}
                    </table>
                    {% include "partials/pagination.html" %}
                </form>
            {% else %}
                <table class="table table-striped table-bordered table-hover">
                    <caption>{{ description }}</caption>
                    <tr><td>{% trans "No reviews found." %}</td></tr>
                </table>
            {% endif %}

        {% endblock dashboard_content %}
