{% extends "base.html" %}

{% block title %}Object #{{ object_id }}: {{ data['name']['text'] }} — {{ service_name }}{% endblock %}

{% block head %}
  {{ super() }}
  <link rel="meta" type="application/rdf+xml" href="{% if link_version_specific_rdf %}{{ url_for('.object_rdf', object_id=object_id, version_id=version_id) }}{% else %}{{ url_for('.object_rdf', object_id=object_id) }}{% endif %}" />
{% endblock %}

{% block stylesheets %}
  {{ super() }}
    <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-datetimepicker.min.css') }}" />
    <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-select.min.css') }}" />
    <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-treeview.min.css') }}" />
{% endblock %}

{% block content %}

  {% if is_archived %}
  <div class="alert alert-info alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <strong>Note:</strong> This is an archived version of the object information. For the current information, <a href="{{ url_for('frontend.object', object_id=object_id) }}">click here</a>.
  </div>
  {% endif %}

  <h3>{{ object_type }} #{{ object_id }}: {{ data['name']['text'] }}</h3>

  <h4>Information</h4>
  <div class="row" style="padding-right:0.75em">
    <label class="col-md-3" style="text-align: right">Instrument <i class="fa fa-search" style="visibility:hidden" aria-hidden="true"></i></label>
    <div class="col-md-9">{% if instrument is not none %}<a href="{{ url_for('frontend.instrument', instrument_id=instrument.id) }}">{{ instrument.name }}</a>{% else %}&mdash;{% endif %}</div>
  </div>
  <div class="row" style="padding-right:0.75em">
    <label class="col-md-3" style="text-align: right">Action <a href="{{ url_for('.objects', action=action.id) }}" class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a></label>
    <div class="col-md-9"><a href="{{ url_for('frontend.action', action_id=action.id) }}">{{ action.name }}</a></div>
  </div>
  {% include "objects/view/any.html" %}
  <div class="object-button-bar">
  {% if not is_archived %}
    {% if not current_user.is_readonly %}
    {% if user_may_edit %}
    <div class="form-group">
      <a href="{{ url_for('.object', object_id=object_id, mode='edit') }}" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="Create a new version of the information for this object."><i class="fa fa-pencil" aria-hidden="true"></i> Edit Object</a>
    </div>
    {% endif %}
    {% if user_may_edit and new_schema_available %}
    <div class="form-group">
      <a href="{{ url_for('.object', object_id=object_id, mode='upgrade') }}" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="Update the schema for the information for this object."><i class="fa fa-arrow-circle-o-up" aria-hidden="true"></i> Update Schema</a>
    </div>
    {% endif %}
    {% if user_may_grant %}
    <div class="form-group">
      <a href="{{ url_for('.object_permissions', object_id=object_id) }}" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="Modify who can read the information for this object, write it or grant permissions to other users."><i class="fa fa-lock" aria-hidden="true"></i> Edit Permissions</a>
    </div>
    {% endif %}
    {% if user_may_use_as_template %}
    <div class="form-group">
      <a href="{{ url_for('.new_object', previous_object_id=object_id) }}" class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="Create a new object based on the information for this object."><i class="fa fa-files-o" aria-hidden="true"></i> Use as Template</a>
    </div>
    {% endif %}
    {% if object_type.lower() == 'sample' %}
    <div class="form-group">
      <div class="btn-group" data-toggle="tooltip" data-placement="top" title="Create a new measurement using this sample.">
        <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-bar-chart" aria-hidden="true"></i> Use in Measurement <span class="caret"></span></button>
        <ul class="dropdown-menu dropdown-menu-right">
          <li><strong style="padding: 3px 20px">Favorites:</strong></li>
          {% if favorite_measurement_actions %}
          {% for action in favorite_measurement_actions %}
          <li>
            <a href="{{ url_for('.new_object', action_id=action.id, sample_id=object_id) }}">
            {% if action.user is not none %}
              {{ action.user.name }} /
            {% endif %}
            {% if action.instrument is not none %}
              {{ action.instrument.name }} &mdash;
            {% endif %}
              {{ action.name }}
            </a>
          </li>
          {% endfor %}
          {% else %}
          <li><span style="padding: 3px 20px">&mdash;</span></li>
          {% endif %}
          <li role="separator" class="divider"></li>
          <li><a href="{{ url_for('.actions', t='measurements', sample_id=object_id) }}">See other Measurement Actions...</a></li>
        </ul>
      </div>
    </div>
    {% endif %}
    {% endif %}
    {% if action.type.enable_labels %}
    <div class="form-group">
      <button type="button" class="btn btn-primary" id="button-show-object-label-modal" data-toggle="tooltip" data-placement="top" title="Generate a PDF containing labels for this object."><i class="fa fa-tag" aria-hidden="true"></i> Generate Labels</button>
    </div>
    {% endif %}
    <div class="form-group">
      <button type="button" class="btn btn-primary" id="button-show-object-qrcode-modal" data-toggle="tooltip" data-placement="top" title="Show a QR code for a link to this object."><i class="fa fa-qrcode" aria-hidden="true"></i> Show QR Code</button>
    </div>
    <div class="form-group">
      <div data-toggle="tooltip" data-placement="top" title="Export object information to an archive or PDF file."><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#dataExportModal"><i class="fa fa-file-text-o" aria-hidden="true"></i> Export Data</button></div>
    </div>
    {% if notebook_templates and jupyterhub_templates_url %}
      <div class="form-group">
        <div class="btn-group" data-toggle="tooltip" data-placement="top" title="Create a Jupyter Notebook in {{ jupyterhub_name }} to analyze this object.">
          <button class="btn btn-primary dropdown-toggle" type="button" id="notebookDropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <img src="{{ url_for("static", filename="img/jupyter-40.png") }}" style="height:1.3em; margin-top:-0.2em; margin-right: -0.2em;" alt=""/> Create Notebook <span class="caret"></span>
          </button>
          <ul class="dropdown-menu" aria-labelledby="notebookDropdownMenuButton">
            {% for notebook_template in notebook_templates %}
              <li>
                <form action="{{ jupyterhub_templates_url }}/t/{{ notebook_template.url }}" method="post">
                <input type="hidden" name="params" value='{{ notebook_template.params | tojson }}'>
                <input type="submit" value="{{ notebook_template.title }}" class="btn btn-link dropdown-menu-button" />
                </form>
              </li>
            {% endfor %}
          </ul>
        </div>
      </div>
    {% endif %}
  {% endif %}
    {% if restore_form is not none %}
    <div class="form-group">
      <form class="text-center" action="{{ url_for('.restore_object_version', object_id=object_id, version_id=version_id) }}" method="post">
        {{ restore_form.csrf_token() }}
        <button type="submit" class="btn btn-primary"><i class="fa fa-undo" aria-hidden="true"></i> Restore Version</button>
      </form>
    </div>
    {% endif %}
  </div>

  {% if not is_archived %}
    {% if action.type.enable_files %}
    <h4>Files</h4>
    {% if files %}
    <table class="table" id="file_table">
      <thead>
        <tr>
          <th scope="col" style="white-space: nowrap;width: 1%;"></th>
          <th scope="col">Title</th>
          <th scope="col" class="text-right" style="white-space: nowrap;width: 1%;">
            <button type="button" class="btn btn-sm btn-primary" data-container="body" data-toggle="popover" data-placement="left" data-html="true" data-content="
              <label style='font-weight:400'><input type='checkbox' id='file_table_filter_notebooks' onclick='file_table_toggle($(this).is(&quot;:checked&quot;), &quot;notebooks&quot;);'/> Notebooks</label><br />
              <label style='font-weight:400'><input type='checkbox' id='file_table_filter_other' onclick='file_table_toggle($(this).is(&quot;:checked&quot;), &quot;other&quot;);' /> Other Files</label><br />
              <script>
                window.update_file_table_filter_states();
              </script>
            " style="display: none">
              <i class="fa fa-filter" style="font-size: 1.5rem"></i> <span class="badge" id="file_table_counter"></span>
            </button>
            <a href="{{ url_for('.object_files', object_id=object_id) }}" class="btn btn-link" style="padding-top:0;padding-bottom:0;" data-toggle="tooltip" data-placement="top" title="Download files as zip archive"><i class="fa fa-download"></i></a>
          </th>
        </tr>
      </thead>
      <tbody>
      {% for file in files %}
        {% if not file.is_hidden %}
        <tr id="file-{{ file.id }}">
          <td style="white-space: nowrap;width: 1%;">{% if file | is_image %}
            <img src="{{ url_for('.object_file', object_id=object_id, file_id=file.id) }}?preview" alt="{{ file.title }}" style="max-width:100px; max-height:100px;" class="show-fullscreen-image-preview"/>
            <span class="fullscreen-image-preview">
              <span class="close-fullscreen-image-preview"><i class="fa fa-close fa-fw"></i></span>
              <a href="{{ url_for('.object_file', object_id=object_id, file_id=file.id) }}">
                <span class="download-fullscreen-image-preview"><i class="fa fa-download fa-fw"></i></span>
              </a>
              <img src="{{ url_for('.object_file', object_id=object_id, file_id=file.id) }}?preview" alt="Fullscreen Image Preview">
            </span>{% endif %}
          </td>
          <td>
            {{ file.title }}
            {% if file.description %}
