{% extends "base.html" %}

{% block title %}{{ _('ELN Import') }} #{{ eln_import.id }} — {{ service_name }}{% endblock %}

{% block content %}
  <h1>{{ _('ELN Import') }} #{{ eln_import.id }}</h1>
  <dl class="dl-horizontal">
    <dt>{{ _('Uploaded by') }}</dt>
    <dd>{{ user_reference(eln_import.user_id) }}</dd>
    <dt>{{ _('Uploaded at') }}</dt>
    <dd>{{ eln_import.upload_utc_datetime | babel_format_datetime }}</dd>
    <dt>{{ _('Imported at') }}</dt>
    <dd>{% if eln_import.import_utc_datetime %}{{ eln_import.import_utc_datetime | babel_format_datetime }}{% else %}&mdash;{% endif %}</dd>
    {% if eln_import.imported %}
    <dt>{{ _('Objects') }}</dt>
    <dd>
      {% if imported_objects %}
        <ul style="padding-left: 1em; margin-bottom: 0">
        {% for object in imported_objects %}
          <li>
            <a href="{{ url_for('.object', object_id=object.id) }}">{{ object.name | get_translated_text(default=_('Unnamed Object')) }}</a>
            {{ import_information_symbol(object) }}
          </li>
        {% endfor %}
        </ul>
      {% else %}
        &mdash;
      {% endif %}
    </dd>
    <dt>{{ _('Users') }}</dt>
    <dd>
      {% if imported_users %}
        <ul style="padding-left: 1em">
        {% for user in imported_users %}
          <li>
            <a href="{{ url_for('.user_profile', user_id=user.id) }}">{{ user.name }}</a>
            {{ import_information_symbol(user) }}
          </li>
        {% endfor %}
        </ul>
      {% else %}
        &mdash;
      {% endif %}
    </dd>
    <dt>{{ _('Federated Identities') }}</dt>
    <dd>
        {% if fed_identities %}
          <ul style="padding-left: 1em;">
              {% for user_id, identities in fed_identities.items() %}
                <li>
                  {% set user = identities[0][1].user %}
                  <a href="{{ url_for('.user_profile', user_id=user.id) }}">{{ user.name }} (#{{ user.id }})</a>
                  <ul style="padding-left: 1em;">
                    <table>
                      {% for form, identity in identities %}
                        <tr>
                          <td class="column-space">
                            <li>
                              <span {% if not identity.active %} class="text-muted" {% endif %}>
                                <a href="{{ url_for('.user_profile', user_id=identity.local_fed_user.id) }}">{{ identity.local_fed_user.name }}</a>
                                {{ import_information_symbol(identity.local_fed_user) }}
                              </span>
                            </li>
                          </td>
                          {% if form is not none %}
                          <form action="{{ url_for('.modify_eln_identity', eln_import_id=eln_import.id) }}" method="post" style="display: inline; margin: 0; padding: 0;">
                            {{ form.csrf_token }}
                            {% set enable_revoke_title = _('Revokes the federated identity with %(username)s.', username=identity.local_fed_user.name) if identity.active else _('Enables the federated identity with %(username)s.', username=identity.local_fed_user.name) %}
                            <input type="hidden" name="{{ form.eln_user_id.name }}" value="{{ form.eln_user_id.data }}">
                            <td class="column-space">
                              <button type="submit" name="{{ form.type.name }}" value="{% if identity.active %}revoke{% else %}enable{% endif %}" class="btn btn-xs btn-default" data-toggle="tooltip" title="{{ enable_revoke_title }}">{{ _('Revoke') if identity.active else _('Enable') }}</button>
                            </td>
                            <td>
                              <button type="submit" name="{{ form.type.name }}" value="remove" class="btn btn-xs btn-danger" data-toggle="tooltip" title="{{ _('Removes the federated identity with %(username)s permanently.', username=identity.local_fed_user.name) }}">{{ _('Remove') }}</button>
                            </td>
                          </form>
                          {% endif %}
                        </tr>
                      {% endfor %}
                    </table>
                  </ul>
                </li>
              {% endfor %}
          </ul>
        {% else %}
          &mdash;
        {% endif %}
    </dd>
    <dt>{{ _('Signed by') }}</dt>
    <dd>
      {% if eln_import.signed_by != None %}
        <a href="{{ eln_import.signed_by }}">{{ eln_import.signed_by }}</a>
      {% else %}
        &mdash;
      {% endif %}
    </dd>
    {% endif %}
  </dl>
{% endblock %}
