{% extends "base.html" %}
{% load i18n brainstormers %}

{% block subtitle %}
    {% blocktrans with training=session.training date=session.date|date:"j F Y" brainstormer_type=brainstormer_display %}{{ brainstormer_type }} List of "{{ training }}" - {{ date }}{% endblocktrans %}
{% endblock subtitle %}

{% block actions %}
    {% if not session.is_closed %}
        <a class="btn btn-success" href="{% get_brainstormer_create_url session brainstormer_type%}"><i class="fa fa-plus"></i>Add {{ brainstormer_display }}</a>
        <a class="btn btn-warning" href="{{ session.get_brainstormer_import_url }}"><i class="fa fa-plus"></i> {% trans 'Import' %}</a>
    {% endif %}
    <a class="btn btn-default" href="{{ session.get_list_url }}">{% trans 'Back to session list' %}</a>
{% endblock actions %}

{% block main %}
    <div class="row">
        {% for brainstormer in object_list %}
            <div class="modal fade" id="modal{{ brainstormer.id }}">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title">{% trans 'Export' %}</h4>
                        </div>
                        <div class="modal-body">
                            <p>{% trans "Export your data with the wanted format." %}</p>
                            <p class="connectTrello">{% trans "For export with trello, sign in please :" %}</p>
                            <button type="button" class="btn btn-warning connectTrello">{% trans "Connect Trello" %}</button>
                        </div>
                        <div class="modal-footer">
                            <a class="btn btn-primary" href="{{ brainstormer.get_export_xls_url }}">{% trans "XLS" %}</a>
                            <a class="btn btn-primary" href="{{ brainstormer.get_export_csv_url }}">{% trans "CSV" %}</a>
                            <button type="button" class="btn btn-primary exportTrello" data-idbrainstormer="{{ brainstormer.id }}">{% trans "Trello" %}</button>
                            <button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6 col-md-4">
                <div class="panel panel-default">
                    <div class="panel-heading text-center">
                        {% trans brainstormer.get_brainstormer_type_display %} "<i>{{ brainstormer }}</i>"
                        <span class="btn-group pull-right">
                            {% if user.is_trainer or user.is_superuser %}
                                <a class="btn btn-xs btn-warning" href="{{ brainstormer.get_update_url }}"><i class="fa fa-pencil"></i></a>
                                <a class="btn btn-xs btn-danger" href="{{ brainstormer.get_delete_url }}"><i class="fa fa-trash"></i></a>
                            {% endif %}
                        </span>
                    </div>
                    <div class="panel-body">

                        {% with num_props=brainstormer.get_propositions|length num_grouped_props=brainstormer.get_grouped_propositions|length %}
                        <div class="row">
                          {% if num_grouped_props %}
                              <div class="col-xs-6 text-center" style="padding-right:0">
                                  <strong>{{ num_grouped_props }}</strong>
                                  <div>{% trans 'group' %}{{ num_grouped_props|pluralize }}</div>
                              </div>
                          {% endif %}
                          <div class="col-xs-6 text-center" style="padding-left:0">
                              <strong>{{ num_props }}</strong>
                              <div>{% trans 'proposition' %}{{ num_props|pluralize }}</div>
                          </div>
                        </div>
                        {% endwith %}
                        <br>
                        {% if brainstormer.is_exportable %}
                            <div class="btn-group btn-group-justified">
                                <a class="btn btn-warning btn-sm" data-toggle="modal" data-target="#modal{{ brainstormer.id }}">
                                    <i class="fa fa-download"></i> {% trans 'Export' %}
                                </a>
                                <a class="btn btn-primary btn-sm" href="{{ brainstormer.get_detail_url }}"><i class="fa fa-info"></i> {% trans 'Details' %}</a>
                            </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        {% empty %}
        <div class="alert alert-info">
            {% blocktrans with brainstormer_type=brainstormer_display %}No {{ brainstormer_type }}.{% endblocktrans %}
        </div>
        {% endfor %}
    </div>
    <script src="https://api.trello.com/1/client.js?key=4242942443eb5f4116a8b9d059a3400d"></script>
    <script src="{{ STATIC_URL }}brainstormers/js/exportTrello.js"></script>
{% endblock main %}
