{% extends "base.html" %}
{% load i18n %}
{% load static %}
{% load permissions %}


{% block title %}
  {% trans 'Enhydris - Instrument' %} -
    {% if instrument %}
      {{ instrument.name }} - {{ instrument.type }},
      {% trans 'Station:' %} {{ instrument.station }}
    {% endif %}
{% endblock %}


{% block extrajs %}
  <script type="text/javascript">
    function confirmPost(){
      var agree=confirm("Are you sure you want to delete this timeseries?");
      if (agree)
        return true;
      else
      return false;
    };
  </script>
{% endblock %}


{% block content %}
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <div class="panel panel-default">
          <div class="panel-heading">
            <b> {{ instrument.station }} </b>
            <br>
            <sub>
              {% if not enabled_user_content %}
                {% if request.user|can_edit:instrument.station %}
                  <a class="btn btn-xs btn-primary" href='{% url "instrument_edit" instrument.id%}'>{% trans "Edit" %}</a>
                  <a class="btn btn-xs btn-danger" onClick='return confirmPost()' href='{% url "instrument_delete" instrument.id%}'>{% trans "Delete" %}</a>
                {% endif %}
              {% endif %}
              {% if request.user|can_edit:instrument.station %}
                <a class="btn btn-xs btn-default" href="{% url "timeseries_add" %}?instrument_id={{ instrument.id }}"><i class="glyphicon glyphicon-plus"></i> {% trans "New Timeseries" %}</a>
              {% endif %}
            </sub>
          </div>
          <div class="panel-body">
            {% if instrument %}
              <div class="table-responsive">
                <table class="table table-hover table-condensed">
                  <tr>
                    <th>{% trans 'ID' %}</th>
                    <td colspan='2'>{{ instrument.id }}</td>
                  </tr>
                  <tr>
                    <th>{% trans 'Related Station' %}</th>
                    <td colspan='2'><a href="{% url "station_detail" instrument.station.id %}">{{ instrument.station }}</a></td>
                  </tr>
                  <tr>
                    <th>{% trans 'Name' %}</th>
                    <td colspan='2'>{{ instrument.name }}</td>
                  </tr>
                  <tr>
                    <th>{% trans 'Type' %}</th>
                    <td colspan='2'>{{ instrument.type }}</td>
                  </tr>
                  <tr>
                    <th>{% trans 'Remarks' %}</th>
                    <td colspan='2'>{{ instrument.remarks }}</td>
                  </tr>
                  <tr>
                    <th>{% trans 'Manufacturer' %}</th>
                    <td colspan='2'>{{ instrument.manufacturer }}</td>
                  </tr>
                  <tr>
                    <th>{% trans 'Model' %}</th>
                    <td colspan='2'>{{ instrument.model }}</td>
                  </tr>
                  <tr>
                    <th>{% trans 'Start Date' %}</th>
                    <td colspan='2'>{{ instrument.start_date|date:"Y/m/d" }}</td>
                  </tr>
                  <tr>
                    <th>{% trans 'End Date' %}</th>
                    <td colspan='2'>{{ instrument.end_date|date:"Y/m/d" }}</td>
                  </tr>
                  <tr>
                    <th>{% trans 'Timeseries' %}</th>
                    {% if timeseries.count %}
                      <td colspan="2">
                        <div class="table-responsive">
                          <table class="table table-hover table-condensed">
                            <thead>
                              <tr>
                                <th>{% trans "ID" %}</th>
                                <th>{% trans "Name" %}</th>
                                <th>{% trans "Variable" %}</th>
                                <th>{% trans "Time step" %}</th>
                                <th>{% trans "Unit Of Measurement" %}</th>
                                <th>{% trans "Remarks" %}</th>
                                <th>{% trans "Instrument" %}</th>
                                <th>{% trans "Start Date" %}</th>
                                <th>{% trans "End Date" %}</th>
                                {% if request.user|can_edit:station %}
                                  <th>{% trans "Management" %}</th>
                                {% endif %}
                              </tr>
                            </thead>
                            <tbody>
                              {% for t in timeseries %}
                                {% if not t.hidden %}
                                  {% with t.id as t_id %}
                                    {% url "timeseries_detail" t_id as timeseries_url %}
                                    <tr>
                                      <td><a href="{{ timeseries_url }}">{{ t_id }}</a></td>
                                      <td>{{ t.name }}</td>
                                      <td>{{ t.variable }}</td>
                                      <td>{% if not t.time_step %}
                                            {% trans 'Variable step' %}
                                          {% else %}
                                            {{ t.time_step }}
                                          {% endif %}
                                      </td>
                                      <td>{{ t.unit_of_measurement }}</td>
                                      <td>{{ t.remarks }}</td>
                                      <td>{{ t.instrument }}</td>
                                      <td>{{ t.start_date|date:"Y/m/d H:i" }}</td>
                                      <td>{{ t.end_date|date:"Y/m/d H:i" }}</td>
                                      {% if request.user|can_edit:station %}
                                      <td class="col-sm-2">
                                        <a href="{% url "timeseries_edit" t.id %}" title="Edit"><i class="glyphicon glyphicon-pencil"></i></a>&nbsp;
                                        <a href="{% url "timeseries_delete" t.id %}" title="Delete"><i class="glyphicon glyphicon-remove"></i></a>
                                      </td>
                                      {% endif %}
                                    {% endwith %}
                                  {% endif %}
                                {% endfor %}
                              </tr>
                            </table>
                          </div>
                        </td>
                    {% endif %}
                  </tr>
                </table>
            {% endif %}
          </div>
         </div>
       </div>
      </div>
    </div>
  </div>
{% endblock %}
