digitalfabrik/integreat-cms

View on GitHub
integreat_cms/cms/templates/events/event_list.html

Summary

Maintainability
Test Coverage
{% extends "_base.html" %}
{% load i18n %}
{% load static %}
{% load content_filters %}
{% block content %}
    {% with filter_form.filters_visible as filters_visible %}
        <div class="table-header">
            <div class="flex flex-wrap justify-between">
                <h1 class="heading">
                    {% translate "Events" %}
                </h1>
                <a href="{% url 'events_archived' region_slug=request.region.slug language_slug=language.slug %}"
                   class="font-bold text-sm text-gray-800 flex items-center gap-1 pb-2 hover:underline">
                    <span>
                        <i icon-name="archive" class="align-top h-5"></i>
                        {% translate "Archived events" %}
                        ({{ archived_count }})
                    </span>
                </a>
            </div>
            <div class="flex flex-wrap justify-between gap-4">
                <div class="flex flex-wrap gap-4">
                    {% include "generic_language_switcher.html" with target="events" %}
                    {% include "_search_input.html" with object_type="event" related_form="event-filter-form" %}
                </div>
                <div class="flex flex-wrap gap-4">
                    <button id="filter-toggle" class="btn btn-ghost">
                        <span class="filter-toggle-text {% if filters_visible %}hidden{% endif %}">{% translate "Show filters" %}</span>
                        <span class="filter-toggle-text {% if not filters_visible %}hidden{% endif %}">{% translate "Hide filters" %}</span>
                    </button>
                    {% if request.region.default_language == language and perms.cms.change_event %}
                        <a href="{% url 'new_event' region_slug=request.region.slug language_slug=language.slug %}"
                           class="btn">
                            {% translate "Create event" %}
                        </a>
                    {% elif perms.cms.change_event %}
                        {% blocktranslate trimmed asvar disabled_button_title with request.region.default_language.translated_name as default_language %}
                            You can only create events in the default language ({{ default_language }}).
                        {% endblocktranslate %}
                        <button title="{{ disabled_button_title }}" class="btn" disabled>
                            {% translate "Create event" %}
                        </button>
                    {% endif %}
                </div>
            </div>
        </div>
        <div id="filter-form-container"
             class="{% if not filters_visible %}hidden{% endif %} w-full mt-4 rounded border border-solid border-gray-200 shadow bg-white">
            {% include "events/_event_filter_form.html" %}
        </div>
    {% endwith %}
    <div class="table-listing">
        <form id="bulk-action-form" method="post">
            {% csrf_token %}
        </form>
        <table id="event-list"
               class="w-full mt-4 rounded border border-solid border-gray-200 shadow bg-white">
            <thead>
                <tr class="border-b border-solid border-gray-200">
                    <th class="py-3 pl-4 min">
                        <input form="bulk-action-form" type="checkbox" id="bulk-select-all" />
                    </th>
                    <th class="text-sm text-left uppercase py-3 pl-2 pr-2">
                        {% translate "Title in" %} {{ language.translated_name }}
                    </th>
                    {% get_current_language as LANGUAGE_CODE %}
                    {% get_language LANGUAGE_CODE as backend_language %}
                    {% if backend_language and backend_language != language %}
                        <th class="text-sm text-left uppercase py-3 pr-2">
                            {% translate "Title in" %} {{ backend_language.translated_name }}
                        </th>
                    {% endif %}
                    <th class="text-sm text-left uppercase py-3 pr-2">
                        <div class="lang-grid flags whitespace-nowrap">
                            {% spaceless %}
                                {% for lang in languages %}
                                    {% if lang != request.region.default_language %}
                                        <a href="{% url 'events' region_slug=request.region.slug language_slug=lang.slug %}">
                                            <span class="fp fp-rounded fp-{{ lang.primary_country_code }}"
                                                  title="{{ lang.translated_name }}"></span>
                                        </a>
                                    {% endif %}
                                {% endfor %}
                            {% endspaceless %}
                        </div>
                    </th>
                    <th class="text-sm text-left uppercase py-3 pr-2">
                        {% translate "Publication status" %}
                    </th>
                    <th class="text-sm text-left uppercase py-3 pr-2">
                        {% translate "Event location" %}
                    </th>
                    <th class="text-sm text-left uppercase py-3 pr-2">
                        {% translate "Start" %}
                    </th>
                    <th class="text-sm text-left uppercase py-3 pr-2">
                        {% translate "End" %}
                    </th>
                    <th class="text-sm text-left uppercase py-3 pr-2">
                        {% translate "Recurrence" %}
                    </th>
                    <th class="text-sm text-left uppercase py-3 pr-2">
                        {% translate "External calendar" %}
                    </th>
                    <th class="text-sm text-right uppercase py-3 pr-4 min">
                        {% translate "Options" %}
                    </th>
                </tr>
            </thead>
            <tbody>
                {% if events %}
                    {% for event in events %}
                        {% get_translation event language.slug as event_translation %}
                        {% include "events/event_list_row.html" with event=event event_translation=event_translation %}
                    {% endfor %}
                {% else %}
                    <tr>
                        <td colspan="8" class="pl-4 pr-2 py-3">
                            {% if filter_form.has_changed %}
                                {% translate "No events found with these filters." %}
                            {% else %}
                                {% translate "No upcoming events available." %}
                            {% endif %}
                        </td>
                    </tr>
                {% endif %}
            </tbody>
        </table>
    </div>
    {% if events %}
        <div class="pt-2 px-2">
            <div class="inline">
                <span class="text-gray-800 font-bold" data-list-selection-count>0</span> <span class="text-gray-600">{% translate "Events selected" %}</span>
            </div>
        </div>
    {% endif %}
    {% if perms.cms.change_event %}
        <div class="flex flex-wrap gap-2 mt-4">
            <select id="bulk-action" class="w-auto max-w-full">
                <option>
                    {% translate "Select bulk action" %}
                </option>
                <option data-bulk-action="{% url 'bulk_archive_events' region_slug=request.region.slug language_slug=language.slug %}">
                    {% translate "Archive events" %}
                </option>
                {% if request.user.is_superuser or request.user.is_staff %}
                    {% translate "events" as content_type %}
                    <option data-bulk-action="{% url 'publish_multiple_events' region_slug=request.region.slug language_slug=language.slug %}">
                        {% blocktranslate trimmed %}
                            Publish {{ content_type }}
                        {% endblocktranslate %}
                    </option>
                    <option data-bulk-action="{% url 'draft_multiple_events' region_slug=request.region.slug language_slug=language.slug %}">
                        {% blocktranslate trimmed %}
                            Draft {{ content_type }}
                        {% endblocktranslate %}
                    </option>
                {% endif %}
                {% if MT_PERMITTED %}
                    {% translate "events" as content_type %}
                    {% if MT_PROVIDER %}
                        <option id="machine-translation-option"
                                data-mt-provider="{{ MT_PROVIDER.name }}"
                                data-bulk-action="{% url 'machine_translation_events' region_slug=request.region.slug language_slug=language.slug %}"
                                data-url="{% url 'word_count' region_slug=request.region.slug language_slug=language.slug model_type="event" %}">
                            {% blocktranslate trimmed with provider=MT_PROVIDER.name %}
                                Machine translate {{ content_type }} via {{ provider }} to {{ language }}
                            {% endblocktranslate %}
                        </option>
                    {% else %}
                        <option disabled
                                title="{% translate "This language is not supported by any available machine translation provider." %}">
                            {% blocktranslate trimmed %}
                                Machine translate {{ content_type }} to {{ language }}
                            {% endblocktranslate %}
                        </option>
                    {% endif %}
                {% endif %}
            </select>
            <button form="bulk-action-form" id="bulk-action-execute" class="btn" disabled>
                {% translate "Execute" %}
            </button>
        </div>
    {% endif %}
    {% include "../generic_confirmation_dialog.html" %}
    {% include "../_machine_translation_overlay.html" %}
    {% url "events" as url %}
    {% include "pagination.html" with chunk=events %}
{% endblock content %}