{% extends "base.html" %}

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

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

{% block template_values %}
  {% set language_info_languages = [] %}
  {% for lang in languages %}
    {% do language_info_languages.append({"id": lang.id | string, "name": lang.names | get_translated_text, "lang_code": lang.lang_code}) %}
  {% endfor %}
  {% do set_template_value("language_info.languages", language_info_languages) %}
  {% do set_template_value("language_info.english_id", ENGLISH.id) %}

  {% set translations = [] %}
  {% for translation in action_type_translations %}
    {% do translations.append({"language_id": translation.language_id | string, "name": translation.name, "description": translation.description, "object_name": translation.object_name, "object_name_plural": translation.object_name_plural, "view_text": translation.view_text, "perform_text": translation.perform_text}) %}
  {% endfor %}
  {% do set_template_value("translations", translations) %}

  {% do set_template_value("is_create_form", submit_text == _('Create')) %}

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

{% block scripts %}
  {{ super() }}
  <script src="{{ fingerprinted_static('bootstrap-select/js/bootstrap-select.min.js') }}"></script>
  <script src="{{ fingerprinted_static('sampledb/js/page/action_type_form.js') }}" type="module"></script>
{% endblock %}

{% block content %}
  <form method="post">
    {{ action_type_form.hidden_tag() }}
    <div class="col-md-12">

      <div class="hidden" id="name-template">
        <div class="input-group" data-language-id="">
          <input type="text" class="form-control" id="input-name" placeholder="{{ _("Name") }}" data-name="input-name" data-translation-attribute="name" data-empty-text="{{ _("Please enter a name.") }}" data-max-length="100" data-max-length-text="{{ _("Please enter a shorter name (at most 100 characters).") }}" data-required-in-all-languages="1">
          <span class="input-group-addon language-addon" data-name="language"></span>
        </div>
        <span class="help-block" data-name="name"></span>
      </div>

      <div class="hidden" id="description-template">
        <div class="input-group" data-language-id="">
          <input type="text" class="form-control" id="input-description" placeholder="{{ _("Description") }}" data-name="input-description" data-translation-attribute="description">
          <span class="input-group-addon language-addon" data-name="language"></span>
        </div>
        <span class="help-block" data-name="description"></span>
      </div>

      <div class="hidden" id="object-name-singular-template">
        <div class="input-group" data-language-id="">
          <input type="text" class="form-control" id="input-object-name-singular" placeholder="{{ _("Object Name (singular)") }}" data-name="input-object-name-singular" data-translation-attribute="object_name" data-empty-text="{{ _("Please enter an object name (singular).") }}" data-max-length="100" data-max-length-text="{{ _("Please enter a shorter object name (singular) (at most 100 characters).") }}" data-required-in-all-languages="1">
          <span class="input-group-addon language-addon" data-name="language"></span>
        </div>
        <span class="help-block" data-name="object-name-singular"></span>
      </div>

      <div class="hidden" id="object-name-plural-template">
        <div class="input-group" data-language-id="">
          <input type="text" class="form-control" id="input-object-name-plural" placeholder="{{ _("Object Name (plural)") }}" data-name="input-object-name-plural" data-translation-attribute="object_name_plural" data-empty-text="{{ _("Please enter an object name (plural).") }}" data-max-length="100" data-max-length-text="{{ _("Please enter a shorter object name (plural) (at most 100 characters).") }}" data-required-in-all-languages="1">
          <span class="input-group-addon language-addon" data-name="language"></span>
        </div>
        <span class="help-block" data-name="object-name-plural"></span>
      </div>

      <div class="hidden" id="view-text-template">
        <div class="input-group" data-language-id="">
          <input type="text" class="form-control" id="input-view-text" placeholder="{{ _("View text") }}" data-name="input-view-text" data-translation-attribute="view_text" data-empty-text="{{ _("Please enter a view text.") }}" data-max-length="100" data-max-length-text="{{ _("Please enter a shorter view text (at most 100 characters).") }}" data-required-in-all-languages="1">
          <span class="input-group-addon language-addon" data-name="language"></span>
        </div>
        <span class="help-block" data-name="view-text"></span>
      </div>

      <div class="hidden" id="perform-text-template">
        <div class="input-group" data-language-id="">
          <input type="text" class="form-control" id="input-perform-text" placeholder="{{ _("Perform Text") }}" data-name="input-perform-text" data-translation-attribute="perform_text" data-empty-text="{{ _("Please enter a perform text.") }}" data-max-length="100" data-max-length-text="{{ _("Please enter a shorter perform text (at most 100 characters).") }}" data-required-in-all-languages="1">
          <span class="input-group-addon language-addon" data-name="language"></span>
        </div>
        <span class="help-block" data-name="perform-text"></span>
      </div>

      <div class="form-group row" style="padding-right: 10px">
        <label for="select-languages" class="control-label col-md-10">{{ _("Languages") }}</label>
        <select class="selectpicker btn-xs select-language col-md-2" data-style="btn-default btn-xs" multiple="multiple" id="select-languages">
          {% for language in languages %}
            <option value="{{ language.id }}" {% if language.id == ENGLISH.id %} disabled="disabled" selected="selected" {% endif %} {% if language.id in action_type_language_ids %} selected="selected"{% endif %} data-name="{{ language.names | get_translated_text }}">{{ language.names | get_translated_text }}</option>
          {% endfor %}
        </select>
      </div>

      <input type="hidden" id="input-translations" name="{{ action_type_form.translations.name }}" value="">

      <div class="form-group" data-name="input-names">
        <div class="form-group" style="margin-bottom: 0">
            <label for="input-name" class="control-label">{{ _('Name') }}</label>
        </div>
        <div class="input-group" hidden="hidden"></div>
        {% for translation in action_type_translations %}
          <div class="input-group" data-language-id="{{ translation.language.id }}">
            <input type="text" class="form-control" id="input-name-{{ translation.language.id }}" placeholder="{{ _('Name') }}" data-name="input-name" value="{{ translation.name }}" data-translation-attribute="name" data-empty-text="{{ _("Please enter a name.") }}" data-max-length="100" data-max-length-text="{{ _("Please enter a shorter name (at most 100 characters).") }}">
            <span class="input-group-addon language-addon" data-name="language">{{ translation.language.names | get_translated_text }}</span>
          </div>
          <span class="help-block" data-name="name" id="help-block-name-{{ translation.language_id }}" data-language-id="{{ translation.language.id }}"></span>
        {% endfor %}
      </div>

      <div class="form-group" data-name="input-descriptions">
        <div class="form-group" style="margin-bottom: 0">
          <label for="input-description" class="control-label">{{ _("Description") }}</label>
        </div>
        <div class="input-group" hidden="hidden"></div>
        {% for translation in action_type_translations %}
          <div class="input-group" data-language-id="{{ translation.language.id }}">
            <input type="text" class="form-control" id="input-description-{{ translation.language.id }}" placeholder="{{ _('Description') }}" data-name="input-description" value="{{ translation.description }}" data-translation-attribute="description">
            <span class="input-group-addon language-addon" data-name="language">{{ translation.language.names | get_translated_text }}</span>
          </div>
          <span class="help-block" data-name="name" id="help-block-description-{{ translation.language_id }}" data-language-id="{{ translation.language.id }}"></span>
        {% endfor %}
      </div>

      <div class="form-group" data-name="input-object-names-singular">
        <div class="form-group" style="margin-bottom: 0">
          <label for="input-object-name-singular" class="control-label">{{ _("Object Name (singular)") }}</label>
        </div>
        <div class="input-group" hidden="hidden"></div>
        {% for translation in action_type_translations %}
          <div class="input-group" data-language-id="{{ translation.language.id }}">
            <input type="text" class="form-control" id="input-object-name-singular-{{ translation.language.id }}" placeholder="{{ _('Object Name (singular)') }}" data-name="input-object-name-singular" value="{{ translation.object_name }}" data-translation-attribute="object_name" data-empty-text="{{ _("Please enter an object name (singular).") }}" data-max-length="100" data-max-length-text="{{ _("Please enter a shorter object name (singular) (at most 100 characters).") }}">
            <span class="input-group-addon language-addon" data-name="language">{{ translation.language.names | get_translated_text }}</span>
          </div>
          <span class="help-block" data-name="name" id="help-block-object-name-singular-{{ translation.language_id }}" data-language-id="{{ translation.language.id }}"></span>
        {% endfor %}
      </div>

      <div class="form-group" data-name="input-object-names-plural">
        <div class="form-group" style="margin-bottom: 0">
            <label for="input-object-name-plural" class="control-label">{{ _("Object Name (plural)") }}</label>
        </div>
        <div class="input-group" hidden="hidden"></div>
        {% for translation in action_type_translations %}
          <div class="input-group" data-language-id="{{ translation.language.id }}">
            <input type="text" class="form-control" id="input-object-name-plural-{{ translation.language.id }}" placeholder="{{ _('Object Name (plural)') }}" data-name="input-object-name-plural" value="{{ translation.object_name_plural }}" data-translation-attribute="object_name_plural" data-empty-text="{{ _("Please enter an object name (plural).") }}" data-max-length="100" data-max-length-text="{{ _("Please enter a shorter object name (plural) (at most 100 characters).") }}">
            <span class="input-group-addon language-addon" data-name="language">{{ translation.language.names | get_translated_text }}</span>
          </div>
          <span class="help-block" data-name="name" id="help-block-object-name-plural-{{ translation.language_id }}" data-language-id="{{ translation.language.id }}"></span>
        {% endfor %}
      </div>

      <div class="form-group" data-name="input-view-texts">
        <div class="form-group" style="margin-bottom: 0">
          <label for="input-view-text" class="control-label">{{ _("View Text") }}</label>
        </div>
        <div class="input-group" hidden="hidden"></div>
        {% for translation in action_type_translations %}
          <div class="input-group" data-language-id="{{ translation.language.id }}">
            <input type="text" class="form-control" id="input-view-text-{{ translation.language.id }}" placeholder="{{ _('Object Name (plural)') }}" data-name="input-view-text" value="{{ translation.view_text }}" data-translation-attribute="view_text" data-empty-text="{{ _("Please enter a view text.") }}" data-max-length="100" data-max-length-text="{{ _("Please enter a shorter view text (at most 100 characters).") }}">
            <span class="input-group-addon language-addon" data-name="language">{{ translation.language.names | get_translated_text }}</span>
          </div>
          <span class="help-block" data-name="name" id="help-block-view-text-{{ translation.language_id }}" data-language-id="{{ translation.language.id }}"></span>
        {% endfor %}
      </div>

      <div class="form-group" data-name="input-perform-texts">
        <div class="form-group" style="margin-bottom: 0">
          <label for="input-perform-text" class="control-label">{{ _("Perform Text") }}</label>
        </div>
        <div class="input-group" hidden="hidden"></div>
        {% for translation in action_type_translations %}
          <div class="input-group" data-language-id="{{ translation.language.id }}">
            <input type="text" class="form-control" id="input-perform-text-{{ translation.language.id }}" placeholder="{{ _('Object Name (plural)') }}" data-name="input-perform-text" value="{{ translation.perform_text }}" data-translation-attribute="perform_text" data-empty-text="{{ _("Please enter a perform text.") }}" data-max-length="100" data-max-length-text="{{ _("Please enter a shorter perform text (at most 100 characters).") }}">
            <span class="input-group-addon language-addon" data-name="language">{{ translation.language.names | get_translated_text }}</span>
          </div>
          <span class="help-block" data-name="name" id="help-block-perform-text-{{ translation.language_id }}" data-language-id="{{ translation.language.id }}"></span>
        {% endfor %}
      </div>

      <div class="checkbox">
        <label for="input-admin_only" style="font-weight:400">
          <input type="checkbox" id="input-admin_only" name="{{ action_type_form.admin_only.name }}"
                 {% if action_type_form.admin_only.data %}checked="checked"{% endif %}> {{ _('Only administrators can create actions of this type') }}
        </label>
      </div>
        <div class="checkbox">
          <label for="input-show_on_frontpage" style="font-weight:400">
            <input type="checkbox" id="input-show_on_frontpage"
                   name="{{ action_type_form.show_on_frontpage.name }}"
                   {% if action_type_form.show_on_frontpage.data %}checked="checked"{% endif %}> {{ _('Show this action type on the frontpage') }}
          </label>
        </div>
        <div class="checkbox">
          <label for="input-show_in_navbar" style="font-weight:400">
            <input type="checkbox" id="input-show_in_navbar" name="{{ action_type_form.show_in_navbar.name }}"
                   {% if action_type_form.show_in_navbar.data %}checked="checked"{% endif %}> {{ _('Show actions of this type in the navbar') }}
          </label>
          <span data-toggle="tooltip" data-placement="top" title="{{ _('Only action types with usable actions are shown in the navbar Actions drop-down menu') }}"><i class="fa fa-question-circle" aria-hidden="true"></i></span>
        </div>
        <div class="checkbox">
          <label for="input-show_in_object_filters" style="font-weight:400">
            <input type="checkbox" id="input-show_in_object_filters" name="{{ action_type_form.show_in_object_filters.name }}"
                   {% if action_type_form.show_in_object_filters.data %}checked="checked"{% endif %}> {{ _('Show action type in object filters') }}
          </label>
        </div>
        <div class="checkbox">
          <label for="input-enable_labels" style="font-weight:400">
            <input type="checkbox" id="input-enable_labels" name="{{ action_type_form.enable_labels.name }}"
                   {% if action_type_form.enable_labels.data %}checked="checked"{% endif %}> {{ _('Enable labels for objects created with actions of this type') }}
          </label>
        </div>
        <div class="checkbox">
          <label for="input-enable_files" style="font-weight:400">
            <input type="checkbox" id="input-enable_files" name="{{ action_type_form.enable_files.name }}"
                   {% if action_type_form.enable_files.data %}checked="checked"{% endif %}> {{ _('Enable files for objects created with actions of this type') }}
          </label>
        </div>
        <div class="checkbox">
          <label for="input-enable_locations" style="font-weight:400">
            <input type="checkbox" id="input-enable_locations"
                   name="{{ action_type_form.enable_locations.name }}"
                   {% if action_type_form.enable_locations.data %}checked="checked"{% endif %}> {{ _('Enable locations and responsible users for objects created with actions of this type') }}
          </label>
        </div>
        <div class="checkbox">
          <label for="input-enable_publications" style="font-weight:400">
            <input type="checkbox" id="input-enable_publications"
                   name="{{ action_type_form.enable_publications.name }}"
                   {% if action_type_form.enable_publications.data %}checked="checked"{% endif %}> {{ _('Enable publications for objects created with actions of this type') }}
          </label>
        </div>
        <div class="checkbox">
          <label for="input-enable_comments" style="font-weight:400">
            <input type="checkbox" id="input-enable_comments" name="{{ action_type_form.enable_comments.name }}"
                   {% if action_type_form.enable_comments.data %}checked="checked"{% endif %}> {{ _('Enable comments for objects created with actions of this type') }}
          </label>
        </div>
        <div class="checkbox">
          <label for="input-enable_activity_log" style="font-weight:400">
            <input type="checkbox" id="input-enable_activity_log"
                   name="{{ action_type_form.enable_activity_log.name }}"
                   {% if action_type_form.enable_activity_log.data %}checked="checked"{% endif %}> {{ _('Enable the activity log for objects created with actions of this type') }}
          </label>
        </div>
        <div class="checkbox">
          <label for="input-enable_related_objects" style="font-weight:400">
            <input type="checkbox" id="input-enable_related_objects"
                   name="{{ action_type_form.enable_related_objects.name }}"
                   {% if action_type_form.enable_related_objects.data %}checked="checked"{% endif %}> {{ _('Show related objects for objects created with actions of this type') }}
          </label>
        </div>
        <div class="checkbox">
          <label for="input-disable_create_objects" style="font-weight:400">
            <input type="checkbox" id="input-disable_create_objects" name="{{ action_type_form.disable_create_objects.name }}"
                 {% if action_type_form.disable_create_objects.data %}checked="checked"{% endif %}> {{ _('Disable creating objects of this action type') }}
          </label>
        </div>
        <div class="checkbox">
          <label for="input-is_template" style="font-weight:400">
            <input type="checkbox" id="input-is_template" name="{{ action_type_form.is_template.name }}"
                 {% if action_type_form.is_template.data %}checked="checked"{% endif %}> {{ _('Allow actions of this type as schema templates in other actions') }}
          </label>
        </div>
        <div class="checkbox">
          <label for="input-enable_project_link" style="font-weight:400">
            <input type="checkbox" id="input-enable_project_link" name="{{ action_type_form.enable_project_link.name }}"
                   {% if action_type_form.enable_project_link.data %}checked="checked"{% endif %}> {{ _('Enable linking objects created with actions of this type to project groups') }}
          </label>
        </div>
        <div class="checkbox">
          <label for="input-enable_instrument_link" style="font-weight:400">
            <input type="checkbox" id="input-enable_instrument_link" name="{{ action_type_form.enable_instrument_link.name }}"
                   {% if action_type_form.enable_instrument_link.data %}checked="checked"{% endif %}> {{ _('Enable linking objects created with actions of this type to instruments') }}
          </label>
        </div>
        <div class="form-group">
          <div class="form-group" style="margin-bottom: 0">
              <label for="select-usable_in_action_types-input" class="control-label">{{ _("Usable in")}}</label>
          </div>
          <select title="{{ _('Nothing selected') }}" id="select-select_usable_in_action_types-input" name="{{ action_type_form.select_usable_in_action_types.name }}" class="selectpicker" multiple> 
            {% for value, label in action_type_form.select_usable_in_action_types.choices %}
            <option value="{{value}}" {% if value in action_type_form.select_usable_in_action_types.shared_action_types %} data-icon="fa fa-share-alt" {% endif %} {% if action_type_form.select_usable_in_action_types.data and value in action_type_form.select_usable_in_action_types.data %} selected="selected" {% endif %}>{{ label }}</option>
            {% endfor %}
          </select>
        </div>
        <div class="form-group">
          <div class="form-group" style="margin-bottom: 0">
            <label for="select-scicat_export-type" class="control-label">{{ _("SciCat Export Type") }}</label>
          </div>
          <select id="select-scicat_export-type" name="{{ action_type_form.scicat_export_type.name }}" class="selectpicker">
            {% for value, label in action_type_form.scicat_export_type.choices %}
            <option value="{{ value }}" {% if action_type_form.scicat_export_type.data == value %} selected="selected"{% endif %}>{{ label }}</option>
            {% endfor %}
          </select>
        </div>
      </div>
    <div class="form-group row clearfix" style="padding-right:0.75em">
      <div class="col-md-3 col-md-offset-6">
        <a href="{{ url_for('.action_types') }}" class="btn btn-default pull-right" style="width:20em">{{ _('Cancel') }}</a>
      </div>
      <div class="col-md-3">
        <button type="submit" name="action_submit" class="btn btn-primary pull-right" style="width:20em">{{ submit_text }}</button>
      </div>
    </div>
  </form>
{% endblock %}
