{% extends 'events/management/full_width_base.html' %}
{% from 'events/contributions/management/_contribution_list.html' import render_contrib_list %}
{% from 'events/management/_lists.html' import render_filter_statistics %}

{% block title %}
    {% trans %}Contributions{% endtrans %}
{% endblock %}

{% block title_actions %}
    {%- if event.type == 'conference' -%}
        <a id="contributions-settings-dropdown"
           class="i-button borderless icon-settings arrow js-dropdown"
           data-toggle="dropdown">{% trans %}Settings{% endtrans %}</a>
        <ul class="i-dropdown">
            <li>
                <a href="#"
                   title="{% trans %}Manage contribution types{% endtrans %}"
                   data-reload-after="customData"
                   data-title="{% trans %}Manage contribution types{% endtrans %}"
                   data-href="{{ url_for('.manage_types', event) }}"
                   data-qtip-position="right"
                   data-ajax-dialog>
                    {% trans %}Contribution types{% endtrans %}</a>
            </li>
            <li>
                <a href="#"
                   title="{% trans %}Set default contribution duration{% endtrans %}"
                   data-title="{% trans %}Set default contribution duration{% endtrans %}"
                   data-href="{{ url_for('.manage_default_duration', event) }}"
                   data-qtip-position="right"
                   data-ajax-dialog>
                    {% trans %}Contribution duration{% endtrans %}</a>
            </li>
            <li>
                <a href="#"
                   title="{% trans %}Manage custom fields{% endtrans %}"
                   data-ajax-dialog
                   data-reload-after="customData"
                   data-title="{% trans %}Manage custom fields{% endtrans %}"
                   data-href="{{ url_for('.manage_fields', event) }}"
                   data-qtip-position="right">
                    {% trans %}Custom fields{% endtrans %}</a>
            </li>
            <li>
                <a href="#"
                   title="{% trans %}Submitter privileges{% endtrans %}"
                   data-ajax-dialog
                   data-title="{% trans %}Submitter privileges{% endtrans %}"
                   data-href="{{ url_for('.manage_submitter_edits', event) }}"
                   data-qtip-position="right">
                    {% trans %}Submitter privileges{% endtrans %}</a>
            </li>
        </ul>
    {%- endif -%}
    <div id="pub-switch" data-event-id="{{ event.id }}"></div>
{% endblock %}

{% block description %}
    {%- trans -%}
        Manage the contributions of the event from the list below or configure the <strong>contribution types</strong>
        and <strong>custom fields</strong> from the settings menu above.
    {%- endtrans -%}
{% endblock %}

