{% extends "base.html" %}

{% load common bootstrap3 %}

{% block page_title %}Operating System - {{ os }} {% endblock %}

{% block breadcrumbs %} {{ block.super }} <li><a href="{% url 'operatingsystems:os_list' %}">Operating Systems</a></li><li class="active">

{% if os %}
    {{ os }}
{% endif %}

{% if oses %}
    Multiple
{% endif %}

</li>{% endblock %}

{% block content_title %}Operating System - {{ os }}{% endblock %}

{% block content %}

{% if os %}
  <div class="well well-sm">
    <table class="table table-striped table-bordered table-hover table-condensed table-responsive">
      <tr><th>Name</th><td> {{ os.name }} </td></tr>
      <tr><th>Hosts</th><td>{% if os.host_set.count != None %} {{ os.host_set.count }} {% else %} 0 {% endif %}</td>
      <tr><th>OS Group</th><td>{% if os.osgroup != None %}<a href="{{ os.osgroup.get_absolute_url }}"> {{ os.osgroup }} </a>{% else %}No OS Group{% endif %}</td></tr>
    </table>
{% endif %}

{% if oses %}
  <div class="well well-sm">
    <table class="table table-striped table-bordered table-hover table-condensed table-responsive">
      <tr>
        <th>Name</th><th>Hosts</th><th>OS Group</th>
      </tr>
      {% for os in oses %}
        <tr>
          <td><a href="{{ os.get_absolute_url }}"> {{ os }} </a></td>
          <td>{% if os.host_set.count != None %} {{ os.host_set.count }} {% else %} 0 {% endif %}</td>
          <td>{% if os.osgroup != None %}<a href="{{ os.osgroup.get_absolute_url }}"> {{ os.osgroup }} </a>{% else %}No OS Group{% endif %}</td>
        </tr>
      {% endfor %}
    </table>
{% endif %}

  <div class="panel panel-danger">
    {% if user.is_authenticated and perms.is_admin %}
      <div class="panel-heading">
        Are you sure you want to delete
        {% if os %}
          this Operating System?
        {% endif %}
        {% if oses %}
          these Operating Systems?
        {% endif %}
      </div>
      <div class="panel-body">
        <form action={{ request.path }} method="post">
         {% csrf_token %}
          <button name="delete" type="submit" class="btn btn-primary btn-sm">{% bootstrap_icon "trash" %} Delete</button>
          <button name="cancel" type="submit" class="btn btn-primary btn-sm">{% bootstrap_icon "stop" %} Cancel</button>
        </form>
      </div>
    {% else %}
      <div class="panel-heading">
        You do not have permission to delete Operating Systems.
      </div>
      <div class="panel-body">
        <a class="btn btn-primary btn-sm" href="{{ os.get_absolute_url }}">{% bootstrap_icon "arrow-left" %} Back</a>
      </div>
    {% endif %}
  </div>
</div>

{% endblock %}