<span class="file-description">
{{ file.description }}</span>
            {% endif %}
          </td>
          <td>
            <span class="pull-right" style="display:flex;">
              <button type="button" class="btn btn-link button-file-info" style="padding-top:0;padding-bottom:0;" data-file_id="{{ file.id }}" data-toggle="tooltip" data-placement="top" title="View information"><i class="fa fa-info"></i></button>
              {% if file.storage == 'local' %}
              {% if file | has_preview %}
              <a href="{{ url_for('.object_file', object_id=object_id, file_id=file.id) }}?preview" class="btn btn-link" style="padding-top:0;padding-bottom:0;" data-toggle="tooltip" data-placement="top" title="View preview"><i class="fa fa-search"></i></a>
              {% else %}
              <a href="{{ url_for('.object_file', object_id=object_id, file_id=file.id) }}?preview" class="btn btn-link" style="padding-top:0;padding-bottom:0;visibility: hidden"><i class="fa fa-search"></i></a>
              {% endif %}
              <a href="{{ url_for('.object_file', object_id=object_id, file_id=file.id) }}" class="btn btn-link" style="padding-top:0;padding-bottom:0;" data-toggle="tooltip" data-placement="top" title="Download file"><i class="fa fa-download"></i></a>
              {% elif file.storage == 'url' %}
              <span data-placement="top" data-trigger="manual" title="Copied successfully"><span data-url="{{ file.data['url'] }}" class="btn btn-link copy-external-link" style="padding-top:0;padding-bottom:0;" data-toggle="tooltip" data-placement="top" title="Copy address to clipboard"><i class="fa fa-clipboard"></i></span></span>
              <a href="{{ file.data['url'] }}" class="btn btn-link" style="padding-top:0;padding-bottom:0;" data-toggle="tooltip" data-placement="top" title="Open external link"><i class="fa fa-external-link"></i></a>
              {% endif %}
            </span>
          </td>
        </tr>
        {% else %}
        <tr>
          <td style="white-space: nowrap;width: 1%;"></td>
          <td>&mdash;</td>
          <td>
            <span class="pull-right" style="display:flex;">
              <button type="button" class="btn btn-link button-file-info" style="padding-top:0;padding-bottom:0;" data-file_id="{{ file.id }}"><i class="fa fa-question"></i></button>
            </span>
          </td>
        </tr>
        {% endif %}
      {% endfor %}
      </tbody>
    </table>
    {% else %}
      <p>There are no files for this {{ object_type.lower() }}.</p>
    {% endif %}

    {% for file in files %}
    {% if file.is_hidden %}
    <div class="modal fade modal-file-info" id="fileInfoModal-{{ file.id }}" tabindex="-1" role="dialog" aria-labelledby="fileInfoModalLabel-{{ file.id }}">
      <div class="modal-dialog" role="document">
        <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="fileInfoModalLabel-{{ file.id }}">Hidden File Information</h4>
            </div>
            <div class="modal-body">
              {% if file.hide_reason %}
              This file has been hidden for the following reason:
              <pre style="font-family: inherit">{{ file.hide_reason }}</pre>
              {% else %}
              This file has been hidden.
              {% endif %}
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
      </div>
    </div>
    {% endif %}
    {% endfor %}

    {% for file in files %}
    {% if not file.is_hidden %}
    <div class="modal fade modal-file-info" id="fileInfoModal-{{ file.id }}" tabindex="-1" role="dialog" aria-labelledby="fileInfoModalLabel-{{ file.id }}">
      <div class="modal-dialog" role="document">
        <div class="modal-content file-info-main">
          <form method="post" action="{{ url_for('.update_file_information', object_id=object_id, file_id=file.id) }}">
          {{ file_information_form.csrf_token() }}
            <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="fileInfoModalLabel-{{ file.id }}">File Information</h4>
            </div>
            <div class="modal-body">
            <div class="row">
              <div class="col-sm-3 text-right"><label>Title:</label></div>
              <div class="col-sm-9"><span class="file-info-view-mode">{% if file.title %}{{ file.title }}{% else %}&mdash;{% endif %}</span><span class="file-info-edit-mode"><input type="text" name="{{ file_information_form.title.name }}" class="input-file-info-title" style="width:100%" value="{% if file.title %}{{ file.title }}{% endif %}"></span></div>
            </div>
            {% if file.storage == 'local' %}
            <div class="row">
              <div class="col-sm-3 text-right"><label>Name:</label></div>
              <div class="col-sm-9">{{ file.original_file_name }}</div>
            </div>
            <div class="row">
              <div class="col-sm-3 text-right"><label>Uploaded by:</label></div>
              <div class="col-sm-9"><a href="{{ url_for('.user_profile', user_id=file.uploader.id) }}">{{ file.uploader.name }}</a></div>
            </div>
            {% elif file.storage == 'url' %}
            <div class="row">
              <div class="col-sm-3 text-right"><label>URL:</label></div>
              <div class="col-sm-9">{{ file.data.url }}</div>
            </div>
            <div class="row">
              <div class="col-sm-3 text-right"><label>Linked by:</label></div>
              <div class="col-sm-9"><a href="{{ url_for('.user_profile', user_id=file.uploader.id) }}">{{ file.uploader.name }}</a></div>
            </div>
            {% else %}
            <div class="row">
              <div class="col-sm-3 text-right"><label>Posted by:</label></div>
              <div class="col-sm-9"><a href="{{ url_for('.user_profile', user_id=file.uploader.id) }}">{{ file.uploader.name }}</a></div>
            </div>
            {% endif %}
            <div class="row">
              <div class="col-sm-3 text-right"><label>Description:</label></div>
              <div class="col-sm-9"><span class="file-info-view-mode">{% if file.description %}<pre style="font-family: inherit">{{ file.description }}</pre>{% else %}&mdash;{% endif %}</span><span class="file-info-edit-mode"><textarea name="{{ file_information_form.description.name }}"class="input-file-info-description" style="width:100%;resize: vertical;">{% if file.description %}{{ file.description }}{% endif %}</textarea></span></div>
            </div>
            <div class="row">
              <div class="col-sm-3 text-right"><label>History:</label></div>
              <div class="col-sm-9"><a role="button" data-toggle="collapse" href="#fileInfoModalCollapse-{{ file.id }}" aria-expanded="false" aria-controls="fileInfoModalCollapse-{{ file.id }}">Show/Hide</a></div>
            </div>
            <div class="collapse" id="fileInfoModalCollapse-{{ file.id }}">
              <table class="table">
                <thead>
                  <tr>
                    <th scope="col" style="white-space: nowrap;width: 1%;">Datetime</th>
                    <th scope="col"></th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td>{{ file.utc_datetime.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                    <td><a href="{{ url_for('.user_profile', user_id=file.uploader.id) }}">{{ file.uploader.name }}</a> has uploaded the file.</td>
                  </tr>
                  {% for log_entry in file.log_entries %}
                    {% if log_entry.type == FileLogEntryType.EDIT_TITLE %}
                      <tr>
                        <td>{{ log_entry.utc_datetime.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                        <td><a href="{{ url_for('.user_profile', user_id=log_entry.user.id) }}">{{ log_entry.user.name }}</a> updated the title to:<br />{{ log_entry.data['title'] }}</td>
                      </tr>
                    {% elif log_entry.type == FileLogEntryType.EDIT_DESCRIPTION %}
                      <tr>
                        <td>{{ log_entry.utc_datetime.strftime('%Y-%m-%d %H:%M:%S') }}</td>
                        <td><a href="{{ url_for('.user_profile', user_id=file.uploader.id) }}">{{ log_entry.user.name }}</a> updated the description to: <pre style="font-family: inherit">{{ log_entry.data['description'] }}</pre></td>
                      </tr>
                    {% else %}
                      <tr>{{ log_entry.type }}</tr>
                    {% endif %}
                  {% endfor %}
                </tbody>
              </table>
            </div>
            </div>
            <div class="modal-footer">
              {% if user_may_edit %}
              <button type="submit" class="btn btn-primary file-info-edit-mode">Save</button>
              <button type="button" class="btn btn-default file-info-edit-mode button-file-info-cancel">Cancel</button>
              <button type="button" class="btn btn-primary file-info-view-mode button-file-info-edit">Edit</button>
              <button type="button" class="btn btn-default file-info-view-mode button-file-info-hide">Hide</button>
              {% endif %}
              {% if file.storage == 'local' %}
              <a href="{{ url_for('.object_file', object_id=object_id, file_id=file.id) }}" class="btn btn-default file-info-view-mode">Download</a>
              {% endif %}
              <button type="button" class="btn btn-default file-info-view-mode" data-dismiss="modal">Close</button>
            </div>
          </form>
        </div>
        <div class="modal-content file-info-hide">
          <form method="post" action="{{ url_for('.hide_file', object_id=object_id, file_id=file.id) }}">
          {{ file_hiding_form.csrf_token() }}
            <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">Hide File</h4>
            </div>
            <div class="modal-body">
              <div class="form-group">
                <label>Reason:</label>
                <textarea class="form-control" rows="3" name="{{ file_hiding_form.reason.name }}" title="Reason"></textarea>
              </div>
              <strong>Note</strong>: Other users will still see that a file has been hidden. The file may be restored by an administrator upon request.
            </div>
            <div class="modal-footer">
              <button type="submit" class="btn btn-danger">Hide</button>
              <button type="button" class="btn btn-default button-file-info-hide-cancel">Cancel</button>
            </div>
          </form>
        </div>
      </div>
    </div>
    {% endif %}
    {% endfor %}

    {% if user_may_edit %}
    <h5>Upload File</h5>
    <div class="form-group row clearfix" style="padding-right:0.75em">
      <div class="col-md-12">
            <form class="form" method="post" action="{{ url_for('.post_object_files', object_id=object_id) }}" enctype="multipart/form-data">
              <div class="input-group" id="upload-area">
                <span class="input-group-addon"><i class="fa fa-file"></i></span>
                <input id="input-file-text" type="text" class="form-control disabled" disabled />
                <span class="input-group-btn">
                  <input type="hidden" value="" id="input-file-names-hidden" name="{{ file_form.file_names.name }}" />
                  <input type="hidden" value="" id="input-file-source-hidden" name="{{ file_form.file_source.name }}" />
                  {{ file_form.csrf_token }}
                  <div class="btn-group" style="z-index: 3">
                    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="width:10em;">
                    <i class="fa fa-folder-open"></i> Browse... <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                      <li>
                        <label class="btn btn-link btn-file" style="color:#333333;"><i class="fa fa-hdd-o fa-fw"></i> Local files<input id="input-file-upload" type="file" name="{{ file_form.local_files.name }}" multiple style="display: none;"></label>
                      </li>
                      <li role="separator" class="divider"></li>
                      <li>
                        <button type="button" class="btn btn-link" style="color:#333333;" id="button-show-mobile-file-upload-modal"><i class="fa fa-mobile-phone fa-fw"></i> Smartphone</button>
                      </li>
                    </ul>
                  </div>
                  <button type="submit" class="btn btn-primary disabled" style="width:10em;" id="button-upload-files"><i class="fa fa-upload fa-fw"></i> Upload</button>
                </span>
              </div>
            </form>
      </div>
    </div>

    <div class="modal fade" id="mobileFileLinkModal" tabindex="-1" role="dialog" aria-labelledby="mobileFileLinkModalLabel">
      <div class="modal-dialog" role="document">
        <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="mobileFileLinkModalLabel">Mobile File Upload</h4>
          </div>
          <div class="modal-body">
            <p class="text-center">To upload files from mobile devices, scan this QR code:</p>
            <a href="{{ mobile_upload_url }}"><img src="{{ mobile_upload_qrcode }}" alt="{{ mobile_upload_url }}" style="width: 100%"/></a>
          </div>
        </div>
      </div>
    </div>

    <h5 id="anchor-post-link">Post Link</h5>
    <div class="form-group" style="padding-right:0.75em">
      <form class="form {% if external_link_invalid %}has-error{% endif %}" method="post" action="{{ url_for('.post_object_files', object_id=object_id) }}">
        {{ external_link_form.csrf_token }}
        <div class="input-group">
          <span class="input-group-addon"><i class="fa fa-link"></i></span>
          <input name="url" type="text" class="form-control" required="required" />
          <span class="input-group-btn">
            <button type="submit" class="btn btn-primary" style="width:10em;"><i class="fa fa-link fa-fw"></i> Submit</button>
          </span>
        </div>
        {% if external_link_invalid %}
          <div class="help-block">Please enter a valid URL.</div>
        {% endif %}
      </form>
    </div>
    {% endif %}
    {% endif %}
  {% endif %}

    {% if action.type.enable_labels %}
    <div class="modal fade" id="objectLabelModal" tabindex="-1" role="dialog" aria-labelledby="objectLabelModalLabel">
      <div class="modal-dialog" role="document">
        <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="objectLabelModalLabel">Generate Labels</h4>
          </div>
          <form method="get" action="{{ url_for('.print_object_label', object_id=object_id) }}" class="form-horizontal" onsubmit="return validateLabelsForm()" id="form-generate-labels">
          <div class="modal-body">
              <div class="radio">
                <label class="control-label"><input type="radio" name="mode" value="mixed" checked="checked" onchange="updateLabelsForm()"/>Mixed label formats</label>
              </div>
              <span class="help-block">This will generate labels in a selection of predefined formats. To request adding a new format, please <a href="mailto:{{ config['CONTACT_EMAIL'] }}">contact an administrator</a>.</span>
              <div class="form-group">
                <label for="input-label-mixed-paper-format" class="control-label col-sm-4">Paper Size</label>
                <div class="col-sm-8">
                <select class="selectpicker form-control" id="input-label-mixed-paper-format" name="mixed-paper-format">
                  <option value="DIN A4 (Portrait)" selected="selected">DIN A4 (Portrait)</option>
                  <option value="DIN A4 (Landscape)">DIN A4 (Landscape)</option>
                  <option value="Letter (Portrait)">Letter / ANSI A (Portrait)</option>
                  <option value="Letter (Landscape)">Letter / ANSI A (Landscape)</option>
                </select>
                </div>
              </div>
              <hr />
              <div class="radio">
                <label class="control-label"><input type="radio" name="mode" value="fixed-width" onchange="updateLabelsForm()"/>Fixed-width labels</label>
              </div>
              <span class="help-block">This will generate vertically oriented labels with a fixed-width and an optional minimum height.</span>
              <div class="form-group">
                <label for="input-label-width-paper-format" class="control-label col-sm-4">Paper Size</label>
                <div class="col-sm-8">
                <select class="selectpicker form-control" id="input-label-width-paper-format" name="width-paper-format">
                  <option value="DIN A4 (Portrait)" selected="selected">DIN A4 (Portrait)</option>
                  <option value="DIN A4 (Landscape)">DIN A4 (Landscape)</option>
                  <option value="Letter (Portrait)">Letter / ANSI A (Portrait)</option>
                  <option value="Letter (Landscape)">Letter / ANSI A (Landscape)</option>
                </select>
                <span class="help-block"></span>
                </div>
              </div>
              <div class="form-group">
                <label for="input-width" class="col-sm-4 control-label">Label Width:</label>
                <div class="col-sm-8">
                  <div class="input-group">
                    <input type="text" class="form-control" aria-label="Label Width" value="40" name="label-width" id="input-width">
                    <span class="input-group-addon">mm</span>
                  </div>
                  <span class="help-block"></span>
                </div>
              </div>
              <div class="form-group">
                <label for="input-minimum-height" class="col-sm-4 control-label">Minimum Label Height:</label>
                <div class="col-sm-8">
                  <div class="input-group">
                    <input type="text" class="form-control" aria-label="Minimum Label Height" value="0" name="label-minimum-height" id="input-minimum-height">
                    <span class="input-group-addon">mm</span>
                  </div>
                  <span class="help-block"></span>
                </div>
              </div>
              <div class="form-group">
                <div class="col-sm-offset-4 col-sm-8">
                  <div class="checkbox">
                    <label>
                      <input type="checkbox" name="side-by-side"> QR Code and GHS symbols side-by-side
                    </label>
                  </div>
                </div>
              </div>
              <div class="form-group">
                <div class="col-sm-offset-4 col-sm-8">
                  <div class="checkbox">
                    <label>
                      <input type="checkbox" name="centered" checked="checked"> Center QR Code and GHS symbols
                    </label>
                  </div>
                </div>
              </div>
              <hr />
              <div class="radio">
                <label class="control-label"><input type="radio" name="mode" value="minimum-height" onchange="updateLabelsForm()"/>Minimal-height labels</label>
              </div>
              <span class="help-block">This will generate vertically oriented labels with a height as low as possible and an optional minimum width.</span>
              <div class="form-group">
                <label for="input-label-height-paper-format" class="control-label col-sm-4">Paper Size</label>
                <div class="col-sm-8">
                <select class="selectpicker form-control" id="input-label-height-paper-format" name="height-paper-format">
                  <option value="DIN A4 (Portrait)" selected="selected">DIN A4 (Portrait)</option>
                  <option value="DIN A4 (Landscape)">DIN A4 (Landscape)</option>
                  <option value="Letter (Portrait)">Letter / ANSI A (Portrait)</option>
                  <option value="Letter (Landscape)">Letter / ANSI A (Landscape)</option>
                </select>
                </div>
              </div>
              <div class="form-group">
                <label for="input-minimum-width" class="col-sm-4 control-label">Minimum Label Width:</label>
                <div class="col-sm-8">
                  <div class="input-group">
                    <input type="text" class="form-control" aria-label="Minimum Label Width" value="0" name="label-minimum-width" id="input-minimum-width">
                    <span class="input-group-addon">mm</span>
                  </div>
                  <span class="help-block"></span>
                </div>
              </div>
              <div class="form-group">
                <div class="col-sm-offset-4 col-sm-8">
                  <div class="checkbox">
                    <label>
                      <input type="checkbox" name="include-qrcode"> Include QR Code
                    </label>
                  </div>
                </div>
              </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
            <button class="btn btn-primary" type="submit">Generate Labels</button>
          </div>
          </form>
        </div>
      </div>
    </div>
  {% endif %}
  {% if object_qrcode %}
    <div class="modal fade" id="mobileObjectLinkModal" tabindex="-1" role="dialog" aria-labelledby="mobileObjectLinkModalLabel">
      <div class="modal-dialog" role="document">
        <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="mobileObjectLinkModalLabel">Object QR Code</h4>
          </div>
          <div class="modal-body">
            <p class="text-center">To view this object in the future, scan this QR code:</p>
            <a href="{{ object_qrcode }}"><img src="{{ object_qrcode }}" alt="{{ object_url }}" style="width: 100%"/></a>
          </div>
        </div>
      </div>
    </div>
  {% endif %}

  {% if not is_archived and action.type.enable_locations %}
  <h4 id="locations">Location</h4>
  {% if object_location_assignments %}
    <table class="table">
    <thead>
    <tr>
      <th>Datetime</th><th>Location</th><th>Responsible User</th><th>Assigning User</th><th>Description</th>
    </tr>
    </thead>
    <tbody>
    {% for object_location_assignment in object_location_assignments | reverse %}
      <tr>
        <td>{{ object_location_assignment.utc_datetime.strftime('%Y-%m-%d %H:%M:%S') }}</td>
        <td>{% if object_location_assignment.location_id is not none %}<a href="{{ url_for('frontend.location', location_id=object_location_assignment.location_id) }}">{{ get_location(object_location_assignment.location_id).name }} (#{{ object_location_assignment.location_id }})</a>{% else %}&mdash;{% endif %}</td>
        <td>
          {% if object_location_assignment.responsible_user_id is not none %}
          <a href="{{ url_for('frontend.user_profile', user_id=object_location_assignment.responsible_user_id) }}">{{ get_user(object_location_assignment.responsible_user_id).name }}</a>
            {% if object_location_assignment.confirmed %}
              <span class="label label-primary label-responsibility-assigment" data-toggle="tooltip" data-placement="top" title="The user has confirmed this responsibility assignment.">&check;</span>
            {% elif object_location_assignment.responsible_user_id == current_user.id %}
              <a class="btn btn-xs btn-primary" href="{{ build_object_location_assignment_confirmation_url(object_location_assignment.id) }}">Confirm</a>
            {% else %}
              <span class="label label-warning label-responsibility-assigment" data-toggle="tooltip" data-placement="top" title="The user has not confirmed this responsibility assignment yet.">?</span>
            {% endif %}
          {% else %}
            &mdash;
          {% endif %}
        </td>
        <td><a href="{{ url_for('frontend.user_profile', user_id=object_location_assignment.user_id) }}">{{ get_user(object_location_assignment.user_id).name }}</a></td>
        <td><pre class="location-description">{{ object_location_assignment.description }}</pre></td>
      </tr>
    {% endfor %}
    </tbody>
    </table>
  {% else %}
    This object has not been assigned to a location yet.
  {% endif %}
  {% if user_may_assign_location %}
    <form class="form" method="post" action="{{ url_for('frontend.post_object_location', object_id=object_id) }}" id="assign-location-form">
      {{ location_form.csrf_token }}
      <div class="form-group {% if location_form.location.name in location_form.errors %}has-error{% endif %}">
        <label for="input-location" class="control-label">Location</label>
        <select class="selectpicker form-control" id="input-location" name="{{ location_form.location.name }}" data-live-search="true">
          {% for location_id, location_name in location_form.location.choices %}
          <option value="{{ location_id }}" {% if location_form.location.data == location_id %}selected="selected"{% endif %}>{% if location_id == '-1' %}&mdash;{% else %}{{ location_name }}{% endif %}</option>
          {% endfor %}
        </select>
      </div>
      <div class="form-group {% if location_form.responsible_user.name in location_form.errors %}has-error{% endif %}">
        <label for="input-responsible-user" class="control-label">Responsible User</label>
        <select class="selectpicker form-control" id="input-responsible-user" name="{{ location_form.responsible_user.name }}" data-live-search="true">
          {% for user_id, user_name in location_form.responsible_user.choices %}
          <option value="{{ user_id }}" {% if location_form.responsible_user.data == user_id %}selected="selected"{% endif %}>{% if user_id == '-1' %}&mdash;{% else %}{{ user_name }}{% endif %}</option>
          {% endfor %}
        </select>
      </div>
      <div class="form-group {% if location_form.description.name in location_form.errors %}has-error{% endif %}">
        <label for="input-location" class="control-label">Description</label>
        <textarea class="form-control" rows="3" placeholder="Description" style="resize:vertical; min-height:2.5em; margin-bottom: 10px;" name="{{ location_form.description.name }}">{% if location_form.description.data %}{{ location_form.description.data }}{% endif %}</textarea>
      </div>
      <div class="text-right">
        <button type="submit" class="btn btn-primary" style="width:11em; margin-bottom: 20px;"><i class="fa fa-map-marker fa-fw"></i> Assign Location</button>
      </div>
    </form>
  {% endif %}
  {% endif %}

  {% if not is_archived and action.type.enable_publications %}
  <h4 id="publications">Publications</h4>
  {% if object_publications %}
    <table class="table">
    <thead>
    <tr>
      <th scope="col" style="white-space: nowrap;width: 1%;">DOI</th>
      <th scope="col">Title</th>
      <th scope="col">Object Name</th>
      <th scope="col" class="text-right" style="white-space: nowrap;width: 1%;"></th>
    </tr>
    </thead>
    <tbody>
    {% for object_publication in object_publications %}
      <tr>
        <td><a href="http://doi.org/{{ object_publication.doi | urlencode }}">{{ object_publication.doi }}</a></td>
        <td>{% if object_publication.title is none %}&mdash;{% else %}{{ object_publication.title }}{% endif %}</td>
        <td>{% if object_publication.object_name is none %}&mdash;{% else %}{{ object_publication.object_name }}{% endif %}</td>
        <td><a href="{{ url_for('.objects', doi=object_publication.doi) }}">View&nbsp;Objects</a></td>
      </tr>
    {% endfor %}
    </tbody>
    </table>
  {% else %}
    <p>This object has not been linked to a publication yet.</p>
  {% endif %}
  {% if user_may_link_publication %}
    {% for message in get_flashed_messages() %}
    {% if 'Please enter a valid DOI' in message %}
      {{ publication_form.errors.__setitem__(publication_form.doi.name, 'Please enter a valid DOI.') or '' }}
    {% endif %}
    {% endfor %}
    <form class="form" method="post" action="{{ url_for('frontend.post_object_publication', object_id=object_id) }}" id="assign-publication-form">
      {{ publication_form.csrf_token }}
      <div class="form-group {% if publication_form.doi.name in publication_form.errors %}has-error{% endif %}">
        <label for="input-location" class="control-label">DOI</label>
        <input type="text" class="form-control" placeholder="DOI" style="margin-bottom: 10px;" name="{{ publication_form.doi.name }}" value="{% if publication_form.doi.data %}{{ publication_form.doi.data }}{% endif %}"/>
        {% if publication_form.doi.name in publication_form.errors %}
          <span class="help-block">{{ publication_form.errors[publication_form.doi.name] }}</span>
        {% endif %}
      </div>
      <div class="form-group {% if publication_form.title.name in publication_form.errors %}has-error{% endif %}">
        <label for="input-location" class="control-label">Title</label>
        <input type="text" class="form-control" placeholder="Title" style="margin-bottom: 10px;" name="{{ publication_form.title.name }}" value="{% if publication_form.title.data %}{{ publication_form.title.data }}{% endif %}"/>
      </div>
      <div class="form-group {% if publication_form.object_name.name in publication_form.errors %}has-error{% endif %}">
        <label for="input-location" class="control-label">Object Name</label>
        <input type="text" class="form-control" placeholder="Object Name" style="margin-bottom: 10px;" name="{{ publication_form.object_name.name }}" value="{% if publication_form.object_name.data %}{{ publication_form.object_name.data }}{% endif %}"/>
      </div>
      <div class="text-right">
        <button type="submit" class="btn btn-primary" style="width:11em; margin-bottom: 20px;"><i class="fa fa-book fa-fw"></i> Link Publication</button>
      </div>
    </form>
  {% endif %}
  {% endif %}

  {% if not is_archived %}
  {% if action.type.enable_comments %}
    <h4>Comments</h4>
    {% if comments %}
      {% for comment in comments %}
        <div class="well" id="comment-{{ comment.id }}">
          <pre class="comment">{{ comment.content }}</pre>
          <div class="text-right">&mdash; <a href="{{ url_for('frontend.user_profile', user_id=comment.author.id) }}">{{ comment.author.name }}</a>, {{ comment.utc_datetime.strftime('%Y-%m-%d %H:%M:%S') }}</div>
        </div>
      {% endfor %}
    {% else %}
      <p>There are no comments for this object.</p>
    {% endif %}
    {% if user_may_comment %}
      <form class="form" method="post" action="{{ url_for('frontend.post_object_comments', object_id=object_id) }}" id="new-comment-form">
        {{ comment_form.csrf_token }}
        <div class="form-group">
          <textarea class="form-control" rows="3" placeholder="Comment" style="resize:vertical; min-height:2.5em; margin-bottom: 10px;" name="{{ comment_form.content.name }}">{% if comment_form.content.data %}{{ comment_form.content.data }}{% endif %}</textarea>
        </div>
        <div class="text-right">
          <button type="submit" class="btn btn-primary" style="width:11em; margin-bottom: 20px;"><i class="fa fa-comment fa-fw"></i> Post Comment</button>
        </div>
      </form>
    {% endif %}
  {% endif %}
  {% endif %}

  {% if not is_archived and action.type.enable_activity_log %}
  {% if object_log_entries %}
    <h4>Activity Log</h4>
    <table class="table" id="activity_log">
      <thead>
        <tr>
          <th scope="col" style="white-space: nowrap;width: 1%;">Datetime</th>
          <th scope="col"></th>
          <th scope="col" class="text-right" style="white-space: nowrap;width: 1%;">
            <button type="button" class="btn btn-sm btn-primary" data-container="body" data-toggle="popover" data-placement="left" data-html="true" data-content="
              <label style='font-weight:400'><input type='checkbox' id='activity_log_filter_versions' onclick='activity_log_toggle($(this).is(&quot;:checked&quot;), &quot;versions&quot;);'/> Versions</label><br />
              <label style='font-weight:400'><input type='checkbox' id='activity_log_filter_measurements' onclick='activity_log_toggle($(this).is(&quot;:checked&quot;), &quot;measurements&quot;);' /> Measurements</label><br />
              <label style='font-weight:400'><input type='checkbox'  id='activity_log_filter_comments' onclick='activity_log_toggle($(this).is(&quot;:checked&quot;), &quot;comments&quot;);' /> Comments</label><br />
              <label style='font-weight:400'><input type='checkbox'  id='activity_log_filter_files' onclick='activity_log_toggle($(this).is(&quot;:checked&quot;), &quot;files&quot;);' /> Files</label><br />
              <label style='font-weight:400'><input type='checkbox' id='activity_log_filter_other' onclick='activity_log_toggle($(this).is(&quot;:checked&quot;), &quot;other&quot;);'; /> Other</label>
              <script>
                window.update_activity_log_filter_states();
              </script>
            ">
              <i class="fa fa-filter" style="font-size: 1.5rem"></i> <span class="badge" id="activity_log_counter"></span>
            </button>
          </th>
        </tr>
      </thead>
      <tbody>
      {% for object_log_entry in object_log_entries %}
        <tr data-activity-log-type="{{ object_log_entry.type.name.lower() }}">
          <td style="white-space: nowrap;width: 1%;">{{ object_log_entry.utc_datetime.strftime('%Y-%m-%d %H:%M:%S') }}</td>
          {% if object_log_entry.type == ObjectLogEntryType.CREATE_OBJECT %}
            <td>
              <a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> created the object{% if 'previous_object_id' in object_log_entry.data %} using data from <a href="{{ url_for('.object', object_id=object_log_entry.data['previous_object_id']) }}"> Object {{ object_log_entry.data['previous_object_id'] }}</a>{% endif %}.
            </td>
            <td class="text-right">
              <a href="{{ url_for('.object_version', object_id=object_id, version_id=0) }}">View</a>
            </td>
          {% elif object_log_entry.type == ObjectLogEntryType.CREATE_BATCH %}
            <td>
              <a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> created the object as part of a <a href="{{ url_for('.objects', ids=(object_log_entry.data['object_ids'] | tojson)[1:-1]) }}">batch</a>.
            </td>
            <td class="text-right">
              <a href="{{ url_for('.object_version', object_id=object_id, version_id=0) }}">View</a>
            </td>
          {% elif object_log_entry.type == ObjectLogEntryType.EDIT_OBJECT %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> edited the object.</td>
            <td class="text-right">
              {% if 'version_id' in object_log_entry.data %}
                <a href="{{ url_for('.object_version', object_id=object_id, version_id=object_log_entry.data['version_id']) }}">View</a>
              {% endif %}
            </td>
          {% elif object_log_entry.type == ObjectLogEntryType.RESTORE_OBJECT_VERSION %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> restored object <a href="{{ url_for('.object_version', object_id=object_id, version_id=object_log_entry.data['restored_version_id']) }}">version #{{ object_log_entry.data['restored_version_id'] }}</a>.</td>
            <td class="text-right">
              {% if 'version_id' in object_log_entry.data %}
                <a href="{{ url_for('.object_version', object_id=object_id, version_id=object_log_entry.data['version_id']) }}">View</a>
              {% endif %}
            </td>
          {% elif object_log_entry.type == ObjectLogEntryType.USE_OBJECT_IN_MEASUREMENT %}
            {% if object_log_entry.data['measurement_id'] %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> used the object in measurement <a href="{{ url_for('.object', object_id=object_log_entry.data['measurement_id']) }}">{{ object_log_entry.data['measurement'].data['name']['text'] }} (#{{ object_log_entry.data['measurement_id'] }})</a>.</td>
            <td class="text-right">
              <a href="{{ url_for('.object', object_id=object_log_entry.data['measurement_id']) }}">View</a>
            </td>
            {% else %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> used the object in a measurement.</td>
            <td class="text-right">
            </td>
            {% endif %}
          {% elif object_log_entry.type == ObjectLogEntryType.USE_OBJECT_IN_SAMPLE_CREATION %}
            {% if object_log_entry.data['sample_id'] %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> used the object to create the sample <a href="{{ url_for('.object', object_id=object_log_entry.data['sample_id']) }}">{{ object_log_entry.data['sample'].data['name']['text'] }} (#{{ object_log_entry.data['sample_id'] }})</a>.</td>
            <td class="text-right">
              <a href="{{ url_for('.object', object_id=object_log_entry.data['sample_id']) }}">View</a>
            </td>
            {% else %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> used the object to create a sample.</td>
            <td class="text-right">
            </td>
            {% endif %}
          {% elif object_log_entry.type == ObjectLogEntryType.POST_COMMENT %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> posted a comment for this object.</td>
            <td class="text-right">
            {% if action.type.enable_comments %}
              {% if 'comment_id' in object_log_entry.data %}
                <a href="#comment-{{ object_log_entry.data['comment_id'] }}">View</a>
              {% endif %}
            {% endif %}
            </td>
          {% elif object_log_entry.type == ObjectLogEntryType.UPLOAD_FILE %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> {% for file in files %}{% if file.id == object_log_entry.data['file_id'] %}{% if file.storage == 'local' %}uploaded {% if action.type.enable_files %}<a href="#file-{{ object_log_entry.data['file_id'] }}">{% endif %}{{ file.original_file_name }}{% if action.type.enable_files %}</a>{% endif %}{% elif file.storage == 'url' %}linked <a href="{{ file.data.url }}">{{ file.data.url }}</a>{% else %}posted {% if action.type.enable_files %}<a href="#file-{{ object_log_entry.data['file_id'] }}">file #{{ file.id }}</a>{% else %} a file{% endif %}{% endif %}{% endif %}{% endfor %}.</td>
            <td class="text-right">
            {% if action.type.enable_files %}
              {% if 'file_id' in object_log_entry.data %}
                <a href="#file-{{ object_log_entry.data['file_id'] }}">View</a>
              {% endif %}
            {% endif %}
            </td>
          {% elif object_log_entry.type == ObjectLogEntryType.ASSIGN_LOCATION %}
            {% set object_location_assignment = get_object_location_assignment(object_log_entry.data['object_location_assignment_id']) %}
            {% if object_location_assignment.location is not none and object_location_assignment.responsible_user_id is not none %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> assigned this object to location <a href="{{ url_for('.location', location_id=object_location_assignment.location_id) }}">{{ get_location(object_location_assignment.location_id).name }}</a> and user <a href="{{ url_for('.user_profile', user_id=object_location_assignment.responsible_user_id) }}">{{ get_user(object_location_assignment.responsible_user_id).name }}</a>.</td>
            {% elif object_location_assignment.location is not none %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> assigned this object to location <a href="{{ url_for('.location', location_id=object_location_assignment.location_id) }}">{{ get_location(object_location_assignment.location_id).name }}</a>.</td>
            {% elif object_location_assignment.responsible_user_id is not none %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> assigned this object to user <a href="{{ url_for('.user_profile', user_id=object_location_assignment.responsible_user_id) }}">{{ get_user(object_location_assignment.responsible_user_id).name }}</a>.</td>
            {% endif %}
            <td class="text-right">
            </td>
          {% elif object_log_entry.type == ObjectLogEntryType.LINK_PUBLICATION %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> linked publication <a href="https://doi.org/{{ object_log_entry.data['doi'] | urlencode }}">{{ object_log_entry.data['doi'] }}</a> to this object.</td>
            <td class="text-right">
            {% if action.type.enable_publications %}
              <a href="#publications">View</a>
            {% endif %}
            </td>
          {% elif object_log_entry.type == ObjectLogEntryType.REFERENCE_OBJECT_IN_METADATA %}
            {% if object_log_entry.data['object_id'] %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> referenced the object in the metadata of <a href="{{ url_for('.object', object_id=object_log_entry.data['object_id']) }}">{{ object_log_entry.data['object'].data['name']['text'] }} (#{{ object_log_entry.data['object_id'] }})</a>.</td>
            <td class="text-right">
              <a href="{{ url_for('.object', object_id=object_log_entry.data['object_id']) }}">View</a>
            </td>
            {% else %}
            <td><a href="{{ url_for('.user_profile', user_id=object_log_entry.user.id) }}">{{ object_log_entry.user.name }}</a> referenced the object in the metadata of another object.</td>
            <td class="text-right">
            </td>
            {% endif %}
          {% else %}
            <td>Unknown event</td><td></td>
          {% endif %}
        </tr>
      {% endfor %}
      </tbody>
    </table>
  {% endif %}
  {% endif %}

  {% if related_objects_tree %}
  {% if not is_archived and action.type.enable_related_objects %}
    <h4>Related Objects</h4>

    <div class="related-objects">
      {% set in_export_data_model = False %}
      {% include "objects/view/related_objects_tree_toggle.html" %}{% include "objects/view/related_objects.html" %}
    </div>
  {% endif %}

    <div class="modal fade" id="dataExportModal" tabindex="-1" role="dialog" aria-labelledby="dataExportModalLabel">
      <div class="modal-dialog" role="document">
        <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="dataExportModalLabel">Export Data</h4>
          </div>
          <div class="modal-body">
            <div class="form-group">
              <label for="select-export-format" class="control-label">Export Format</label>
              <select id="select-export-format" class="selectpicker" data-width="100%">
                <option value=".pdf" selected="selected">PDF file</option>
                {% for file_extension in export_file_formats %}
                  <option value="{{ file_extension }}">{{ export_file_formats[file_extension][0] }}</option>
                {% endfor %}
              </select>
            </div>
            <div class="form-group" id="pdf–export-sections">
              <div>PDF Export Sections</div>
              <label><input type="checkbox" checked="checked" disabled="disabled" class="disabled"> Information</label>
              {% if action.type.enable_activity_log %}
              <label><input type="checkbox" checked="checked" name="activity_log"> Activity Log</label>
              {% endif %}
              {% if action.type.enable_locations %}
              <label><input type="checkbox" checked="checked" name="locations"> Locations</label>
              {% endif %}
              {% if action.type.enable_publications %}
              <label><input type="checkbox" checked="checked" name="publications"> Publications</label>
              {% endif %}
              {% if action.type.enable_files %}
              <label><input type="checkbox" checked="checked" name="files"> Files</label>
              {% endif %}
              {% if action.type.enable_comments %}
              <label><input type="checkbox" checked="checked" name="comments"> Comments</label>
              {% endif %}
            </div>

            {% if action.type.enable_related_objects %}
            <div class="related-objects">
              <div>Objects</div>
              {% set in_export_data_model = True %}
              {% include "objects/view/related_objects_tree_toggle.html" %}{% include "objects/view/related_objects.html" %}
            </div>
            {% endif %}
          </div>
          <div class="modal-footer">
            {% if action.type.enable_related_objects %}
            <button type="button" class="btn btn-default" id="button-related-objects-select-all">Select All</button>
            <button type="button" class="btn btn-default" id="button-related-objects-deselect-all">Deselect All</button>
            {% endif %}
            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
            <a href="{{ url_for('.export_data', object_id=object_id) }}" class="btn btn-primary" id="button-related-objects-export-data">Export Data</a>
          </div>
        </div>
      </div>
    </div>
  {% endif %}
{% endblock %}

{% block scripts %}
  {{ super() }}
  <script src="{{ url_for('static', filename='js/moment-with-locales.min.js') }}"></script>
  <script src="{{ url_for('static', filename='js/bootstrap-datetimepicker.min.js') }}"></script>
  <script src="{{ url_for('static', filename='js/bootstrap-select.min.js') }}"></script>
  <script src="{{ url_for('static', filename='js/bootstrap-treeview.min.js') }}"></script>
  <script src="{{ url_for('static', filename='js/js.cookie.js') }}"></script>
  <script type="text/javascript">
    $(function () {
        $('.input-group.date').each(function() {
          $(this).datetimepicker({
            format: 'YYYY-MM-DD HH:mm:ss',
            date: $(this).attr('data-datetime')
          });
        });
        $('.nav-tabs a').click(function (e) {
          e.preventDefault();
          $(this).tab('show');
        });
      {% if (not is_archived) and user_may_comment and action.type.enable_comments %}
        var comment_form = $('#new-comment-form');
        var comment_textarea = comment_form.find('textarea');
        comment_textarea.on('input change propertychange', function() {
            comment_textarea.closest('.form-group').removeClass('has-error');
        });
        comment_form.on('submit', function() {
          if (comment_textarea.val() === "") {
            comment_textarea.closest('.form-group').addClass('has-error');
            comment_textarea.focus();
            return false;
          }
          return true;
        });
      {% endif %}
      $(function () {
        $('[data-toggle="popover"]').popover()
      });
      {% if object_log_entries and action.type.enable_activity_log %}
        var activity_log_filter_type_list = {
          "versions": ['{{ ObjectLogEntryType.CREATE_OBJECT.name.lower() }}', '{{ ObjectLogEntryType.CREATE_BATCH.name.lower() }}', '{{ ObjectLogEntryType.EDIT_OBJECT.name.lower() }}', '{{ ObjectLogEntryType.RESTORE_OBJECT_VERSION.name.lower() }}'],
          "measurements": ['{{ ObjectLogEntryType.USE_OBJECT_IN_MEASUREMENT.name.lower() }}'],
          "comments": ['{{ ObjectLogEntryType.POST_COMMENT.name.lower() }}'],
          "files": ['{{ ObjectLogEntryType.UPLOAD_FILE.name.lower() }}'],
          "other": ['{{ ObjectLogEntryType.OTHER.name.lower() }}', '{{ ObjectLogEntryType.USE_OBJECT_IN_SAMPLE_CREATION.name.lower() }}']
        };
        window.activity_log_toggle = function(should_show, category) {
          var type_list = activity_log_filter_type_list[category];
          var activity_log = $('#activity_log').find('> tbody');
          type_list.forEach(function(activity_log_type) {
            var activity_log_rows = activity_log.find('tr[data-activity-log-type='+activity_log_type+']');
            if (should_show) {
              activity_log_rows.css({display: 'table-row'});
            } else {
              activity_log_rows.css({display: 'none'});
            }
          });
          $('#activity_log_counter').html(''+activity_log.find('tr:visible').length+'&thinsp;/&thinsp;'+activity_log.find('tr').length);
          window.activity_log_toggle.current_state[category] = should_show;
          Cookies.set('SAMPLEDB_ACTIVITY_LOG_FILTER_STATE', window.activity_log_toggle.current_state);
        };
        window.activity_log_toggle.current_state = {};
        var activity_log_filter_state = Cookies.getJSON('SAMPLEDB_ACTIVITY_LOG_FILTER_STATE');
        if (activity_log_filter_state === undefined) {
          activity_log_filter_state = {
            "versions": true,
            "measurements": true,
            "comments": true,
            "files": true,
            "other": true
          };
          Cookies.set('SAMPLEDB_ACTIVITY_LOG_FILTER_STATE', activity_log_filter_state);
        }
        window.activity_log_toggle(activity_log_filter_state['versions'], "versions");
        window.activity_log_toggle(activity_log_filter_state['measurements'], "measurements");
        window.activity_log_toggle(activity_log_filter_state['comments'], "comments");
        window.activity_log_toggle(activity_log_filter_state['files'], "files");
        window.activity_log_toggle(activity_log_filter_state['other'], "other");
        window.update_activity_log_filter_states = function() {
          if (window.activity_log_toggle.current_state['versions']) {
            $('#activity_log_filter_versions').attr('checked', 'checked');
          }
          if (window.activity_log_toggle.current_state['measurements']) {
            $('#activity_log_filter_measurements').attr('checked', 'checked');
          }
          if (window.activity_log_toggle.current_state['comments']) {
            $('#activity_log_filter_comments').attr('checked', 'checked');
          }
          if (window.activity_log_toggle.current_state['files']) {
            $('#activity_log_filter_files').attr('checked', 'checked');
          }
          if (window.activity_log_toggle.current_state['other']) {
            $('#activity_log_filter_other').attr('checked', 'checked');
          }
        };
      {% endif %}
      {% if not is_archived %}
        {% if action.type.enable_files %}
        window.file_table_toggle = function(should_show, category) {
          var file_table = $('#file_table').find('> tbody');
            var file_table_rows = file_table.find('tr[data-file-type='+category+']');
            if (should_show) {
              file_table_rows.css({display: 'table-row'});
            } else {
              file_table_rows.css({display: 'none'});
            }
          $('#file_table_counter').html(''+file_table.find('tr:visible').length+'&thinsp;/&thinsp;'+file_table.find('tr').length);
          window.file_table_toggle.current_state[category] = should_show;
          Cookies.set('SAMPLEDB_FILE_TABLE_FILTER_STATE', window.file_table_toggle.current_state);
        };
        window.file_table_toggle.current_state = {};
        var file_table_filter_state = Cookies.getJSON('SAMPLEDB_FILE_TABLE_FILTER_STATE');
        if (file_table_filter_state === undefined) {
          file_table_filter_state = {
            "notebooks": true,
            "other": true
          };
          Cookies.set('SAMPLEDB_FILE_TABLE_FILTER_STATE', file_table_filter_state);
        }
        window.file_table_toggle(file_table_filter_state['notebooks'], "notebooks");
        window.file_table_toggle(file_table_filter_state['other'], "other");
        window.update_file_table_filter_states = function() {
          if (window.file_table_toggle.current_state['notebooks']) {
            $('#file_table_filter_notebooks').attr('checked', 'checked');
          }
          if (window.file_table_toggle.current_state['other']) {
            $('#file_table_filter_other').attr('checked', 'checked');
          }
        };
        {% endif %}
        $('#button-show-mobile-file-upload-modal').click(function() {
            $('#mobileFileLinkModal').modal('show');
        });
        $('#button-show-object-qrcode-modal').click(function() {
            $('#mobileObjectLinkModal').modal('show');
        });
        $('#button-show-object-label-modal').click(function() {
            $('#objectLabelModal').modal('show');
        });
        {% if action.type.enable_files %}
        function changeHandler() {
          var files = $('#input-file-upload').get(0).files;
          if (files.length === 0) {
            $('#input-file-text').val("");
          } else if (files.length === 1) {
            $('#input-file-text').val(files[0].name);
            $('#button-upload-files').removeClass('disabled');
          } else {
            $('#input-file-text').val(files.length + " files selected");
            $('#button-upload-files').removeClass('disabled');
          }
          $('#input-file-names-hidden').val("");
          $('#input-file-source-hidden').val("local");
        }
        {% if user_may_edit %}
        $('#input-file-upload').on('change', changeHandler);
        function dropHandler(e) {
          e.preventDefault();
          $('#input-file-upload')[0].files = e.dataTransfer.files;
          changeHandler();
        }
        function dragOverHandler(e) {
          e.preventDefault();
        }
        var upload_area = $('#upload-area')[0];
        upload_area.ondrop = dropHandler;
        upload_area.ondragover = dragOverHandler;
        {% endif %}
        {% endif %}
      {% endif %}

    {% if action.type.enable_files %}
    $('.button-file-info').on('click', function() {
      var file_id = $(this).attr('data-file_id');
      $('#fileInfoModal-'+file_id).modal('show');
    });
    $('.file-info-hide').hide();
    $('.file-info-edit-mode').hide();
    $('.file-info-view-mode').show();
    $('.button-file-info-edit').on('click', function() {
      $('.input-file-info-title').each(function() {
        $(this).attr('data-value', $(this).attr('value'));
      });
      $('.input-file-info-description').each(function() {
        $(this).attr('data-value', $(this).val());
      });
      $('.file-info-edit-mode').show();
      $('.file-info-view-mode').hide();
    });
    $('.button-file-info-cancel').on('click', function() {
      $('.file-info-edit-mode').hide();
      $('.file-info-view-mode').show();
      $('.input-file-info-title').each(function() {
        $(this).val($(this).attr('data-value'));
      });
      $('.input-file-info-description').each(function() {
        $(this).val($(this).attr('data-value'));
      });
    });
    $('.button-file-info-hide-cancel').on('click', function() {
      $('.file-info-main').show();
      $('.file-info-hide').hide();
    });
    $('.button-file-info-hide').on('click', function() {
      $('.file-info-main').hide();
      $('.file-info-hide').show();
    });
    $('.modal-file-info').on('hidden.bs.modal', function (e) {
      $('.file-info-hide').hide();
      $('.file-info-main').show();
    });
    {% endif %}
    {% if related_objects_tree %}
    $('input[name^=data_export_object_]').prop("checked", false);
    $('input.data_export_object').prop("checked", false);
    $('input.data_export_object_{{ object_id }}').prop("checked", true);
    function updateDataExportLink() {
      var format = ".pdf";
      var selected_format_option = $('#select-export-format > option:selected');
      if (selected_format_option) {
        format = selected_format_option.val();
      }
      $('#pdf–export-sections').toggleClass('disabled', format !== '.pdf');
      var pdf_export_sections = $('#pdf–export-sections input');
      var enabled_sections = [];
      pdf_export_sections.each(function(_, input) {
        if (!$(input).hasClass('disabled')) {
          input.disabled = (format !== '.pdf');
          if (input.checked) {
            enabled_sections.push(input.name);
          }
        }
      });
      var object_ids_to_export = [];
      {% if action.type.enable_related_objects %}
      $('input[name^=data_export_object_]').each(function() {
        if ($(this).prop('checked')) {
          object_ids_to_export.push(parseInt($(this).attr('data-object-id'), 10));
        }
      });
      {% else %}
        object_ids_to_export.push({{ object_id }});
      {% endif %}
      var export_link = $('#button-related-objects-export-data');
      if (object_ids_to_export.length > 0) {
        export_link.attr('href', "{{ url_for('.export_data', object_id=object_id) }}?format=" + format + "&object_ids=" + encodeURIComponent(JSON.stringify(object_ids_to_export)) + "&sections=" + encodeURIComponent(JSON.stringify(enabled_sections)));
        export_link.removeClass("disabled");
      } else {
        export_link.attr('href', "#");
        export_link.addClass("disabled");
      }
    }

    $('#pdf–export-sections input').on('change', function() {
      updateDataExportLink();
    });
    $('input[name^=data_export_object_]').on('change', function() {
      $('input.' + this.name + ':not([name=' + this.name + '])').prop("checked",  $(this).prop("checked"));
      updateDataExportLink();
    });
    $('#button-related-objects-select-all').on('click', function() {
      $('#dataExportModal .related-objects-tree-toggle').prop("checked", true);
      $('input.data_export_object').prop("checked", true);
      updateDataExportLink();
    });
    $('#button-related-objects-deselect-all').on('click', function() {
      $('input.data_export_object').prop("checked", false);
      updateDataExportLink();
    });
    $('#select-export-format').on('change', function() {
      updateDataExportLink();
    });
    updateDataExportLink();
    {% endif %}
    $('[data-toggle="tooltip"]').tooltip();
    });

    function copyToClipboard(text) {
      var element = document.createElement('textarea');
      element.value = text;
      element.setAttribute('readonly', '');
      element.style.position = 'absolute';
      element.style.left = '-9999px';
      document.body.appendChild(element);
      var selected = false;
      if (document.getSelection().rangeCount > 0) {
        selected = document.getSelection().getRangeAt(0);
      }
      element.select();
      document.execCommand('copy');
      document.body.removeChild(element);
      if (selected) {
        document.getSelection().removeAllRanges();
        document.getSelection().addRange(selected);
      }
    }
    $('span.copy-external-link').on('click', function() {
      var button = $(this);
      copyToClipboard(button.attr('data-url'));
      var wrapper = button.parent();
      button.tooltip('hide');
      wrapper.tooltip('show');
      setTimeout(function() {
        wrapper.tooltip('hide');
      }.bind(wrapper), 500);
    });
    {% if not is_archived %}
    {% if action.type.enable_labels %}
    function validateLabelsForm() {
      const PAGE_SIZES = {
        {% for paper_format in PAGE_SIZES %}
          "{{ paper_format }}": [
            {{ PAGE_SIZES[paper_format][0] / mm }},
            {{ PAGE_SIZES[paper_format][1] / mm }}
          ]{% if loop.index < (PAGE_SIZES | length) %},{% endif %}
        {% endfor %}
      };
      var labels_form = $('#form-generate-labels');
      var is_valid = true;
      labels_form.find('.has-error').removeClass('has-error');
      labels_form.find('.has-success').removeClass('has-success');
      labels_form.find('.help-block').text("");
      if (labels_form.find('input[name="mode"][value="fixed-width"]').is(':checked')) {
        var paper_format = labels_form.find('select[name="width-paper-format"] > option:checked').val();
        if (!PAGE_SIZES.hasOwnProperty(paper_format)) {
          var paper_format_group = labels_form.find('select[name="width-paper-format"]').closest('.form-group');
          paper_format_group.addClass('has-error');
          paper_format_group.find('.help-block').text("Please select a paper format.");
          is_valid = false;
        } else {
          labels_form.find('select[name="width-paper-format"]').closest('.form-group').addClass('has-success');
          var maximum_width = Math.floor(PAGE_SIZES[paper_format][0] - {{ HORIZONTAL_LABEL_MARGIN * 2 }});
          var maximum_height = Math.floor(PAGE_SIZES[paper_format][1] - {{ VERTICAL_LABEL_MARGIN * 2 }});
          var minimum_width = 20;
          if (labels_form.find('input[name="side-by-side"]').is(':checked')) {
            minimum_width = 40;
          }
          var input_width = $('#input-width');
          var input_width_group = input_width.closest('.form-group');
          var input_width_help = input_width_group.find('.help-block');
          var label_width = +input_width.val();
          if (!isNaN(label_width) && label_width >= minimum_width && label_width <= maximum_width) {
            input_width_group.addClass('has-success');
            input_width_help.text("");
            input_width.val(label_width);
          } else {
            input_width_group.addClass('has-error');
            input_width_help.text("Please enter a number between " + minimum_width.toString() + " and " + maximum_width.toString() + ".");
            input_width.closest('.form-group').addClass('has-error');
            is_valid = false;
          }
          var input_minimum_height = $('#input-minimum-height');
          var input_minimum_height_group = input_minimum_height.closest('.form-group');
          var input_minimum_height_help = input_minimum_height_group.find('.help-block');
          var label_minimum_height = +input_minimum_height.val();
          if (!isNaN(label_minimum_height) && label_minimum_height >= 0 && label_minimum_height <= maximum_height) {
            input_minimum_height_group.addClass('has-success');
            input_minimum_height.val(label_minimum_height);
          } else {
            input_minimum_height_group.addClass('has-error');
            input_minimum_height_help.text("Please enter number between 0 and " + maximum_height.toString() + ".");
            is_valid = false;
          }
        }
      }
      if (labels_form.find('input[name="mode"][value="minimum-height"]').is(':checked')) {
        var paper_format = labels_form.find('select[name="height-paper-format"] > option:checked').val();
        if (!PAGE_SIZES.hasOwnProperty(paper_format)) {
          var paper_format_group = labels_form.find('select[name="height-paper-format"]').closest('.form-group');
          paper_format_group.addClass('has-error');
          paper_format_group.find('.help-block').text("Please select a paper format.");
          is_valid = false;
        } else {
          labels_form.find('select[name="height-paper-format"]').closest('.form-group').addClass('has-success');
          var maximum_width = Math.floor(PAGE_SIZES[paper_format][0] - {{ HORIZONTAL_LABEL_MARGIN * 2 }});
          var input_minimum_width = $('#input-minimum-width');
          var input_minimum_width_group = input_minimum_width.closest('.form-group');
          var input_minimum_width_help = input_minimum_width_group.find('.help-block');
          var label_minimum_width = +input_minimum_width.val();
          if (!isNaN(label_minimum_width) && label_minimum_width >= 0 && label_minimum_width <= maximum_width) {
            input_minimum_width_group.addClass('has-success');
            input_minimum_width.val(label_minimum_width);
          } else {
            input_minimum_width_group.addClass('has-error');
            input_minimum_width_help.text("Please enter a number between 0 and " + maximum_width.toString() + ".");
            is_valid = false;
          }
        }
      }
      if (labels_form.find('input[name="mode"][value="mixed"]').is(':checked')) {
        var paper_format = labels_form.find('select[name="mixed-paper-format"] > option:checked').val();
        if (!PAGE_SIZES.hasOwnProperty(paper_format)) {
          var paper_format_group = labels_form.find('select[name="mixed-paper-format"]').closest('.form-group');
          paper_format_group.addClass('has-error');
          paper_format_group.find('.help-block').text("Please select a paper format.");
          is_valid = false;
        } else {
          labels_form.find('select[name="mixed-paper-format"]').closest('.form-group').addClass('has-success');
        }
      }
      if (labels_form.find('input[name="mode"]:checked').length == 0) {
        labels_form.find('input[name="mode"]').closest('.radio').addClass('has-error');
        is_valid = false;
      }
      return is_valid;
    }
    function updateLabelsForm() {
      var labels_form = $('#form-generate-labels');
      labels_form.find('.has-error').removeClass('has-error');
      labels_form.find('.has-success').removeClass('has-success');
      labels_form.find('.help-block').text("");
      var is_mixed = labels_form.find('input[name="mode"][value="mixed"]').is(':checked');
      labels_form.find('select[name="mixed-paper-format"]').prop('disabled', !is_mixed).selectpicker('refresh');
      var is_fixed_width = labels_form.find('input[name="mode"][value="fixed-width"]').is(':checked');
      labels_form.find('input[name="side-by-side"]').prop('disabled', !is_fixed_width);
      labels_form.find('input[name="centered"]').prop('disabled', !is_fixed_width);
      labels_form.find('input[name="label-width"]').prop('disabled', !is_fixed_width);
      labels_form.find('input[name="label-minimum-height"]').prop('disabled', !is_fixed_width);
      labels_form.find('select[name="width-paper-format"]').prop('disabled', !is_fixed_width).selectpicker('refresh');
      var is_minimum_height = labels_form.find('input[name="mode"][value="minimum-height"]').is(':checked');
      labels_form.find('input[name="include-qrcode"]').prop('disabled', !is_minimum_height);
      labels_form.find('input[name="label-minimum-width"]').prop('disabled', !is_minimum_height);
      labels_form.find('select[name="height-paper-format"]').prop('disabled', !is_minimum_height).selectpicker('refresh');
    }
    updateLabelsForm();
    {% endif %}
    {% endif %}
  </script>
{% endblock %}