{% block content %}
    <div class="list">
        <div class="toolbars space-after">
            <div class="toolbar">
                <button class="i-button icon-checkbox-checked arrow js-dropdown" data-toggle="dropdown"></button>
                <ul class="i-dropdown">
                    <li>
                        <a href="#" data-select-all="#contribution-list input:checkbox">{% trans 'Selection' %}All{% endtrans %}</a>
                    </li>
                    <li>
                        <a href="#" data-select-none="#contribution-list input:checkbox">{% trans 'Selection' %}None{% endtrans %}</a>
                    </li>
                </ul>
                <button class="i-button highlight icon-plus js-dialog-action hide-if-locked"
                        title="{% trans %}Add new contribution{% endtrans %}"
                        data-title="{% trans %}Add new contribution{% endtrans %}"
                        data-href="{{ url_for('.manage_create_contrib', event) }}"
                        data-update='{"html": "#contribution-list", "filter_statistics": "#filter-statistics"}'
                        data-ajax-dialog>
                    {%- trans %}New contribution{% endtrans -%}
                </button>
                <button class="i-button js-enable-if-checked icon-remove disabled hide-if-locked"
                        title="{% trans %}Remove{% endtrans %}"
                        data-method="POST"
                        data-href="{{ url_for('.manage_delete_contribs', event) }}"
                        data-params-selector="#contribution-list input[name=contribution_id]:checked"
                        data-confirm="{% trans %}Do you really want to delete the selected contributions?{% endtrans %}"
                        data-title="{% trans %}Confirm deletion{% endtrans %}"
                        data-update='{"html": "#contribution-list", "filter_statistics": "#filter-statistics"}'>
                    {%- trans %}Remove{% endtrans -%}
                </button>
                <div class="group">
                    <div id="email-authors-container"
                         class="i-button-wrapper"
                         data-event-id="{{ event.id }}"
                         data-object-context="contributions"
                         data-params-selector="#contribution-list input[name=contribution_id]:checked">
                    </div>
                    <div id="email-contrib-roles-container"
                         class="i-button-wrapper"
                         data-object-context="contributions"
                         data-id-selector="#contribution-list input[name=contribution_id]:checked"
                         data-metadata-url="{{ url_for('.api_email_contrib_roles_metadata', event) }}"
                         data-preview-url="{{ url_for('.api_email_contrib_roles_preview', event) }}"
                         data-send-url="{{ url_for('.api_email_contrib_roles_send', event) }}">
                    </div>
                </div>
                <button class="i-button icon-attachment js-enable-if-checked js-submit-form disabled"
                        data-href="{{ url_for('.material_package', event) }}">
                    {%- trans %}Material package{% endtrans -%}
                </button>
                <div class="group">
                    <button class="i-button js-enable-if-checked arrow disabled"
                            title="{% trans %}Export data{% endtrans %}"
                            data-toggle="dropdown">
                        {%- trans %}Export{% endtrans -%}
                    </button>
                    <ul class="i-dropdown">
                        {% if indico_config.LATEX_ENABLED %}
                            <li>
                                <a href="#" class="icon-file-pdf js-submit-form js-enable-if-checked disabled"
                                   data-href="{{ url_for('.contributions_pdf_export', event) }}">
                                    {%- trans %}PDF{% endtrans -%}
                                </a>
                            </li>
                        {% endif %}
                        <li>
                            <a href="#" class="icon-file-spreadsheet js-submit-form js-enable-if-checked disabled"
                               data-href="{{ url_for('.contributions_csv_export', event) }}">
                                {%- trans %}CSV{% endtrans -%}
                            </a>
                        </li>
                        <li>
                            <a href="#" class="icon-file-excel js-submit-form js-enable-if-checked disabled"
                               data-href="{{ url_for('.contributions_excel_export', event) }}">
                                {%- trans %}XLSX (Excel){% endtrans -%}
                            </a>
                        </li>
                        <li>
                            <a href="#" class="icon-file-css js-submit-form js-enable-if-checked disabled"
                               data-href="{{ url_for('.contributions_json_export', event) }}">JSON</a>
                        </li>
                        <li>
                            <a href="#" class="icon-file-text js-submit-form js-enable-if-checked disabled"
                               data-href="{{ url_for('.contributions_tex_export', event) }}">
                                {%- trans %}LaTeX{% endtrans -%}
                            </a>
                        </li>
                        <li>
                            <a href="#" class="icon-file-text js-enable-if-checked disabled"
                               data-href="{{ url_for('.contributions_tex_export_dialog', event) }}"
                               data-method="POST"
                               data-params-selector="#contribution-list input[name=contribution_id]:checked"
                               data-ajax-dialog>
                                {%- trans %}Book of Abstracts{% endtrans -%}
                            </a>
                        </li>
                    </ul>
                    <button class="i-button"
                            title="{% trans %}Import contributions from CSV file{% endtrans %}"
                            data-href="{{ url_for('.contributions_import', event) }}"
                            data-title="{% trans %}Import contributions from CSV File{% endtrans %}"
                            data-ajax-dialog>
                        {%- trans %}Import{% endtrans -%}
                    </button>
                </div>
                {{ template_hook('contribution-list-options', event=event) }}
                <button class="i-button js-enable-if-checked disabled"
                        data-title="{% trans %}Assign program codes{% endtrans %}"
                        data-href="{{ url_for('event_management.assign_program_codes_contributions', event) }}"
                        data-params-selector="#contribution-list input[name=contribution_id]:checked"
                        data-method="POST"
                        data-ajax-dialog
                        data-reload-after>
                    {%- trans %}Assign program codes{% endtrans -%}
                </button>
                <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" id="filter-statistics">
                    {{ render_filter_statistics(contribs|length, total_entries, total_duration) }}
                </div>
                <button class="i-button icon-settings js-dialog-action js-customize-list highlight"
                        data-href="{{ url_for('.customize_contrib_list', event) }}"
                        data-title="{% trans %}Contribution list configuration{% endtrans %}"
                        data-dialog-classes="list-filter-dialog"
                        data-update='{"html": "#contribution-list", "filter_statistics": "#filter-statistics"}'
                        data-ajax-dialog>
                    {%- trans %}Customize list{% endtrans -%}
                </button>
                <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.{% endtrans %}"></button>
                <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="contribution-list">
            {{ render_contrib_list(event, total_entries, contribs, sessions, tracks, registered_persons, static_columns, dynamic_columns, has_types) }}
        </div>
        <div id="filter-placeholder"></div>
    </div>
    <script>
        {% if selected_entry %}
            $('#search-input').val('#{{ selected_entry }}').trigger('change');
        {% endif %}

        setupAuthorsListButton('#email-authors-container');
        setupEmailContribAbstractRoles('#email-contrib-roles-container');
        {% if event.can_manage(session.user) %}
            setupContributionConfig();
        {% endif %}
        setupContributionList({
            createSessionURL: {{ url_for('sessions.create_session', event) | tojson }},
            createTrackURL: {{ url_for('tracks.create_track', event) | tojson }},
            timetableRESTURL: {{ url_for('timetable.timetable_rest', event, _method='POST') | tojson }}
        });
    </script>
{% endblock %}
