{% extends "base.html" %}

{% block title %}Actions — {{ service_name }}{% endblock %}

{% block content %}
  <h1>{% if action_type %}{{ action_type.name }} {% endif %}Actions</h1>
  <p class="text-muted">{% if action_type and action_type.description %}{{ action_type.description }}{% else %}Actions represent processes like creating a sample, performing a measurement or running a simulation.{% endif %} <a href="https://scientific-it-systems.iffgit.fz-juelich.de/SampleDB/user_guide/actions.html">Read more.</a></p>
  {% if current_user.is_admin and not current_user.is_readonly %}
    {% if action_type %}
    <a href="{{ url_for('.new_action', action_type_id=action_type.id) }}" class="btn btn-default">Create Action</a>
    {% else %}
    <a href="{{ url_for('.new_action') }}" class="btn btn-default">Create Action</a>
    {% endif %}
  {% endif %}
  {% for action in actions %}
    <form action="{{ url_for('.toggle_favorite_action', sample_id=request.args.get('sample_id', None), t=request.args.get('t', None)) }}" method="post">
      <input type="hidden" name="action_id" value="{{ action.id }}">
      {{ toggle_favorite_action_form.csrf_token() }}
      <h2>
        {% if action.user is not none %}
        <a href="{{ url_for('.user_profile', user_id=action.user.id) }}" title="{{ action.user.name }}">{{ action.user.name }}</a> /
        {% endif %}
        {% if action.instrument is not none %}
        <a href="{{ url_for('.instrument', instrument_id=action.instrument.id) }}" title="{{ action.instrument.name }}">{{ action.instrument.name }}</a> &mdash;
        {% endif %}
        <a href="{{ url_for('.action', action_id=action.id) }}" title="{{ action.name }}">{{ action.name }}</a>
        <button type="submit" class="fa {% if action.id in user_favorite_action_ids %}fav-star-on{% else %}fav-star-off{% endif %}" value=""></button>
      </h2>
    </form>
    {% if action.is_hidden %}
    <p class="text-muted"><i class="fa fa-eye-slash" aria-hidden="true"></i> This action has been hidden from action lists.</p>
    {% endif %}
    {% if action.description_as_html or action.description %}
    <div class="action-user-content">
    {% if action.description_as_html %}{{ action.description_as_html | safe }}{% else %}<p>{{ action.description }}</p>{% endif %}
    </div>
    {% endif %}
    {% with instrument = action.instrument %}
      {% include "instruments/instrument_scientists.html" %}
    {% endwith %}
    <p>
      <a href="{{ url_for('.objects', action=action.id) }}" class="btn btn-default">{{ action.type.view_text }}</a>
      {% if not current_user.is_readonly %}
      <a href="{{ url_for('.new_object', action_id=action.id, sample_id=request.args.get('sample_id', None)) }}" class="btn btn-primary">{{ action.type.perform_text }}</a>
      {% endif %}
    </p>
  {% endfor %}
{% endblock %}

{% block scripts %}
  {{ super() }}
  <script src="{{ url_for('static', filename='js/markdown_image_viewer.js') }}"></script>
{% endblock %}