{% 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 extracss %}
<link type="text/css" href="{% static "css/ui_override.css" %}" rel="stylesheet" />
<link media="screen" href="{% static "css/tablesorter.css" %}" type="text/css" rel="stylesheet">
{% 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>
  <script type="text/javascript">
  $(document).ready(function() {
      $("table").tablesorter();
  });
  </script>
{% endblock %}

{% block content %}
    <h2>{% trans 'Instrument Details' %}
	{% if enabled_user_content %}
            {% if request.user|can_edit:instrument.station %}
            <sup class='sup_link'>
                <a href='{% url "instrument_edit" instrument.id%}'>edit</a>
                ,
                <a onClick='return confirmPost()' href='{% url "instrument_delete" instrument.id%}'>delete</a>
            {% endif %} 
            </sup>
        {% endif %}
	</h2>
    {% if request.user|can_edit:instrument.station %}
    <div id="menu_bar">
        <ul style="list-style-type:none;">
            <li>
                <span style="color:#A0A095">More: </span>
                <span class="menu_options"><a href="{% url "timeseries_add" %}?instrument_id={{ instrument.id }}">Add new Timeseries</a></span>
            </li>
        </ul>
        <br />
    </div>
    {% endif %}

        {% if instrument %}
        <table class="definition tablesorter table_container">
            <tr class="{% cycle 'odd' 'even' as rowalts %}">
                <th>{% trans 'ID' %}</th>
                <td colspan='2'>{{ instrument.id }}</td>
            </tr>
            <tr class="{% cycle rowalts %}">
                <th>{% trans 'Related Station' %}</th>
                <td colspan='2'><a href="{% url "station_detail" instrument.station.id %}">{{ instrument.station }}</a></td>
            </tr>
            <tr class="{% cycle rowalts %}">
                <th>{% trans 'Name' %}</th>
                <td colspan='2'>{{ instrument.name }}</td>
            </tr>
            <tr class="{% cycle rowalts %}">
                <th>{% trans 'Type' %}</th>
                <td colspan='2'>{{ instrument.type }}</td>
            </tr>
            <tr class="{% cycle rowalts %}">
                <th>{% trans 'Remarks' %}</th>
                <td colspan='2'>{{ instrument.remarks }}</td>
            </tr>
            <tr class="{% cycle rowalts %}">
                <th>{% trans 'Manufacturer' %}</th>
                <td colspan='2'>{{ instrument.manufacturer }}</td>
            </tr>
            <tr class="{% cycle rowalts %}">
                <th>{% trans 'Model' %}</th>
                <td colspan='2'>{{ instrument.model }}</td>
            </tr>
            <tr class="{% cycle rowalts %}">
                <th>{% trans 'Is Active' %}</th>
                <td colspan='2'>{{ instrument.is_active }}</td>
            </tr>
            <tr class="{% cycle rowalts %}">
                <th>{% trans 'Start Date' %}</th>
                <td colspan='2'>{{ instrument.start_date|date:"Y/m/d" }}</td>
            </tr>
            <tr class="{% cycle rowalts %}">
                <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">
                    <table class="tablesorter" style='text-align:right;width:100%;'>
                        <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 style="text-align:center;">
                                <a href="{% url "timeseries_edit" t.id %}" title="Edit"><img class="mgmt_button " alt="edit" width="12" height="12" src="{% static "images/icons/pencil.png" %}"</img></a>&nbsp;
                                <a href="{% url "timeseries_delete" t.id %}" title="Delete"><img class="mgmt_button  verification_required" alt="delete" width="12" height="12" src="{% static "images/icons/cross.png" %}"</img></a>
                            </td>
							{% endif %}
                        {% endwith %}
                        {% endif %}
                        {% endfor %}
                        </tr>
                    </table>
                </td>
                {% endif %}
            </tr>
        </table>
        {% endif %}
{% endblock %}
