{% extends "ui/base-devices.html" %}
{% load url from future %}
{% load icons %}

{% block content %}
{% if deployment_status %}
    <div class="alert alert-block">
        <strong>The deployment is running. Deployment status: <span class="label label-warning">{{ deployment_status }}</span> Status of plugins execution:</strong>
        {% for plugin in plugins %}
        <span title="{% if plugin.state %}done{% else %}waiting{% endif %}" class="label {% if plugin.state %}label-success{% endif %}">{{ plugin.name }}</span>
        {% endfor %}
    </div>
{% endif %}

{% if changed_addresses %}
    <div class="alert alert-info">
        <p><strong>Scan detected changes for the following IP addresses (click to see the change):</strong></p>
        <ul class="unstyled">
            {% for ip in changed_addresses %}
                <li><a href="/ui/scan/status/{{ ip.address }}/" class="btn btn-link">
                    {{ ip|address_icon }}&nbsp;{{ ip.address }}</a>
                </li>
            {% endfor %}
        </ul>
    </div>
{% endif %}

<div class="row-fluid">
<div class="span6">
{% include 'ui/device-form.html' with form=form %}

</div>
<div class="span6">

<form class="form well well-small" method="POST">
    {% csrf_token %}
    <button class="btn btn-mini pull-right" type="submit" name="save-tags">
        {% icon 'fugue-tag-small' %} Save tags
    </button>
    <label for="tags-text">Tags</label>
    <textarea id='tags-text' style="width:97%" name="tags">{{ tags }}</textarea>
</form>

{% if property_form %}
{% include 'ui/device-properties.html' with form=property_form %}
{% endif %}

<table class="table table-striped table-bordered details-info-owners">
    <thead><tr>
        <th width="16"></th>
        <th>Owner</th>
    </tr></thead>
    <tbody>
        {% for o in device.venture.all_ownerships %}
            <tr>
                <td>{{ o|owner_icon }}</td>
                <td>{{ o.owner }}</td>
            </tr>
        {% endfor %}
        {% if device.venture.department %}
            <tr>
                <td>{{ device.venture|venture_icon }}</td>
                <td>{{ device.venture.department }}</td>
            </tr>
        {% endif %}
    </tbody>
</table>

<table class="table table-striped table-bordered details-info-virtual">
    <tbody>
        {% if device.parent %}
        <tr>
            <th>Parent device</th>
            <td><a href="{{ device.parent.id }}"
                 >{{ device.parent|device_icon }}
                  {{ device.parent.name }}</a></td>
        </tr>
        {% endif %}
        {% if device.logical_parent %}
        <tr>
            <th>Logical parent device</th>
            <td><a href="{{ device.logical_parent.id }}"
                 >{{ device.logical_parent|device_icon }}
                  {{ device.logical_parent.name }}</a></td>
        </tr>
        {% endif %}
        {% if device.model.type == dt.blade_server.id %}
        <tr>
            <th>Blade System</th>
            <td><a href="{{ device.parent.id }}"
                 >{{ device.parent|device_icon }}
                  {{ device.parent.name }}</a></td>
        </tr>
        {%  if device.parent.management %}
        <tr>
            <th>Blade System Management Address</th>
            <td><a href="https://{{ device.parent.management.address }}"
                 >{{ device.parent.management|address_icon }}
                  {{ device.parent.management }}</a></td>
        </tr>
        {%  endif %}
        {% endif %}

        {% if device.model.type == dt.virtual_server.id %}
        <tr>
            <th>Virtual Server Hypervisor</th>
            <td><a href="{{ device.parent.id }}"
                 >{{ device.parent|device_icon }}
                  {{ device.parent.name }}</a></td>
        </tr>
        {%  if device.management %}
        <tr>
            <th>Head Node Management Address</th>
            <td><a href="https://{{ device.management.address }}"
                 >{{ device.management|address_icon }}
                  {{ device.management }}</a></td>
        </tr>
        {%  endif %}
        {% else %}
        {%  if device.find_management %}
        <tr>
            <th>Server Management Address</th>
            <td><a href="https://{{ device.find_management.address }}"
                 >{{ device.find_management|address_icon }}
                  {{ device.find_management }}</a></td>
        </tr>
        {%  endif %}
        {% endif %}

        {% for child in device.child_set.all %}
            {% if not child.deleted %}
                <tr>
                    <th>Child device</th>
                    <td><a href="{{ child.id }}">
                        {{ child|device_icon }}{{ child.name }}</a>
                    </td>
                </tr>
            {% endif %}
        {% endfor %}

        {% for child in device.logicalchild_set.all %}
            {% if not child.deleted %}
                <tr>
                    <th>Logical child device</th>
                    <td><a href="{{ child.id }}">
                        {{ child|device_icon }}{{ child.name }}</a>
                    </td>
                </tr>
            {% endif %}
        {% endfor %}
    </tbody>
</table>
</div>
{% endblock content %}
