{% extends "base.html" %}

{% block title %}{{ _('Objects') }} — {{ service_name }}{% endblock %}

{% block stylesheets %}
  {{ super() }}
  <link rel="stylesheet" href="{{ fingerprinted_static('bootstrap-select/css/bootstrap-select.min.css') }}" />
{% endblock %}

{% block template_values %}
  {% do set_template_value("objects_allowed_to_select", objects_allowed_to_select) %}
  {% do set_template_value("translations.select_at_least_one_object", _('You have to select at least one object.')) %}
  {% do set_template_value("translations.you_do_not_have_write_permissions", _('You do not have write permissions for at least one object.')) %}
  {% if edit_location %}
    {% do set_template_value("translations.you_have_to_select_a_location_or_responsible_user", _('You have to select a location or a responsible user.')) %}
    {% do set_template_value("translations.you_have_unallowed_values_in_red_marked_fields", _('You have unallowed values in the red marked fields.')) %}
  {% endif %}
  {% if edit_permissions %}
    {% do set_template_value("current_permissions_special_groups", current_permissions_special_groups) %}
    {% do set_template_value("current_permissions_normal_entities", current_permissions_normal_entities) %}
    {% do set_template_value("translations.you_have_to_select_a_target_type", _('You have to select a target type.')) %}
    {% do set_template_value("translations.you_have_to_select_a_basic_group", _('You have to select a group.')) %}
    {% do set_template_value("translations.you_have_to_select_a_project_group", _('You have to select a project group.')) %}
    {% do set_template_value("translations.you_have_to_select_a_user", _('You have to select a user.')) %}
    {% do set_template_value("translations.you_have_to_select_how_to_update", _('You have to select how you want to update the permissions.')) %}
    {% do set_template_value("translations.you_have_to_select_a_permission", _('You have to select a permission.')) %}
    {% do set_template_value("translations.you_have_selected_write_grant_permissions_for_special_group", _('You have selected write/grant permissions for a special group.')) %}
  {% endif %}
  {% if generate_labels %}
    {% set page_sizes = {} %}
    {% for paper_format in PAGE_SIZES %}
      {% do page_sizes.update({
        paper_format: [
          PAGE_SIZES[paper_format][0],
          PAGE_SIZES[paper_format][1]
        ]
      }) %}
    {% endfor %}
    {% do set_template_value("page_sizes", page_sizes) %}
    {% do set_template_value("horizontal_label_margin", HORIZONTAL_LABEL_MARGIN) %}
    {% do set_template_value("vertical_label_margin", VERTICAL_LABEL_MARGIN) %}
    {% do set_template_value("generate_labels_form.center_qr_ghs.name", generate_labels_form.center_qr_ghs.name) %}
    {% do set_template_value("translations.select_a_paper_format", _("Select a Paper Format")) %}
    {% do set_template_value("translations.quantity_must_be_greater_than_0", _('The quantity must be an integer value greater than 0.')) %}
    {% do set_template_value("translations.width_must_be_between_min_and_max", _("The width must be a number between {minWidth} and {maxWidth}.")) %}
    {% do set_template_value("translations.minimum_height_must_be_between_0_and_placeholder", _("The minimum height must be a number between 0 and {maxHeight}.")) %}
    {% do set_template_value("translations.minimum_width_must_be_greater_or_equal_to_0", _("The minimum width must be a number greater or equal to 0.")) %}
  {% endif %}

  {{ super() }}
{% endblock %}

{% block scripts %}
  {{ super() }}
  <script src="{{ fingerprinted_static('bootstrap-select/js/bootstrap-select.min.js') }}"></script>
  <script src="{{ fingerprinted_static('plotly/js/plotly-latest.min.js') }}"></script>
  <script src="{{ fingerprinted_static('sampledb/js/treepicker.js') }}" type="module"></script>
  {% if get_user_language(current_user).lang_code == 'de' %}
    <script src="{{ fingerprinted_static('plotly/js/plotly-locale-de.js') }}"></script>
  {% endif %}
  <script src="{{ fingerprinted_static('sampledb/js/timeseries.js') }}" type="module"></script>
  <script src="{{ fingerprinted_static('sampledb/js/view-object-data.js') }}" type="module"></script>
  <script src="{{ fingerprinted_static('sampledb/js/markdown_image_viewer.js') }}" type="module"></script>
  <script src="{{ fingerprinted_static('sampledb/js/page/objects/filters.js') }}" type="module"></script>
  {% if edit_location %}
    <script src="{{ fingerprinted_static('sampledb/js/page/objects/multiselect-edit-location.js') }}" type="module"></script>
  {% elif create_from_objects %}
    <script src="{{ fingerprinted_static('sampledb/js/page/objects/multiselect-base.js') }}" type="module"></script>
  {% elif generate_labels %}
    <script src="{{ fingerprinted_static('sampledb/js/page/objects/multiselect-generate-labels.js') }}" type="module"></script>
  {% elif edit_permissions %}
    <script src="{{ fingerprinted_static('sampledb/js/page/objects/multiselect-edit-permissions.js') }}" type="module"></script>
  {% endif %}
{% endblock %}

