{% extends 'events/management/full_width_base.html' %}
{% from 'events/abstracts/management/_abstract_list.html' import render_abstract_list %}
{% from 'events/management/_lists.html' import render_displayed_entries_fragment %}

{% block back_button_url -%}
    {{ url_for('.management', event) }}
{%- endblock %}

{% block back_button_title -%}
    {%- trans %}Back to Call for Abstracts{% endtrans -%}
{% endblock %}

{% block title %}
    {%- trans %}Abstracts{% endtrans -%}
{% endblock %}

{% block subtitle %}
    {% trans %}List of abstracts{% endtrans %}
{% endblock %}

{% block content %}
    <div class="list abstracts">
        <div class="toolbars space-after">
            <div class="toolbar">
                <div class="group">
                    <button class="icon-checkbox-checked i-button arrow left icon-only"
                            aria-hidden="true" data-toggle="dropdown"></button>
                    <ul class="i-dropdown">
                        <li><a href="#" id="select-all">{% trans 'Selection' %}All{% endtrans %}</a></li>
                        <li><a href="#" id="select-none">{% trans 'Selection' %}None{% endtrans %}</a></li>
                    </ul>
                </div>
                <div class="group">
                    <button class="i-button icon-settings js-dialog-action js-customize-list highlight"
                       data-href="{{ url_for('.customize_abstract_list', event) }}"
                       data-title="{% trans %}Abstract list configuration{% endtrans %}"
                       data-dialog-classes="list-filter-dialog"
                       data-update='{"html": "#abstract-list", "filter_statistics": "#filter-statistics"}'
                       data-ajax-dialog>
                        {% trans %}Customize list{% endtrans %}
                    </button>
                </div>
                <div class="group">
                    <button class="i-button arrow icon-plus hide-if-locked"
                            data-toggle="dropdown">
                        {% trans 'Abstract' %}New{% endtrans %}
                    </button>
                    <ul class="i-dropdown">
                        <li>
                            <a class="js-dialog-action"
                               title="{% trans %}Add new abstract{% endtrans %}"
                               data-title="{% trans %}Add new abstract{% endtrans %}"
                               data-href="{{ url_for('.manage_create_abstract', event) }}"
                               data-update='{"html": "#abstract-list", "filter_statistics": "#filter-statistics"}'
                               data-confirm-close-unsaved
                               data-ajax-dialog>
                                {% trans %}Abstract{% endtrans %}
                            </a>
                        </li>
                        <li>
                            {%- if can_create_invited_abstracts -%}
                                {%- set message = _("Add new invited abstract") %}
                            {%- else -%}
                                {%- set message = _("You first need to create a notification template for invited abstracts") %}
                            {%- endif -%}
                            <a class="js-dialog-action {{ 'disabled' if not can_create_invited_abstracts }}"
                               title="{{ message }}"
                               data-title="{% trans %}Add new invited abstract{% endtrans %}"
                               data-href="{{ url_for('.manage_create_abstract', event, invited=true) }}"
                               data-update='{"html": "#abstract-list", "filter_statistics": "#filter-statistics"}'
                               data-confirm-close-unsaved
                               data-ajax-dialog>
                                {% trans %}Invited abstract{% endtrans %}
                            </a>
                        </li>
                    </ul>
                </div>
                <div class="group hide-if-locked">
                    <button class="i-button arrow icon-remove js-requires-selected-row disabled"
                            data-toggle="dropdown">
                        {%- trans %}Remove{% endtrans -%}
                    </button>
                    <ul class="i-dropdown">
                        <li>
                            <a href="#" class="js-requires-selected-row"
                               data-href="{{ url_for('.manage_delete_abstracts', event) }}"
                               data-params-selector="#abstract-list input[name=abstract_id]:checked"
                               data-update='{"html": "#abstract-list", "filter_statistics": "#filter-statistics"}'
                               data-confirm="{% trans %}Do you really want to delete the selected abstracts?{% endtrans %}"
                               data-title="{% trans %}Confirm deletion{% endtrans %}"
                               data-method="POST">
                                {% trans %}Abstracts{% endtrans %}
                            </a>
                        </li>
                        <li>
                            <a href="#" class="js-requires-selected-row"
                               data-href="{{ url_for('.manage_delete_abstracts', event, delete_contribs=1) }}"
                               data-params-selector="#abstract-list input[name=abstract_id]:checked"
                               data-update='{"html": "#abstract-list", "filter_statistics": "#filter-statistics"}'
                               data-confirm="{% trans %}Do you really want to delete the selected abstracts and their linked contributions?{% endtrans %}"
                               data-title="{% trans %}Confirm deletion{% endtrans %}"
                               data-method="POST">
                                {% trans %}Abstracts & linked contributions{% endtrans %}
                            </a>
                        </li>
                    </ul>
                </div>
                <div class="group hide-if-locked">
                    <button class="i-button arrow icon-hammer js-requires-selected-row disabled"
                            data-toggle="dropdown">
                        {%- trans %}Judge{% endtrans -%}
                    </button>
                    <ul class="i-dropdown">
                        <li>
                            <a class="accept js-requires-selected-row"
                               data-href="{{ url_for('.manage_judge_abstracts', event) }}"
                               data-title="{% trans %}Accept selected abstracts{% endtrans %}"
                               data-params-selector="#abstract-list input[name=abstract_id]:checked"
                               data-params='{"judgment": "accept"}'
                               data-update='{"html": "#abstract-list", "filter_statistics": "#filter-statistics"}'
                               data-method="POST"
                               data-ajax-dialog>
                                {%- trans %}Accept{% endtrans -%}
                            </a>
                        </li>
                        <li>
                            <a class="js-requires-selected-row js-dialog-action danger"
                               data-href="{{ url_for('.manage_judge_abstracts', event) }}"
                               data-title="{% trans %}Reject selected abstracts{% endtrans %}"
                               data-params-selector="#abstract-list input[name=abstract_id]:checked"
                               data-params='{"judgment": "reject"}'
                               data-update='{"html": "#abstract-list", "filter_statistics": "#filter-statistics"}'
                               data-method="POST"
                               data-ajax-dialog>
                                {%- trans %}Reject{% endtrans -%}
                            </a>
                        </li>
                        <li>
                            <a class="js-requires-selected-row js-dialog-action"
                               data-href="{{ url_for('.manage_judge_abstracts', event) }}"
                               data-title="{% trans %}Merge selected abstracts{% endtrans %}"
                               data-params-selector="#abstract-list input[name=abstract_id]:checked"
                               data-params='{"judgment": "merge"}'
                               data-update='{"html": "#abstract-list", "filter_statistics": "#filter-statistics"}'
                               data-method="POST"
                               data-ajax-dialog>
                                {%- trans %}Merge{% endtrans -%}
                            </a>
                        </li>
                        <li>
                            <a class="js-requires-selected-row js-dialog-action"
                               data-href="{{ url_for('.manage_judge_abstracts', event) }}"
                               data-title="{% trans %}Mark selected abstracts as duplicate{% endtrans %}"
                               data-params-selector="#abstract-list input[name=abstract_id]:checked"
                               data-params='{"judgment": "mark_as_duplicate"}'
                               data-update='{"html": "#abstract-list", "filter_statistics": "#filter-statistics"}'
                               data-method="POST"
                               data-ajax-dialog>
                                {%- trans %}Mark as duplicate{% endtrans -%}
                            </a>
                        </li>
                    </ul>
                </div>
                <div class="group">
                    <div id="email-authors-container"
                         class="i-button-wrapper"
                         data-event-id="{{ event.id }}"
                         data-object-context="abstracts"
                         data-params-selector="#abstract-list input[name=abstract_id]:checked">
                    </div>
                    <div id="email-abstract-roles-container"
                         class="i-button-wrapper"
                         data-object-context="abstracts"
                         data-id-selector="#abstract-list input[name=abstract_id]:checked"
                         data-metadata-url="{{ url_for('.api_email_abstract_roles_metadata', event) }}"
                         data-preview-url="{{ url_for('.api_email_abstract_roles_preview', event) }}"
                         data-send-url="{{ url_for('.api_email_abstract_roles_send', event) }}">
                    </div>
                </div>
                {% if can_download_attachments %}
                    <div class="group">
                        <button class="i-button icon-attachment js-requires-selected-row js-submit-list-form disabled"
                                data-href="{{ url_for('.download_attachments', event) }}">
                            {%- trans %}Download attachments{%- endtrans %}
                        </button>
                    </div>
                {% endif %}
                <div class="group">
                    <button class="i-button arrow button js-requires-selected-row disabled"
                            data-toggle="dropdown">
                        {%- trans %}Export{% endtrans -%}
                    </button>
                    <ul class="i-dropdown">
                        {% if indico_config.LATEX_ENABLED %}
                            <li>
                                <a href="#"
                                   class="icon-file-pdf js-requires-selected-row disabled js-submit-list-form"
                                   data-href="{{ url_for('.abstracts_pdf_export', event) }}">PDF</a>
                            </li>
                        {% endif %}
                        <li>
                            <a href="#"
                               class="icon-file-spreadsheet js-requires-selected-row disabled js-submit-list-form"
                               data-href="{{ url_for('.abstracts_csv_export', event) }}">CSV</a>
                        </li>
                        <li>
                            <a href="#"
                               class="icon-file-excel js-requires-selected-row disabled js-submit-list-form"
                               data-href="{{ url_for('.abstracts_xlsx_export', event) }}">XLSX (Excel)</a>
                        </li>
                        <li>
                            <a href="#"
                               class="icon-file-css js-requires-selected-row disabled js-submit-list-form"
                               data-href="{{ url_for('.abstracts_json_export', event) }}">JSON</a>
                        </li>
                    </ul>
                </div>
                {{ template_hook('abstract-list-options', event=event) }}
                <div class="group">
                    <button class="i-button button change-columns-width"
                            title="{% trans %}Adapt columns width{% endtrans %}">
                    </button>
                </div>
            </div>
            <div class="toolbar">
                <div class="group">
                    <button class="i-button icon-link js-static-url"
                            data-href="{{ url_for('.generate_static_url', event) }}"
                            title="{% trans %}Generate a URL for the selected filters and columns.{% endtrans %}">
                    </button>
                </div>
                <div class="group">
                    <div id="filter-statistics">
                        {{ render_displayed_entries_fragment(abstracts|length, total_abstracts) }}
                    </div>
                </div>
                <div class="group">
                    <span class="i-button label icon-search"></span>
                    <input type="text" id="search-input" placeholder="{% trans %}Enter #id or search string{% endtrans %}">
                </div>
            </div>
        </div>
        <div class="list-content" id="abstract-list">
            {{ render_abstract_list(abstracts, dynamic_columns, static_columns, total_abstracts, can_create_invited_abstracts=can_create_invited_abstracts) }}
        </div>
        <div id="filter-placeholder"></div>
    </div>

    <script>
        setupAuthorsListButton('#email-authors-container');
        setupEmailContribAbstractRoles('#email-abstract-roles-container');
        setupAbstractList();
        setupAbstractJudgment({
            trackSessionMap: {{ track_session_map|tojson }}
        });
    </script>
{% endblock %}