{% block content %}
  {% if search_notes is defined %}
  {% for category, note, start, end in search_notes %}
    {% if category == "error" %}
      {% set alert_class="alert-danger" %}
    {% elif category == "warning" %}
      {% set alert_class="alert-warning" %}
    {% else %}
      {% set alert_class="alert-info" %}
    {% endif %}
    <div class="alert {{ alert_class }} alert-dismissible" role="alert">
      <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      {% if category == "error" %}
        <strong>{{ _('Error:') }}</strong>
      {% elif category == "warning" %}
        <strong>{{ _('Warning:') }}</strong>
      {% else %}
        <strong>{{ _('Note:') }}</strong>
      {% endif %}
      {{ note }}
      {% if search_query and end is none %}
        {% set end = search_query | length %}
      {% endif %}
      {% if search_query and start != end %}
        <br />
        <strong>{{ _('Query:') }}</strong>
        <span class="search-error-full">
          {{ search_query[:start] }}<span class="search-error">{{ search_query[start:end] }}</span>{{ search_query[end:] }}
        </span>
      {% endif %}
    </div>
  {% endfor %}
  {% endif %}
  {% if not advanced_search_had_error %}
  {% if search_tree %}
    {% macro render_search_tree(search_tree, depth=0) -%}
      {% if depth > 100 %}
        ...
      {% else %}
      {% if search_tree.input_text %}
      {{ search_tree.input_text }}
      {% elif search_tree | length  == 2 %}
        <span style="display:flex;flex-direction:row;justify-content: center; align-items:center; background-color: rgba(0, 128, 255, 0.075); border-radius:8px;">
          {% if search_tree[0].operator %}
          <span style="margin:5px; font-weight: 800;">{{ search_tree[0].operator }}</span>
          {% else %}
          <span style="margin:5px 0 5px 5px;">{{ search_tree[0].input_text }}</span>
          {% endif %}
          {% if search_tree[1].input_text %}
            <span style="margin:5px; ">{{ search_tree[1].input_text }}</span>
          {% else %}
            <span style="margin:5px; border:1px solid rgba(0, 64, 128, 0.5); border-radius:8px;">{{ render_search_tree(search_tree[1], depth=depth + 1) }}</span>
          {% endif %}
        </span>
      {% elif search_tree | length  == 3 %}
        <span style="display:flex;flex-direction:row;justify-content: center; align-items:center; background-color: rgba(0, 128, 255, 0.075); border-radius:8px;">
          {% if search_tree[0].input_text %}
            <span style="margin:5px; ">{{ search_tree[0].input_text }}</span>
          {% else %}
            <div style="margin:5px; border:1px solid rgba(0, 64, 128, 0.5); border-radius:8px;">{{ render_search_tree(search_tree[0], depth=depth + 1) }}</div>
          {% endif %}
          <span style="margin:5px; font-weight: 800; ">{{ search_tree[1].operator }}</span>
          {% if search_tree[2].input_text %}
            <span style="margin:5px; ">{{ search_tree[2].input_text }}</span>
          {% else %}
            <span style="margin:5px; border:1px solid rgba(0, 64, 128, 0.5); border-radius:8px;">{{ render_search_tree(search_tree[2], depth=depth + 1) }}</span>
          {% endif %}
        </span>
      {% endif %}
      {% endif %}
    {%- endmacro %}
    {% if search_tree.input_text %}
      <span style="display:flex; flex-direction:row;justify-content: center;">
        <span style="padding:5px; border:1px solid rgba(0, 64, 128, 0.5); border-radius:8px; background-color: rgba(0, 128, 255, 0.075)">{{ search_tree.input_text }}</span>
      </span>
    {% else %}
      <label style="display:flex; flex-direction:row;justify-content: center; font-weight: normal;" id="search-tree" for="input-search">
        <span style="margin:5px; border:1px solid rgba(0, 64, 128, 0.5); border-radius:8px;">{{ render_search_tree(search_tree) }}</span>
      </label>
    {% endif %}
  {% endif %}
  {% endif %}

  {% if objects or not search_notes %}
    <h1>{{ object_name_plural }}</h1>
    {% if filter_action_type_infos or filter_action_infos or filter_instrument_infos or filter_location_infos or filter_related_user_infos or filter_user_permissions_info or filter_all_users_permissions or filter_anonymous_permissions or filter_group_permissions_info or filter_project_permissions_info or filter_doi_info or filter_origins_info %}
      <ul>
      {% if filter_action_type_infos %}
        <li>
          {% if filter_action_type_infos | length == 1 %}
            {{ _('for action type:') }}
          {% else %}
            {{ _('for action types:') }}
          {% endif %}
          {% for action_type_info in filter_action_type_infos %}
            <a href="{{ action_type_info.url }}">{{ action_type_info.name }}</a>{% if action_type_info.component_name %}&nbsp;<i class="fa fa-share-alt" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="#{{ action_type_info.fed_id }} @ {{ action_type_info.component_name }}"></i>{% endif %}{% if loop.index + 1 < filter_action_type_infos | length %},{% elif loop.index + 1 == filter_action_type_infos | length %} {{ _('or') }} {% endif %}
          {% endfor %}
        </li>
      {% endif %}
      {% if filter_action_infos %}
        <li>
          {% if filter_action_infos | length == 1 %}
            {{ _('for action:') }}
          {% else %}
            {{ _('for actions:') }}
          {% endif %}
          {% for action_info in filter_action_infos %}
            {% if action_info.instrument %}
              <a href="{{ url_for('.instrument', instrument_id=action_info.instrument.id) }}">{{ action_info.instrument.name | get_translated_text(default=_('Unnamed Instrument')) }}</a> —{% endif %}
            {% if action_info.user %}
              {{ user_reference(action_info.user) }} /
            {% endif %}
            <a href="{{ action_info.url }}">{{ action_info.name }}</a>{% if action_info.component_name %}&nbsp;{% if action_info.fed_url %}<a href="{{ action_info.fed_url }}">{% endif %}<i class="fa fa-share-alt" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="#{{ action_info.fed_id }} @ {{ action_info.component_name }}"></i>{% if action_info.fed_url %}</a>{% endif %}{% endif %}{% if loop.index + 1 < filter_action_infos | length %},{% elif loop.index + 1 == filter_action_infos | length %} {{ _('or') }} {% endif %}
          {% endfor %}
        </li>
      {% endif %}
      {% if filter_instrument_infos %}
        <li>
          {% if filter_instrument_infos | length == 1 %}
            {{ _('for instrument:') }}
          {% else %}
            {{ _('for instruments:') }}
          {% endif %}
          {% for instrument_info in filter_instrument_infos %}
            <a href="{{ instrument_info.url }}">{{ instrument_info.name }}</a>{% if instrument_info.component_name %}&nbsp;{% if instrument_info.fed_url %}<a href="{{ instrument_info.fed_url }}">{% endif %}<i class="fa fa-share-alt" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="#{{ instrument_info.fed_id }} @ {{ instrument_info.component_name }}"></i>{% if instrument_info.fed_url %}</a>{% endif %}{% endif %}{% if loop.index + 1 < filter_instrument_infos | length %},{% elif loop.index + 1 == filter_instrument_infos | length %} {{ _('or') }} {% endif %}
          {% endfor %}
        </li>
      {% endif %}
      {% if filter_location_infos %}
        <li>
          {% if filter_location_infos | length == 1 %}
            {{ _('for location:') }}
          {% else %}
            {{ _('for locations:') }}
          {% endif %}
          {% for location_info in filter_location_infos %}
            <a href="{{ location_info.url }}">{{ location_info.name }}</a>{% if location_info.component_name %}&nbsp;<i class="fa fa-share-alt" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="#{{ location_info.fed_id }} @ {{ location_info.component_name }}"></i>{% endif %}{% if loop.index + 1 < filter_location_infos | length %},{% elif loop.index + 1 == filter_location_infos | length %} {{ _('or') }} {% endif %}
          {% endfor %}
        </li>
      {% endif %}
      {% if filter_doi_info %}
        <li>{{ _('for publication:') }} <a href="http://doi.org/{{ filter_doi_info.doi | urlencode }}">{% if filter_doi_info.title %}{{ filter_doi_info.title }}{% else %}{{ _('Untitled publication') }}{% endif %} (DOI: {{ filter_doi_info.doi }})</a></li>
      {% endif %}
      {% if filter_related_user_infos %}
        <li>
        {{ _('with activity by user:') }}
        {% for filter_related_user_info in filter_related_user_infos %}
          {%- if loop.last and not loop.first %} {{ _('or') }} {% elif not loop.first %}, {% endif %}
          <a href="{{ filter_related_user_info.url }}">{{ filter_related_user_info.name }}</a>{% if filter_related_user_info.component_name %}&nbsp;<i class="fa fa-share-alt" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="#{{ filter_related_user_info.fed_id }} @ {{ filter_related_user_info.component_name }}"></i>{% elif filter_related_user_info.eln_import_id %}&nbsp;<a href="{{ url_for('.eln_import', eln_import_id=filter_related_user_info.eln_import_id) }}" class="import-information-symbol"><i class="fa fa-file-archive-o" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="{{ filter_related_user_info.eln_object_id }} @ {{ _('.eln file') }} #{{ filter_related_user_info.eln_import_id }}"></i></a>{% endif -%}
        {% endfor %}
        </li>
      {% endif %}
      {% if filter_anonymous_permissions %}
        <li>
          {{ _('with %(permissions)s permissions for anonymous users', permissions=_(filter_anonymous_permissions.name.title())) }}
        </li>
      {% endif %}
      {% if filter_all_users_permissions %}
        <li>
          {{ _('with %(permissions)s permissions for all signed-in users', permissions=_(filter_all_users_permissions.name.title())) }}
        </li>
      {% endif %}
      {% if filter_user_permissions_info %}
        <li>
        {% if filter_user_permissions_info.url %}
          {{ _('with %(permissions)s permissions for user:', permissions=filter_user_permissions_info.permissions) }}
          <a href="{{ filter_user_permissions_info.url }}">{{ filter_user_permissions_info.name }}</a>{% if filter_user_permissions_info.component_name %}&nbsp;<i class="fa fa-share-alt" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="#{{ filter_user_permissions_info.fed_id }} @ {{ filter_user_permissions_info.component_name }}"></i>{% endif %}
        {% else %}
          {{ _('with %(permissions)s permissions', permissions=filter_user_permissions_info.permissions) }}
        {% endif %}
        </li>
      {% endif %}
      {% if filter_group_permissions_info %}
        <li>
          {{ _('with %(permissions)s permissions for basic group:', permissions=filter_group_permissions_info.permissions) }}
          <a href="{{ filter_group_permissions_info.url }}">{{ filter_group_permissions_info.name }}</a>
        </li>
      {% endif %}
      {% if filter_project_permissions_info %}
        <li>
          {{ _('with %(permissions)s permissions for project group:', permissions=filter_project_permissions_info.permissions) }}
          <a href="{{ filter_project_permissions_info.url }}">{{ filter_project_permissions_info.name }}</a>
        </li>
      {% endif %}
      {% if filter_origins_info %}
        <li>
        {% if filter_origins_info.local and not filter_origins_info.components %}
          {{ _('from this database') }}
        {% else %}
          {% if filter_origins_info.local %}
            {{ _('from this database and from') }}
          {% else %}
            {{ _('from') }}
          {% endif %}
          {% for component in filter_origins_info.components -%}
            {% if loop.last and not loop.first %}
              {{ _('and') }}
            {%- elif not loop.first -%}
              ,
            {% endif %}
            <a href="{{ url_for('.component', component_id=component.id) }}">{{ component.get_name() }}</a>
          {%- endfor %}
        {% endif %}
        </li>
      {% endif %}
      </ul>
    {% endif %}
  {% endif %}

  <button type="button" class="btn btn-default" data-toggle="modal" data-target="#optionsModal" style="margin-bottom: 10px">
    {{ _('Options') }}
  </button>

  <div class="modal fade" id="optionsModal" tabindex="-1" role="dialog" aria-labelledby="optionsModalLabel">
    <div class="modal-dialog" role="document">
      <form method="get" class="form">
        {% for key in request.args %}
          {% if key not in ['object_list_options', 'display_properties', 'creation_info', 'last_edit_info', 'action_info', 'other_databases_info', 'location_info'] %}
            {% for value in request.args.getlist(key) %}
              <input type="hidden" name="{{ key }}" value="{{ value }}" />
            {% endfor %}
          {% endif %}
        {% endfor %}
        <input type="hidden" name="object_list_options" value="" />
        <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" id="optionsModalLabel">{{ _('Options') }}</h4>
          </div>
          <div class="modal-body">
            <div class="form-group">
              <label class="control-label" for="select_display_properties">
                {{ _('Show additional properties') }}
              </label>
              <select class="selectpicker form-control" multiple="multiple" name="display_properties" data-width="100%" id="select_display_properties" data-live-search="true" data-none-selected-text="{{ _('No additional properties') }}">
                {% for property_name in search_paths | sort %}
                  <option value="{{ property_name }}" {% if display_properties and property_name in display_properties %}selected="selected"{% endif %}>{{ property_name }} – {{ search_paths[property_name]['titles'] | join(', ') }}</option>
                {% endfor %}
              </select>
            </div>
            <div class="form-group">
              <label class="control-label">
                {{ _('Show creation information') }}
              </label>
              <div>
                <label style="font-weight: normal">
                  <input type="checkbox" {% if 'date' in creation_info %}checked="checked"{% endif %} name="creation_info" value="date" /> {{ _('Show Date') }}
                </label>
              </div>
              <div>
                <label style="font-weight: normal">
                  <input type="checkbox" {% if 'user' in creation_info %}checked="checked"{% endif %} name="creation_info" value="user" /> {{ _('Show User') }}
                </label>
              </div>
            </div>
            <div class="form-group">
              <label class="control-label">
                {{ _('Show last edit information') }}
              </label>
              <div>
                <label style="font-weight: normal">
                  <input type="checkbox" {% if 'date' in last_edit_info %}checked="checked"{% endif %} name="last_edit_info" value="date" /> {{ _('Show Date') }}
                </label>
              </div>
              <div>
                <label style="font-weight: normal">
                  <input type="checkbox" {% if 'user' in last_edit_info %}checked="checked"{% endif %} name="last_edit_info" value="user" /> {{ _('Show User') }}
                </label>
              </div>
            </div>
            {% if config['FEDERATION_UUID'] %}
            <div class="form-group">
              <label class="control-label">
                {{ _('Show Other Database information') }}
              </label>
              <div>
                <label style="font-weight: normal">
                  <input type="checkbox" {% if other_databases_info %}checked="checked"{% endif %} name="other_databases_info" value="other_databases_info" /> {{ _('Show Other Databases') }}
                </label>
              </div>
            </div>
            {% endif %}
            <div class="form-group">
              <label class="control-label">
                {{ _('Show Action information') }}
              </label>
              {% if not config['DISABLE_INSTRUMENTS'] %}
              <div>
                <label style="font-weight: normal">
                  <input type="checkbox" {% if 'instrument' in action_info %}checked="checked"{% endif %} name="action_info" value="instrument" /> {{ _('Show Instrument') }}
                </label>
              </div>
              {% endif %}
              <div>
              <label style="font-weight: normal">
                <input type="checkbox" {% if 'action' in action_info %}checked="checked"{% endif %} name="action_info" value="action" /> {{ _('Show Action') }}
              </label>
              </div>
            </div>
            <div class="form-group">
              <label class="control-label">
                {{ _('Show Location and Responsibility information') }}
              </label>
              <div>
                <label style="font-weight: normal">
                  <input type="checkbox" {% if 'location' in location_info %}checked="checked"{% endif %} name="location_info" value="location" /> {{ _('Show Location') }}
                </label>
              </div>
              <div>
              <label style="font-weight: normal">
                <input type="checkbox" {% if 'responsible_user' in location_info %}checked="checked"{% endif %} name="location_info" value="responsible_user" /> {{ _('Show Responsible User') }}
              </label>
              </div>
            </div>
            <div class="form-group">
              <label class="control-label">
                {{ _('Show Topics') }}
              </label>
              <div>
                <label style="font-weight: normal">
                  <input type="checkbox" {% if 'topics' in topic_info %}checked="checked"{% endif %} name="topic_info" value="topics" /> {{ _('Show Topics') }}
                </label>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="submit" class="btn btn-default" name="save_default_options" formmethod="post">{{ _('Save') }}</button>
            <button type="submit" class="btn btn-default" name="clear_default_options" formmethod="post">{{ _('Clear') }}</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">{{ _('Close') }}</button>
            <button type="submit" class="btn btn-primary">{{ _('Apply') }}</button>
          </div>
        </div>
      </form>
    </div>
  </div>


  {% if show_filters %}
  <button type="button" class="btn btn-default" data-toggle="modal" data-target="#filtersModal" style="margin-bottom: 10px">
    {{ _('Filters') }}
  </button>

  <div class="modal fade" id="filtersModal" tabindex="-1" role="dialog" aria-labelledby="filtersModalLabel">
    <div class="modal-dialog" role="document">
      <form method="get" class="form">
        {% for key in request.args %}
          {% if key not in ['object_list_filters', 'action_type_ids', 'action_ids', 'instrument_ids', 'user', 'user_permissions', 'all_users_permissions', 'anonymous_permissions', 'location_ids', 't', 'action', 'location', 'offset', 'doi', 'origins', 'related_user_ids', 'related_user'] %}
            {% for value in request.args.getlist(key) %}
              <input type="hidden" name="{{ key }}" value="{{ value }}" />
            {% endfor %}
          {% endif %}
        {% endfor %}
        <input type="hidden" name="object_list_filters" value="" />
        <input type="hidden" name="user" value="{{ current_user.id }}" />
        <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" id="filtersModalLabel">{{ _('Filters') }}</h4>
          </div>
          <div class="modal-body">
            <div class="form-group">
              <label class="control-label" for="filter_related_user_ids">
                {{ _('Filter by User Activity') }}
              </label>
              <select class="selectpicker form-control" name="related_user_ids" id="filter_related_user_ids" multiple="multiple" data-width="100%" data-none-selected-text="{{ _('All users') }}" data-live-search="on">
                {% for user in all_users %}
                  <option value="{{ user.id }}" {% if filter_related_user_ids and user.id in filter_related_user_ids %}selected="selected"{% endif %}>{{ user.get_name() }}</option>
                {% endfor %}
              </select>
            </div>
            <div class="form-group">
              <label class="control-label" for="filter_permissions">
                {{ _('Filter by Permissions') }}
              </label>
              <select class="selectpicker form-control" name="user_permissions" id="filter_permissions" data-width="100%">
                {% for permissions in [Permissions.READ, Permissions.WRITE, Permissions.GRANT] %}
                  <option value="{{ permissions.name.lower() }}" {% if permissions == filter_user_permissions or (permissions == Permissions.READ and filter_user_permissions is none) %}selected="selected"{% endif %}>{{ _(permissions.name.title()) }}</option>
                {% endfor %}
              </select>
            </div>
            <div class="form-group">
              <label class="control-label" for="filter_all_users_permissions">
                {{ _('Filter by Permissions for All Signed-In Users') }}
              </label>
              <select class="selectpicker form-control" name="all_users_permissions" id="filter_all_users_permissions" data-width="100%">
                <option value="" {% if filter_all_users_permissions is none %}selected="selected"{% endif %}>&mdash;</option>
                {% for permissions in [Permissions.READ] %}
                  <option value="{{ permissions.name.lower() }}" {% if permissions == filter_all_users_permissions %}selected="selected"{% endif %}>{{ _(permissions.name.title()) }}</option>
                {% endfor %}
              </select>
            </div>
            {% if config['ENABLE_ANONYMOUS_USERS'] %}
            <div class="form-group">
              <label class="control-label" for="filter_anonymous_permissions">
                {{ _('Filter by Permissions for Anonymous Users') }}
              </label>
              <select class="selectpicker form-control" name="anonymous_permissions" id="filter_anonymous_permissions" data-width="100%">
                <option value="" {% if filter_anonymous_permissions is none %}selected="selected"{% endif %}>&mdash;</option>
                {% for permissions in [Permissions.READ] %}
                  <option value="{{ permissions.name.lower() }}" {% if permissions == filter_anonymous_permissions %}selected="selected"{% endif %}>{{ _(permissions.name.title()) }}</option>
                {% endfor %}
              </select>
            </div>
            {% endif %}
            <div class="form-group">
              <label class="control-label" for="filter_action_type_ids">
                {{ _('Filter by Action Type') }}
              </label>
              <select class="selectpicker form-control" multiple="multiple" name="action_type_ids" id="filter_action_type_ids" data-width="100%" data-none-selected-text="{{ _('All action types') }}" data-hide-disabled="true">
                {% for action_type in all_action_types %}
                  {% if action_type.show_in_object_filters %}
                    <option {% if action_type.component_id is not none %}data-icon="fa fa-share-alt"{% endif %} value="{{ action_type.id }}" {% if filter_action_type_ids and action_type.id in filter_action_type_ids %}selected="selected"{% endif %} data-source="{% if action_type.component_id is none %}local{% else %}component_{{ action_type.component_id }}{% endif %}">{{ action_type.name | get_translated_text(default=_('Unnamed Action Type')) }}</option>
                  {% endif %}
                {% endfor %}
              </select>
            </div>
            <div class="form-group">
              <label class="control-label" for="filter_action_ids">
                {{ _('Filter by Action') }}
              </label>
              <select class="selectpicker form-control" multiple="multiple" name="action_ids" id="filter_action_ids" data-width="100%" data-none-selected-text="{{ _('All actions') }}" data-live-search="on" data-hide-disabled="true">>
                {% for topic in sorted_action_topics + [None] %}
                  {% if sorted_action_topics %}
                    <optgroup label="{% if topic is not none %}{{ topic.name | get_translated_text }}{% else %}{{ _('All Actions') }}{% endif %}">
                  {% endif %}
                  {% for action in all_actions %}
                    {% if topic is none or topic in action.topics %}
                      <option {% if action.component_id is not none %}data-icon="fa fa-share-alt"{% endif %} value="{{ action.id }}" {% if filter_action_ids and action.id in filter_action_ids %}selected="selected"{% endif %} data-source="{% if action.component_id is none %}local{% else %}component_{{ action.component_id }}{% endif %}">
                        {% if action.instrument %}{{ action.instrument.name | get_translated_text(default=_('Unnamed Instrument')) }} — {% endif %}
                        {% if action.user %}{{ action.user.get_name() }} / {% endif %}
                        {{ action.name | get_translated_text(default=_('Unnamed Action')) }} (#{{ action.id }})
                      </option>
                    {% endif %}
                  {% endfor %}
                  {% if sorted_action_topics %}
                    </optgroup>
                  {% endif %}
                {% endfor %}
              </select>
            </div>
            <div class="form-group">
              <label class="control-label" for="filter_instrument_ids">
                {{ _('Filter by Instrument') }}
              </label>
              <select class="selectpicker form-control" multiple="multiple" name="instrument_ids" id="filter_instrument_ids" data-width="100%" data-none-selected-text="{{ _('All instruments') }}" data-live-search="on" data-hide-disabled="true">>
                {% for topic in sorted_instrument_topics + [None] %}
                  {% if sorted_instrument_topics %}
                    <optgroup label="{% if topic is not none %}{{ topic.name | get_translated_text }}{% else %}{{ _('All Instruments') }}{% endif %}">
                  {% endif %}
                  {% for instrument in all_instruments %}
                    {% if topic is none or topic in instrument.topics %}
                      <option {% if instrument.component_id is not none %}data-icon="fa fa-share-alt"{% endif %} value="{{ instrument.id }}" {% if filter_instrument_ids and instrument.id in filter_instrument_ids %}selected="selected"{% endif %} data-source="{% if instrument.component_id is none %}local{% else %}component_{{ instrument.component_id }}{% endif %}">
                        {{ instrument.name | get_translated_text(default=_('Unnamed Instrument')) }}  (#{{ instrument.id }})
                      </option>
                    {% endif %}
                  {% endfor %}
                  {% if sorted_instrument_topics %}
                    </optgroup>
                  {% endif %}
                {% endfor %}
              </select>
            </div>
            <div class="form-group">
              <label class="control-label" for="filter_location_ids">
                {{ _('Filter by Location') }}
              </label>
              <select class="selectpicker form-control" multiple="multiple" name="location_ids" id="filter_location_ids" data-width="100%" data-none-selected-text="{{ _('All locations') }}" data-live-search="on">
                {% for location in all_locations %}
                  <option {% if location.component is not none %}data-icon="fa fa-share-alt"{% endif %} value="{{ location.id }}" {% if filter_location_ids and location.id in filter_location_ids %}selected="selected"{% endif %}>{{ location.name | get_translated_text }}</option>
                {% endfor %}
              </select>
            </div>
            <div class="form-group">
              <label class="control-label" for="filter_doi">
                {{ _('Filter by Publication') }}
              </label>
              <select class="selectpicker form-control" name="doi" id="filter_doi" data-width="100%" data-none-selected-text="{{ _('All publications') }}" data-live-search="on">
                <option value="">{{ _('All publications') }}</option>
                {% for doi, title in all_publications %}
                  <option value="{{ doi }}" {% if filter_doi and doi == filter_doi %}selected="selected"{% endif %}>{% if title %}{{ title }}{% else %}{{ _('Untitled publication') }}{% endif %} (DOI: {{ doi }})</option>
                {% endfor %}
              </select>
            </div>
            {% if all_components %}
            <div class="form-group">
              <label class="control-label" for="filter_origin_ids">
                {{ _('Filter by Origin') }}
              </label>
              <select class="selectpicker form-control" name="origins" id="filter_origin_ids" multiple="multiple" data-width="100%" data-none-selected-text="{{ _('All origins') }}" data-live-search="on">
                <option value="local" {% if filter_origin_ids and ('local', none) in filter_origin_ids %}selected="selected"{% endif %}>{{ config["SERVICE_NAME"] }}</option>
                <optgroup label="{{ _('Other Databases') }}">
                {% for component in all_components %}
                  <option value="component_{{ component.id }}" {% if filter_origin_ids and ('component', component.id) in filter_origin_ids %}selected="selected"{% endif %}>{{ component.get_name() }}</option>
                {% endfor %}
                </optgroup>
              </select>
            </div>
            {% endif %}
          </div>
          <div class="modal-footer">
            <button type="submit" class="btn btn-default" name="save_default_filters" formmethod="post">{{ _('Save') }}</button>
            <button type="submit" class="btn btn-default" name="clear_default_filters" formmethod="post">{{ _('Clear') }}</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">{{ _('Close') }}</button>
            <button type="submit" class="btn btn-primary">{{ _('Apply') }}</button>
          </div>
        </div>
      </form>
    </div>
  </div>
  {% endif %}

  <a href="{{ url_for('.search') }}" class="btn btn-default" style="margin-bottom: 10px">
    {{ _('Search') }}
  </a>

  {% if not edit_location and not create_from_objects and not generate_labels and not edit_permissions %}
    <div class="btn-group" style="margin-bottom: 8px;">
      <button class="btn btn-default dropdown-toggle" type="button" id="multiselect-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        {{ _('Multiple Objects') }}&hellip; <span class="caret"></span>
      </button>
      <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="multiselect-dropdown">
        <li><a href="{{ build_modified_url(edit_location=True) }}" class="dropdown-item"> <i class="fa fa-map-marker" aria-hidden="true"></i> {{ _('Assign Location') }}</a></li>
        <li><a href="{{ build_modified_url(generate_labels=True) }}" class="dropdown-item"><i class="fa fa-tag" aria-hidden="true"></i> {{ _('Generate Labels') }}</a></li>
        <li><a href="{{ build_modified_url(edit_permissions=True) }}" class="dropdown-item"><i class="fa fa-lock" aria-hidden="true"></i> {{ _('Edit Permissions') }}</a></li>
        {% if available_action_types|length > 0 %}
          <h6 class="dropdown-header"> {{ _('Use in Action') }} </h6>
          {% for action_type in available_action_types %}
            <li><a href="{{ build_modified_url(create_from_objects=True, use_in_action_type=action_type.id) }}" class="dropdown-item"> <i class="fa fa-bar-chart" aria-hidden="true"></i> {{ _('Use in %(action_type_name)s', action_type_name=action_type.name|get_translated_text(default=_('Unnamed Action Type'))) }} </a></li>
          {% endfor %}
        {% endif %}
      </ul>
    </div>

  {% elif edit_location and not create_from_objects and not generate_labels and not edit_permissions %}
  {% set allowed_language_ids = [] %}
  {% for language in all_languages %}
    {% if language.enabled_for_input %}
      {% do allowed_language_ids.append(language.id) %}
    {% endif %}
  {% endfor %}

  <form id="multiselect-form" method="post" action="{{ url_for('.edit_multiple_locations') }}">
    {{ location_form.csrf_token }}
    <span class="text-muted">{{ _('Select objects for which you want to change the location.') }}</span>
    <div class="modal-body">
        <div class="form-group">
            <label for="object-location" class="control-label">{{ _('Location') }}</label>
            <select class="treepicker selectpicker form-control" id="object-location" name="{{ location_form.location.name }}" data-live-search="true" >
              {% for location_info in location_form.location.all_choices %}
                  <option {% if location_info.is_fed %}data-icon="fa fa-share-alt"{% endif %} value="{{ location_info.id }}" {% if location_form.location.data == (location_info.id_string) %}selected="selected"{% endif %} {% if location_info.is_disabled %}disabled="disabled"{% endif %} data-content="<span class='{% if location_info.has_subtree %}option-group-{{ location_info.id }}-header{% endif %} closed {% for id in location_info.id_path[:-1] %}option-group-{{ id }}-member option-group-{{ id }}-closed {% endfor %}' style='padding-left:{{ 1.5 * (location_info.id_path | length - 1) }}em'>{% if location_info.has_subtree %}<span class='selectpicker-collapsible-menu'><i class='fa'></i></span> {% endif %}<span class='location_path'>{{ location_info.name_prefix }}</span>{{ location_info.name }}</span>">
                      {{ location_info.full_name }}
                  </option>
              {% endfor %}
            </select>
        </div>
        <div class="form-group">
            <label for="object-responsible-user" class="control-label">{{ _('Responsible User') }}</label>
            <select class="selectpicker form-control" id="object-responsible-user" name="{{ location_form.responsible_user.name }}" data-live-search="true">
                {% for user_id, username in location_form.responsible_user.choices %}
                  <option {% if user_is_fed[user_id] %} data-icon="fa fa-share-alt"{% endif %} value="{{ user_id }}" {% if location_form.responsible_user.data == user_id %} selected="selected" {% endif %}>{% if user_id == '-1' %}&mdash;{% else %} {{ username }} {% endif %}</option>
                {% endfor %}
            </select>
        </div>

        <div class="hidden" id="object_location-template">
            <div class="input-group" data-name="input-group-object_location" style="margin-top: 5px" id="">
                <textarea class="form-control" rows="3" placeholder="{{ _('Description') }}" style="resize: vertical; min-height: 2.5em"></textarea>
                <span class="input-group-addon language-addon" data-name="language"></span>
            </div>
        </div>
        <div class="form-group" {% if location_form.description.name in location_form.errors %} has-error {% endif %} data-name="input-descriptions">
            <label for="object-location" class="control-label" style="padding-right: 5px">{{ _('Description') }}</label>
            <select class="selectpicker pull-right select-language {% if allowed_language_ids | length <= 1 %} hidden {% endif %}" multiple="multiple" data-style="btn-default btn-xs" id="select-language-object_location">
                {% for language in all_languages %}
                <option value="{{ language.lang_code }}" {% if language.id == ENGLISH.id %} disabled="disabled" selected="selected" {% endif %}>{{ language.names | get_translated_text }}</option>
                {% endfor %}
            </select>
        </div>
        <input hidden="hidden" type="text" value="" id="input-object_location-translations" name="{{ location_form.description.name }}" />
        <input hidden="hidden" type="text" value="" id="object-selection" name="selected_objects" />
        <div class="text-right">
          <a type="button" class="btn btn-default" data-dismiss="modal" href="{{ build_modified_url(blocked_parameters=['edit_location']) }}">{{ _('Cancel') }} </a>
          <span id="multiselect-submit-tooltip" style="display: inline-block;" tabindex="0" data-toggle="tooltip" title="{{ _("You have to select at least one object.") }}">
            <button type="submit" id="multiselect-submit" class="btn btn-primary" disabled><i class="fa fa-map-marker fa-fw"></i> {{ _('Assign Location') }} </button>
          </span>
        </div>
    </div>
  </form>
  {% elif create_from_objects and not edit_location and not edit_permissions %}
  <form id="multiselect-form" method="post" action="{{ url_for('.multiselect_action') }}">
    {{ use_in_action_form.csrf_token }}
    <input type="hidden" id="object-selection" name="{{ use_in_action_form.objects.name }}" value="" />
    <span class="text-muted">{{ _('Select objects that can be used in %(action_type_name)s Actions.', action_type_name=use_in_action_type.name|get_translated_text) }}</span>
    <div class="text-left">
      <a type="button" class="btn btn-default" href="{{ build_modified_url(blocked_parameters=['use_in_action_type', 'create_from_objects']) }}"> {{ _('Cancel') }} </a>
      {% if favorite_actions | length > 0 %}
        <div class="btn-group" style="display: inline-block; margin-top: 2px" id="multiselect-submit-tooltip" tabindex="0" data-toggle="tooltip" title="{{ _("You have to select at least one object.") }}">
          <button class="btn btn-primary dropdown-toggle" id="multiselect-submit" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" disabled>
            {{ _('Use in %(action_type_name)s', action_type_name=use_in_action_type.name|get_translated_text(default=_('Unnamed Action Type'))) }} <span class="caret"> </span>
          </button>
          <div class="dropdown-menu dropdown-menu-right multiselect-actions" aria-labelledby="multiselect-submit-by-action">
            <li style="padding: 3px 20px;"><strong>{{ _('Favorites') }}:</strong></li>
            {% for action in favorite_actions %}
              {% if not action.type.disable_create_objects and not action.disable_create_objects and not (action.admin_only and not current_user.is_admin) %}
                <li><button type="submit" class="btn btn-link" style="margin-bottom: 5px;" name="{{ use_in_action_form.action_id.name }}" value="{{ action.id }}">
                    <i class="fa fa-bar-chart fa-fw"></i>
                    {% if action.user_id is not none %}
                      {% set action_owner = get_user(action.user_id) %}
                      {{ action_owner.get_name() }} /
                    {% endif %}
                    {% if action.instrument is not none %}
                      {{ action.instrument.name | get_translated_text }}
                      &mdash;
                    {% endif %}
                    {{ action.name | get_translated_text(default=_('Unnamed Action')) }}
                  </button></li>
              {% endif %}
            {% endfor %}
            <li role="seperator" class="divider"></li>
            <li><button type="submit" class="btn btn-link" name="{{ use_in_action_form.action_type_id.name }}" value="{{ use_in_action_type.id }}">{{ _('See other %(action_type_name)s Actions...', action_type_name=use_in_action_type.name|get_translated_text) }}</button></li>
          </div>
        </div>
      {% else %}
        <span id="multiselect-submit-tooltip" style="display: inline-block;" tabindex="0" data-toggle="tooltip" title="{{ _("You have to select at least one object.") }}">
          <button type="submit" class="btn btn-primary" id="multiselect-submit" disabled data-action-type-id="{{ use_in_action_type.id }}">{{ _('Use in %(action_type_name)s', action_type_name=use_in_action_type.name|get_translated_text) }}</button>
        </span>
      {% endif %}
    </div>
  </form>
  {% elif generate_labels and not create_from_objects and not edit_location and not edit_permissions %}
    <form id="multiselect-form" method="get" action="{{ url_for('.multiselect_labels') }}">
      {{ generate_labels_form.csrf_token }}
      <input type="hidden" id="object-selection" name="{{ generate_labels_form.objects.name }}"/>
      <span class="text-muted">{{ _('Select objects for which you want to generate labels.') }}</span>
      <div class="col-sm-6 col-sm-offset-3" style="margin-top: 15px;">
        <label for="select-label-variant" class="control-label"> {{ _('Select a Label Variant:') }}</label>
        <select id="select-label-variant" class="selectpicker form-control" name="{{ generate_labels_form.form_variant.name }}">
          {% for value, label in generate_labels_form.form_variant.choices %}
            <option value="{{ value }}" {% if loop.first %} selected="selected" {% endif %}> {{ label }}</option>
          {% endfor %}
        </select>
        <hr>
      </div>
      <div id="form-mixed-formats">
        <div class="col-sm-6 col-sm-offset-3">
          <div class="form-group">
            <label for="select-mf-paper-size" class="control-label"> {{ _('Paper Size:') }}</label>
            <select id="select-mf-paper-size" class="selectpicker form-control" name="{{ generate_labels_form.paper_size.name }}" data-multiselect-check-submittable="true">
              {% for value, label in generate_labels_form.paper_size.choices %}
              <option value="{{ value }}" {% if loop.first %} selected="selected" {% endif %}> {{ label }}</option>
              {% endfor %}
            </select>
            <span class="text-muted generate-labels-helper" id="input-mf-paper-size-helper" style="color: red;"></span>
          </div>
          <div class="form-group">
            <label for="input-mf-labels-per-object" class="control-label">{{ _('Labels per Object:') }}</label>
            <input id="input-mf-labels-per-object" type="number" min="1" value="1" class="form-control" aria-label="Labels per Object" name="{{ generate_labels_form.labels_per_object.name }}" data-multiselect-check-submittable="true" />
            <span class="text-muted generate-labels-helper" id="input-mf-labels-per-object-helper" style="color: red;"></span>
          </div>
        </div>
      </div>
      <div id="form-fixed-width" class="multiselect-form-disabled">
        <div class="col-sm-6 col-sm-offset-3">
          <div class="form-group">
            <label for="select-fw-paper-size" class="control-label"> {{ _('Paper Size:') }}</label>
            <select id="select-fw-paper-size" class="selectpicker form-control" name="{{ generate_labels_form.paper_size.name }}" data-multiselect-check-submittable="true" disabled="disabled">
              {% for value, label in generate_labels_form.paper_size.choices %}
                <option value="{{ value }}" {% if loop.first %} selected="selected" {% endif %}> {{ label }}</option>
              {% endfor %}
            </select>
            <span class="text-muted generate-labels-helper" id="input-fw-paper-size-helper" style="color: red;"></span>
          </div>
          <div class="form-group">
            <label for="input-fw-label-width" class="control-label">{{ _('Label Width:') }}</label>
            <div class="input-group">
              <input id="input-fw-label-width" type="text" class="form-control" aria-label="Label Width" value="40" name="{{ generate_labels_form.label_width.name }}" data-multiselect-check-submittable="true" disabled="disabled" />
              <span class="input-group-addon">mm</span>
            </div>
            <span class="text-muted generate-labels-helper" id="input-fw-label-width-helper" style="color: red;"></span>
          </div>
          <div class="form-group">
            <label for="input-fw-label-min-height">{{ _('Minimum Label Height:') }}</label>
            <div class="input-group ">
              <input id="input-fw-label-min-height" type="text" class="form-control" aria-label="Label Heigth" value="0" name="{{ generate_labels_form.min_label_height.name }}" data-multiselect-check-submittable="true" disabled="disabled"/>
              <span class="input-group-addon">mm</span>
            </div>
            <span class="text-muted generate-labels-helper" id="input-fw-min-label-height-helper" style="color: red;"></span>
          </div>
          <div class="form-group">
            <label for="input-fw-labels-per-object">{{ _('Labels per Object:') }}</label>
            <input id="input-fw-labels-per-object" type="number" min="1" class="form-control" aria-label="Labels per Object" value="1" name="{{ generate_labels_form.labels_per_object.name }}" data-multiselect-check-submittable="true" disabled="disabled"/>
            <span class="text-muted generate-labels-helper" id="input-fw-labels-per-object-helper" style="color: red;"></span>
          </div>
          <div class="form-group">
            <div>
              <div class="checkbox">
                <label>
                  <input type="checkbox" name="{{ generate_labels_form.qr_ghs_side_by_side.name }}" disabled="disabled"> {{ _('QR Code and GHS symbols side-by-side') }}
                </label>
              </div>
            </div>
          </div>
          <div class="form-group">
            <div>
              <div class="checkbox">
                <label>
                  <input type="checkbox" name="{{ generate_labels_form.center_qr_ghs.name }}" checked="checked" disabled="disabled" data-multiselect-check-submittable="true"> {{ _('Center QR Code and GHS symbols') }}
                </label>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div id="form-minimal-height" class="multiselect-form-disabled">
        <div class="col-sm-6 col-sm-offset-3">
          <div class="form-group">
            <label for="select-mh-paper-size" class="control-label"> {{ _('Paper Size:') }}</label>
            <select id="select-mh-paper-size" class="selectpicker form-control" name="{{ generate_labels_form.paper_size.name }}" data-multiselect-check-submittable="true" disabled="disabled">
              {% for value, label in generate_labels_form.paper_size.choices %}
                <option value="{{ value }}" {% if loop.first %} selected="selected" {% endif %}> {{ label }}</option>
              {% endfor %}
            </select>
          </div>
          <div class="form-group">
            <label for="input-mh-min-label-width" class="control-label">{{ _('Minimum Label Width:') }}</label>
            <div class="input-group">
              <input id="input-mh-min-label-width" type="text" class="form-control" aria-label="Label Width" value="0" name="{{ generate_labels_form.min_label_width.name }}" data-multiselect-check-submittable="true" disabled="disabled"/>
              <span class="input-group-addon">mm</span>
            </div>
            <span class="text-muted generate-labels-helper" id="input-mh-min-label-width-helper" style="color: red;"></span>
          </div>
          <div class="form-group">
            <label for="input-mh-labels-per-object">{{ _('Labels per Object:') }}</label>
            <input id="input-mh-labels-per-object" type="number" min="1" class="form-control" aria-label="Labels per Object" value="1" name="{{ generate_labels_form.labels_per_object.name }}" data-multiselect-check-submittable="true" disabled="disabled"/>
            <span class="text-muted generate-labels-helper" id="input-mh-labels-per-object-helper" style="color: red;"></span>
          </div>
          <div class="form-group">
            <div>
              <div class="checkbox">
                <label>
                  <input type="checkbox" name="{{ generate_labels_form.include_qr.name }}"> {{ _('Include QR Code') }}
                </label>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="text-right col-sm-offset-8 col-sm-4">
        <a href="{{ build_modified_url(blocked_parameters=['generate_labels']) }}" class="btn btn-default">{{ _('Cancel') }}</a>
        <span id="multiselect-submit-tooltip" style="display: inline-block;" tabindex="0" data-toggle="tooltip" title="{{ _("You have to select at least one object.") }}">
          <button type="submit" class="btn btn-primary" id="multiselect-submit" disabled="disabled"> <i class="fa fa-tag"></i> {{ _('Generate Labels') }}</button>
        </span>
      </div>
    </form>
  {% elif not create_from_objects and not edit_location and not generate_labels and edit_permissions %}
  <form id="multiselect-form" method="post" action="{{ url_for('.multiselect_permissions') }}" style="margin-bottom: 10px;">
    {{ edit_permissions_form.csrf_token }}
    <span class="text-muted">{{ _('Select objects for which you want to change the permissions.') }}</span>
    <input type="hidden" id="object-selection" name="{{ edit_permissions_form.objects.name }}" value="" />
    <div class="row">
      <div class="col-sm-6 col-sm-offset-3" style="margin-top: 15px;">
        <div class="row">
          <div class="form-group col-sm-6">
            <label for="edit-permissions-target-type" class="control-label">{{ _('Select the target type:') }}</label>
            <select id="edit-permissions-target-type" name="{{ edit_permissions_form.target_type.name }}" class="selectpicker form-control">
              {% for key, label in edit_permissions_form.target_type.choices %}objects.html
                <option value="{{key}}" {% if loop.first %} selected="selected" {% endif %} {% if (key == 'group' and edit_permissions_form.groups.choices|length == 0) or (key == 'project-group' and edit_permissions_form.project_groups.choices|length == 0) %} disabled="disabled" {% endif %}>{{ label }}</option>
              {% endfor %}
            </select>
          </div>
          <div class="form-group col-sm-6" id="edit-permissions-groups-container" hidden="hidden">
            <label for="edit-permissions-groups" class="control-label">{{ _('Select a Group:') }}</label>
            <select id="edit-permissions-groups" class="treepicker selectpicker form-control" name="{{ edit_permissions_form.groups.name }}" data-live-search="true" disabled="disabled">
            {% for group_info in groups_treepicker_info %}
              <option value="{{ group_info.id }}" {% if group_info.is_disabled %} disabled="disabled" {% endif %} data-content="<span class='{% if group_info.has_subtree %}option-group-{{group_info.id}}-header {% endif %} closed {% for id in group_info.id_path[:-1] %} option-group-{{ id }}-member option-group-{{ id }}-closed {% endfor %}' style='padding-left: {{1.5 * (group_info.id_path | length - 1)}}em'>{% if group_info.has_subtree %} <span class='selectpicker-collapsible-menu'><i class='fa'></i></span> {% endif %}<span class='location_path'> {{ group_info.name_prefix }}</span>{{ group_info.name }}</span>">
                {{ group_info.full_name }}
              </option>
            {% endfor %}
            </select>
          </div>
          <div class="form-group col-sm-6" id="edit-permissions-users-container" hidden="hidden">
            <label for="edit-permissions-users" class="control-label">{{ _('Select an User:') }}</label>
            <select id="edit-permissions-users" class="selectpicker form-control" name="{{ edit_permissions_form.users.name }}" data-live-search="true" disabled="disabled">
              {% for user_id, user_name in edit_permissions_form.users.choices %}
                <option value="{{ user_id }}" {% if loop.first %} selected="selected" {% endif %}>{{ user_name }}</option>
              {% endfor %}
            </select>
          </div>
          <div class="form-group col-sm-6" id="edit-permissions-project-groups-container" hidden="hidden">
            <label for="edit-permissions-project-groups" class="control-label">{{ _('Select a Project Group:') }}</label>
            <select id="edit-permissions-project-groups" class="treepicker selectpicker form-control" name="{{ edit_permissions_form.project_groups.name }}" data-live-search="true" disabled="disabled">
              {% for project_info in projects_treepicker_info %}
                <option value="{{ project_info.id }}" {% if project_info.is_disabled %} disabled="disabled" {% endif %} data-content="<span class='{% if project_info.has_subtree %} option-group-{{ project_info.id }}-header{% endif %} closed {% for id in project_info.id_path[:-1] %} option-group-{{ id }}-member option-group-{{ id }}-closed {% endfor %}' style='padding-left: {{1.5 * (project_info.id_path | length - 1) }}em'>{% if project_info.has_subtree %}<span class='selectpicker-collapsible-menu'><i class='fa'></i></span> {% endif %}<span class='location_path'> {{ project_info.name_prefix }}</span>{{ project_info.name }}</span>">
                  {{ project_info.full_name }}
                </option>
              {% endfor %}
            </select>
          </div>
        </div>
        <div class="form-group">
          <label for="edit-permissions-update-mode" class="control-label">{{ _('Select how to edit the permissions:') }}</label>
          <div class="row">
            {% for key, label in edit_permissions_form.update_mode.choices %}
              <div class="col-sm-6">
                <label style="font-weight: normal;">
                  <input type="radio" name="{{ edit_permissions_form.update_mode.name }}" value="{{ key }}" {% if loop.first %} checked="checked" {% endif %}>
                  {{ label }}
                  {% if key == 'set-max' %}
                    <i class="fa fa-exclamation-circle" data-toggle="tooltip" data-placement="top" title="{{ _('Note that after setting the maximum permission, a user can still have a higher permission, for example by a group/project group.') }}"></i>
                  {% endif %}
                </label>
              </div>
            {% endfor %}
          </div>
        </div>
        <div class="form-group">
          <label for="edit-permissions-permission" class="control-label">{{ _('Select a Permission:') }}</label>
          <div class="row">
            {% for key, label in edit_permissions_form.permission.choices %}
              <div class="col-sm-3">
                <label style="font-weight: normal;">
                  <input type="radio" name="{{ edit_permissions_form.permission.name }}" value="{{ key }}" {% if loop.first %} checked="checked" {% endif %}>
                  {{ label}}
                </label>
              </div>
            {% endfor %}
          </div>
        </div>
      </div>
    </div>
    <div class="text-right row">
      <a href="{{ build_modified_url(blocked_parameters=['edit_permissions']) }}" class="btn btn-default">{{ _('Cancel') }}</a>
      <span id="multiselect-submit-tooltip" style="display: inline-block;" tabindex="0" data-toggle="tooltip" title="{{ _('You have to select at least one object.') }}">
        <button type="submit" id="multiselect-submit" class="btn btn-primary" disabled>{{ _('Save permissions') }}</button>
      </span>
    </div>
  </form>
  {% endif %}

  {% if objects %}
  </div>

  <div class="container" {% with user_settings = get_user_settings() %}{% if user_settings['FULL_WIDTH_OBJECTS_TABLE'] or (user_settings['FULL_WIDTH_OBJECTS_TABLE'] is none and config['FULL_WIDTH_OBJECTS_TABLE']) %}id="table-objects-container"{% endif %}{% endwith %}>
  <table class="table" id="table-objects">
  <thead>
    <tr>
      {% if edit_location or create_from_objects or generate_labels or edit_permissions %}
        <th scope="col" rowspan="2">
          <input id="checkbox-select-overall" type="checkbox" value="state" />
        </th>
      {% endif %}
      <th scope="col" {% if creation_info or last_edit_info %}rowspan="2"{% endif %}>{{ _('ID') }} {% if sorting_enabled %}<span class="icons-sorting"><a href="{{ build_modified_url(sortby='_object_id', order='asc') }}"><i class="glyphicon glyphicon glyphicon-triangle-top {% if sorting_property == '_object_id' and sorting_order == 'asc' %}current_sorting_property{% endif %}" aria-hidden="true"></i></a><a href="{{ build_modified_url(sortby='_object_id', order='desc') }}"><i class="glyphicon glyphicon glyphicon-triangle-bottom {% if sorting_property == '_object_id' and sorting_order == 'desc' %}current_sorting_property{% endif %}" aria-hidden="true"></i></a></span>{% endif %}</th>
      <th scope="col" {% if creation_info or last_edit_info %}rowspan="2"{% endif %}>{{ _('Name') }} {% if sorting_enabled %}<span class="icons-sorting"><a href="{{ build_modified_url(sortby='name', order='asc') }}"><i class="glyphicon glyphicon glyphicon-triangle-top {% if sorting_property == 'name' and sorting_order == 'asc' %}current_sorting_property{% endif %}" aria-hidden="true"></i></a><a href="{{ build_modified_url(sortby='name', order='desc') }}"><i class="glyphicon glyphicon glyphicon-triangle-bottom {% if sorting_property == 'name' and sorting_order == 'desc' %}current_sorting_property{% endif %}" aria-hidden="true"></i></a></span>{% endif %}</th>
      {% if not edit_permissions %}
        {% if creation_info %}
          <th scope="col" {% if 'user' in creation_info and 'date' in creation_info %}colspan="2"{% endif %}>{{ _('Created') }}</th>
        {% endif %}
        {% if last_edit_info %}
          <th scope="col"  {% if 'user' in last_edit_info and 'date' in last_edit_info %}colspan="2"{% endif %}>{{ _('Last modified') }}</th>
        {% endif %}
        {% if other_databases_info %}
          <th scope="col" {% if creation_info or last_edit_info %}rowspan="2"{% endif %}>{{ _('Other Databases') }}</th>
        {% endif %}
        {% if 'instrument' in action_info and not config['DISABLE_INSTRUMENTS'] %}
          <th scope="col" {% if creation_info or last_edit_info %}rowspan="2"{% endif %}>{{ _('Instrument') }}</th>
        {% endif %}
        {% if 'action' in action_info %}
          <th scope="col" {% if creation_info or last_edit_info %}rowspan="2"{% endif %}>{{ _('Action') }}</th>
        {% endif %}
        {% if 'location' in location_info %}
          <th scope="col" {% if creation_info or last_edit_info %}rowspan="2"{% endif %}>{{ _('Location') }}</th>
        {% endif %}
        {% if 'responsible_user' in location_info %}
          <th scope="col" {% if creation_info or last_edit_info %}rowspan="2"{% endif %}>{{ _('Responsible User') }}</th>
        {% endif %}
        {% if 'topics' in topic_info %}
          <th scope="col" {% if creation_info or last_edit_info %}rowspan="2"{% endif %}>{{ _('Topics') }}</th>
        {% endif %}
        {% for property_name in display_properties %}
          <th scope="col" {% if creation_info or last_edit_info %}rowspan="2"{% endif %}>{{ display_property_titles.get(property_name, property_name | e) | get_translated_text | safe }}{% if property_name not in ('hazards', 'tags') %} {% if sorting_enabled %}<span class="icons-sorting"><a href="{{ build_modified_url(sortby=property_name, order='asc') }}"><i class="glyphicon glyphicon glyphicon-triangle-top {% if sorting_property == property_name and sorting_order == 'asc' %}current_sorting_property{% endif %}" aria-hidden="true"></i></a><a href="{{ build_modified_url(sortby=property_name, order='desc') }}"><i class="glyphicon glyphicon glyphicon-triangle-bottom {% if sorting_property == property_name and sorting_order == 'desc' %}current_sorting_property{% endif %}" aria-hidden="true"></i></a></span>{% endif %}{% endif %}</th>
        {% endfor %}
      </tr>
      {% if creation_info or last_edit_info %}
      <tr>
        {% if 'date' in creation_info %}
          <th scope="col">{{ _('Date') }} {% if sorting_enabled %}<span class="icons-sorting"><a href="{{ build_modified_url(sortby='_creation_date', order='asc') }}"><i class="glyphicon glyphicon glyphicon-triangle-top {% if sorting_property == '_creation_date' and sorting_order == 'asc' %}current_sorting_property{% endif %}" aria-hidden="true"></i></a><a href="{{ build_modified_url(sortby='_creation_date', order='desc') }}"><i class="glyphicon glyphicon glyphicon-triangle-bottom {% if sorting_property == '_creation_date' and sorting_order == 'desc' %}current_sorting_property{% endif %}" aria-hidden="true"></i></a></span>{% endif %}</th>
        {% endif %}
        {% if 'user' in creation_info %}
          <th scope="col">{{ _('User') }}</th>
        {% endif %}
        {% if 'date' in last_edit_info %}
          <th scope="col">{{ _('Date') }} {% if sorting_enabled %}<span class="icons-sorting"><a href="{{ build_modified_url(sortby='_last_modification_date', order='asc') }}"><i class="glyphicon glyphicon glyphicon-triangle-top {% if sorting_property == '_last_modification_date' and sorting_order == 'asc' %}current_sorting_property{% endif %}" aria-hidden="true"></i></a><a href="{{ build_modified_url(sortby='_last_modification_date', order='desc') }}"><i class="glyphicon glyphicon glyphicon-triangle-bottom {% if sorting_property == '_last_modification_date' and sorting_order == 'desc' %}current_sorting_property{% endif %}" aria-hidden="true"></i></a></span>{% endif %}</th>
        {% endif %}
        {% if 'user' in last_edit_info %}
          <th scope="col">{{ _('User') }}</th>
        {% endif %}
      </tr>
      {% endif %}
    {% else %}
      {% set read_permissions_description = _("Permission to view objects and their properties, files and comments.") %}
      {% set write_permissions_description = _("Permission to edit objects and their properties and add files and comments. Includes Read permissions.") %}
      {% set grant_permissions_description = _("Permission to grant permissions to other users. Includes Write permissions.") %}
      <tr>
        <th scope="col" class="permissions-table-head">{{ _('None') }}</th>
        <th scope="col" class="permissions-table-head"><span data-toggle="tooltip" data-placement="top" title="{{ read_permissions_description }}">{{ _('Read') }} <i class="fa fa-question-circle" aria-hidden="true"></i></span></th>
        <th scope="col" class="permissions-table-head"><span data-toggle="tooltip" data-placement="top" title="{{ write_permissions_description }}">{{ _('Write') }} <i class="fa fa-question-circle" aria-hidden="true"></i></span></th>
        <th scope="col" class="permissions-table-head"><span data-toggle="tooltip" data-placement="top" title="{{ grant_permissions_description }}">{{ _('Grant') }} <i class="fa fa-question-circle" aria-hidden="true"></i></span></th>
      </tr>
    {% endif %}
  </thead>
  <tbody>
  {% for object in objects %}
    <tr>
      {% if edit_location or create_from_objects or generate_labels or edit_permissions %}
        {% if edit_location %}
          {% set disabled_checkbox_reason =  _('You need at least write permission to change the location of an object.')  %}
        {% elif create_from_objects %}
          {% set disabled_checkbox_reason = _('The object cannot be used in a %(action_type_name)s Action.', action_type_name=use_in_action_type.name|get_translated_text) %}
        {% elif generate_labels %}
          {% set disabled_checkbox_reason = _('Labels are disabled for the action type of this object.') %}
        {% elif edit_permissions %}
          {% set disabled_checkbox_reason =  _('You need grant permission to change the permissions for this object.')  %}
        {% endif %}
        <td><input type="checkbox" name="cb-{{object.object_id}}" id="cb-{{object.object_id}}" class="checkbox-select-child" value="{{object.object_id}}" {% if (edit_location or create_from_objects or generate_labels or edit_permissions) and object.object_id not in objects_allowed_to_select %} disabled="disabled" data-toggle="tooltip" data-placement="right" title="{{ disabled_checkbox_reason }}" {% endif %}/> </td>
        {% if (edit_location or create_from_objects or generate_labels or edit_permissions) and object.object_id not in objects_allowed_to_select %}
        {% endif %}
      {% endif %}
      <th scope="row"><a href="{{ url_for('.object', object_id=object.object_id) }}">{{ object.object_id }}</a></th>
      <td>
        <a href="{{ url_for('.object', object_id=object.object_id) }}">{% if object.name | get_translated_text == '' %}&mdash;{% else %}{{ object.name | get_translated_text }}{% endif %}</a>
        {{ import_information_symbol(wrap_object_ref(fed_id=object.fed_id, component_uuid=object.component.uuid, eln_import_id=object.eln_import_id, eln_object_id=object.eln_object_id)) }}
      </td>
      {% if not edit_permissions %}
        {% if 'date' in creation_info %}
        <td class="nowrap">{{ object.created_at | babel_format_date }}</td>
        {% endif %}
        {% if 'user' in creation_info %}
        <td>
          {{ user_reference(object.created_by) }}
        </td>
        {% endif %}
        {% if 'date' in last_edit_info %}
        <td class="nowrap">{% if object.last_modified_at is not none %}{{ object.last_modified_at | babel_format_date }}{% else %}&mdash;{% endif %}</td>
        {% endif %}
        {% if 'user' in last_edit_info %}
        <td>
          {{ user_reference(object.modified_by) }}
        </td>
        {% endif %}
        {% if other_databases_info %}
          <td>
          {% set shares = get_shares_for_object(object.object_id) %}
          {% set components = [] %}
          {% if object.component is not none %}
            {% do components.append(object.component) %}
            <span data-toggle="tooltip" data-placement="top" title="{{ _('Shared by %(component_name)s', component_name=object.component.get_name()) }}">
              <i class="fa fa-arrow-left"></i>&nbsp;<a href="{{ url_for('.component', component_id=object.component_id) }}">{{ object.component.get_name() }}</a>
            </span>
          {% endif %}
          {% for share in shares %}
            {% if share.component is not none %}
              {% do components.append(share.component) %}
              <span data-toggle="tooltip" data-placement="top" title="{{ _('Shared with %(component_name)s', component_name=share.component.get_name()) }}">
                <i class="fa fa-arrow-right"></i>&nbsp;<a href="{{ url_for('.component', component_id=share.component_id) }}">{{ share.component.get_name() }}</a>
              </span>
            {% endif %}
          {% endfor %}
          {% if not components %}
            &mdash;
          {% endif %}
          </td>
        {% endif %}
        {% if object.action is not none %}
          {% if 'instrument' in action_info and not config['DISABLE_INSTRUMENTS'] %}
          {% if object.action.instrument is not none %}
            <td><a href="{{ url_for('.instrument', instrument_id=object.action.instrument_id) }}">{{ object.action.instrument.name | get_translated_text(default=_('Unnamed Instrument')) }}</a>
              {{ import_information_symbol(object.action.instrument) }}
            </td>
          {% else %}
            <td>&mdash;</td>
          {% endif %}
          {% endif %}
          {% if 'action' in action_info %}
          <td>
            <a href="{{ url_for('.action', action_id=object.action.id) }}">
              {{ object.action.name | get_translated_text(default=_('Unnamed Action')) }}
            </a>
            {{ import_information_symbol(object.action) }}
          </td>
          {% endif %}
        {% else %}
          {% if 'instrument' in action_info and not config['DISABLE_INSTRUMENTS'] %}
            <td>&mdash;</td>
          {% endif %}
          {% if 'action' in action_info %}
            <td>&mdash;</td>
          {% endif %}
        {% endif %}
        {% if 'location' in location_info %}
          <td>
            {% if object.location_id is none %}
              &mdash;
            {% else %}
              {% with location = get_location(object.location_id) %}
                <a href="{{ url_for('frontend.location', location_id=location.id) }}">
                  {{ location | get_location_name(True) }}
                </a>
                {{ import_information_symbol(location) }}
              {% endwith %}
            {% endif %}
          </td>
        {% endif %}
        {% if 'responsible_user' in location_info %}
          <td>
            {% if object.responsible_user_id is none %}
              &mdash;
            {% else %}
              {{ user_reference(object.responsible_user_id) }}
            {% endif %}
          </td>
        {% endif %}
        {% if 'topics' in topic_info %}
          <td>
            {% if object.topic_ids %}
              {% for topic_id in object.topic_ids %}
                {% set topic = topics_by_id.get(topic_id) %}
                {% if topic is not none %}
                  <a class="badge badge-secondary" href="{{ url_for('.topic', topic_id=topic.id) }}"
                    {% if object.topic_ids[topic_id] %}
                      data-toggle="tooltip" data-placement="top"
                      title="{{ _('via') }} {% for topic_source in object.topic_ids[topic_id] -%}
                        {%- if not loop.first -%}
                          {% if loop.last %} {{ _('and') }} {% else %}, {% endif -%}
                        {%- endif -%}
                         {{ {1: _('Action'), 2: _('Instrument'), 3: _('Locations')}.get(topic_source | int, _('a different source')) }}
                       {%- endfor %}"
                    {% endif %}
                  >{{ topic.name | get_translated_text }}</a>
                {% endif %}
              {% endfor %}
            {% else %}
              &mdash;
            {% endif %}
          </td>
        {% endif %}
        {% set files = object.files %}
        {% for property_name in display_properties %}
          {% if object.display_properties[property_name] is not none %}
            {% set metadata_language = none %}
            {% set object_id = object.object_id %}
            {% set id_prefix_root = "object" ~ object_id %}
            {% set property_path = (property_name,) %}
            {% set id_prefix = id_prefix_for_property_path(property_path, id_prefix_root) %}
            {% set data = object.display_properties[property_name][0] %}
            {% set schema = object.display_properties[property_name][1] %}
            {% set container_style = 'table' %}
            <td>
            {% include "objects/view/any.html" %}
            </td>
          {% else %}
            <td> &mdash; </td>
          {% endif %}
        {% endfor %}
      {% else %}
        {% if object["object_id"] in objects_allowed_to_select %}
          {% for available_permission in ['none', 'read', 'write', 'grant'] %}
            {% if available_permission == current_permissions_special_groups["signed-in-users"][object["object_id"]] %}
              <td id="permission-{{ object["object_id"] }}-{{ available_permission }}" class="permission-entry-disabled permissions-table-data permissions-entry-{{ object['object_id'] }}"><i class="fa fa-check" aria-hidden="true"></i></td>
            {% else %}
              <td id="permission-{{ object["object_id"] }}-{{ available_permission }}" class="permission-entry-disabled permissions-table-data permissions-entry-{{ object['object_id'] }}"><i class="fa fa-times" aria-hidden="true"></i></td>
            {% endif %}
          {% endfor %}
        {% else %}
          <td class="permissions-table-data" class="permission-entry-disabled">&mdash;</td>
          <td class="permissions-table-data" class="permission-entry-disabled">&mdash;</td>
          <td class="permissions-table-data" class="permission-entry-disabled">&mdash;</td>
          <td class="permissions-table-data" class="permission-entry-disabled">&mdash;</td>
        {% endif %}
      {% endif %}
    </tr>
  {% endfor %}
  </tbody>
  </table>
  </div>

  <div class="container">
  {% if pagination_enabled %}
    <div>
    {{ _('Pages') }}:
    <ol class="object-pagination">
    {% if limit and num_objects_found %}
      {% for i in range((num_objects_found+limit-1)//limit) %}
        {% if i * limit == offset %}
          <li>{{ i + 1 }}</li>
        {% else %}
          <li><a href="{{ build_modified_url(limit=limit, offset=i*limit) }}">{{ i + 1 }}</a></li>
        {% endif %}
      {% endfor %}
    {% else %}
      <li>1</li>
    {% endif %}
    </ol>
    </div>
    <div>
    {{ _('Objects per page') }}:
    <ol class="object-pagination">
    {% for i in (10, 25, 50, 100, 'all') %}
      {% if i == limit or (limit is none and i == 'all') %}
        <li>{% if i == 'all' %}{{ _('all') }}{% else %}{{ i }}{% endif %}</li>
      {% else %}
        <li><a href="{{ build_modified_url(limit=i, offset=0) }}">{% if i == 'all' %}{{ _('all') }}{% else %}{{ i }}{% endif %}</a></li>
      {% endif %}
    {% endfor %}
    </ol>
    </div>
  {% endif %}
  {% elif not search_notes and use_advanced_search and advanced_search_had_error %}
    <div class="alert alert-danger" role="alert">
      {{ _('Failed to interpret advanced search query. Please check your query or try the regular search instead.') }}
    </div>
  {% elif not advanced_search_had_error %}
    <div class="alert alert-warning" role="alert">
      {{ _('No objects were found.') }}
    </div>
  {% endif %}
  {% include "objects/view/timeseries_modals.html" %}
{% endblock %}
