{% extends "dashboard/base.html" %}
{% load static %}
{% load i18n %}

{% block title-page %}{% trans "Virtual machines" %}{% endblock %}

{% block content %}

<div class="row">
  <div class="col-md-12">
    <div class="panel panel-default">
      <div class="panel-heading">
        <div class="pull-right table-sorting">
          {% trans "Sorting ... " %}
          <!--<i class="fa fa-refresh fa-spin fa-2x"></i>-->
        </div>
        <a class="pull-right btn btn-success btn-xs vm-create" href="{% url "dashboard.views.vm-create" %}"><i class="fa fa-plus-circle"></i> {% trans "new virtual machine" %}</a>
        <h3 class="no-margin"><i class="fa fa-desktop"></i> {% trans "Virtual machines" %}</h3>
      </div>
      <div class="panel-body">
        <div class="row">
          <div class="col-md-8 vm-list-group-control" id="vm-mass-ops">
            <strong>{% trans "Group actions" %}</strong>
            <button id="vm-list-group-select-all" class="btn btn-info btn-xs">{% trans "Select all" %}</button>
            {% for o in ops %}
              <a href="{{ o.get_url }}" class="btn btn-xs btn-{{ o.effect }} mass-operation"
               title="{{ o.name|capfirst }}" disabled>
                <i class="fa fa-{{ o.icon }}"></i>
              </a>
            {% endfor %}
          </div><!-- .vm-list-group-control -->
          <div class="col-md-4" id="vm-list-search">
            <form action="" method="GET">
              <div class="input-group">
                {{ search_form.s }}
                <div class="input-group-btn">
                  {{ search_form.stype }}
                </div>
                <label class="input-group-addon input-tags" title="{% trans "Include deleted VMs" %}"
                  id="vm-list-search-checkbox-span" data-container="body">
                  {{ search_form.include_deleted }}
                </label>
                <div class="input-group-btn">
                  <button type="submit" class="btn btn-primary input-tags">
                    <i class="fa fa-search"></i>
                  </button>
                </div>
              </div><!-- .input-group -->
            </form>
          </div><!-- .col-md-4 #vm-list-search -->
        </div><!-- .row -->
      </div><!-- .panel-body -->
      <div class="panel-body">
        <div class="table-responsive">
        <table class="table table-bordered table-striped table-hover vm-list-table"
         id="vm-list-table">
          <thead><tr>
              <th data-sort="int" class="orderable pk sortable vm-list-table-thin" style="min-width: 50px;">
                {% trans "ID" as t %}
                {% include "dashboard/vm-list/header-link.html" with name=t sort="pk" %}
              </th>
              <th data-sort="string" class="name orderable sortable">
                {% trans "Name" as t %}
                {% include "dashboard/vm-list/header-link.html" with name=t sort="name" %}
              </th>
              <th data-sort="string">
                {% trans "State" as t %}
                {% include "dashboard/vm-list/header-link.html" with name=t sort="status" %}
              </th>
              <th data-sort="string" class="orderable sortable">
                {% trans "Owner" as t %}
                {% include "dashboard/vm-list/header-link.html" with name=t sort="owner" %}
              </th>
              <th data-sort="string" class="orderable sortable">
                {% trans "Lease" as t %}
                {% include "dashboard/vm-list/header-link.html" with name=t sort="lease" %}
              </th>
              <th data-sort="string" class="orderable sortable">
                {% trans "Memory" as t %}
                {% include "dashboard/vm-list/header-link.html" with name=t sort="ram_size" %}
              </th>
              {% if user.is_superuser %}
                <th data-sort="string" class="orderable sortable">
                  {% trans "IP address" as t %}
                  {% include "dashboard/vm-list/header-link.html" with name=t sort="ip_addr" %}
                </th>
                <th data-sort="string" class="orderable sortable">
                  {% trans "Node" as t %}
                  {% include "dashboard/vm-list/header-link.html" with name=t sort="node" %}
                </th>
              {% endif %}
          </tr></thead><tbody>
          {% for i in object_list %}
          <tr class="{% cycle 'odd' 'even' %}" data-vm-pk="{{ i.pk }}">
            <td class="pk"><div id="vm-{{i.pk}}">{{i.pk}}</div> </td>
            <td class="name"><a class="real-link" href="{% url "dashboard.views.detail" i.pk %}">
                {{ i.name }}</a>
            </td>
            <td class="state">
              <i class="fa fa-fw
                {% if show_acts_in_progress and i.is_in_status_change %}
                  fa-spin fa-spinner
                {% else %}
                {{ i.get_status_icon }}{% endif %}"></i>
              <span>{{ i.get_status_display }}</span>
            </td>
            <td>
              {% if i.owner.profile %}
                {{ i.owner.profile.get_display_name }}
              {% else %}
                {{ i.owner.username }}
              {% endif %}
              {# include "dashboard/_display-name.html" with user=i.owner show_org=True #}
            </td>
            <td class="lease "data-sort-value="{{ i.lease.name }}">
              <span title="{{ i.time_of_suspend|timeuntil }} | {{ i.time_of_delete|timeuntil }}">
                {{ i.lease.name }}
              </span>
            </td>
            <td class="memory "data-sort-value="{{ i.ram_size }}">
              {{ i.ram_size }} MiB
            </td>
            {% if user.is_superuser %}
            <td class="ip_addr "data-sort-value="{{ i.ipv4 }}">
              {{ i.ipv4|default:"-" }}
            </td>
            <td class="node "data-sort-value="{{ i.node.normalized_name }}">
              {{ i.node.name|default:"-" }}
            </td>
            {% endif %}
          </tr>
          {% empty %}
          <tr>
            <td colspan="7">
              {% if request.GET.s %}
                <strong>{% trans "No result." %}</strong>
              {% else %}
                <strong>{% trans "You have no virtual machines." %}</strong>
              {% endif %}
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      </div><!-- .table-responsive -->
    </div>
  </div>
</div>
</div>

<div class="alert alert-info">
  {% blocktrans %}
  You can filter the list by certain attributes (owner, name, status, tags)
  in the following way: "owner:John Doe name:my little server !name:test".
  If you don't specify any attribute names the filtering will be done by name.
  {% endblocktrans %}
</div>

<div class="alert alert-info">
  {% trans "You can select multiple vm instances while holding down the <strong>CTRL</strong> key." %}
  {% trans "If you want to select multiple instances by one click select an instance then hold down <strong>SHIFT</strong> key and select another one!" %}
</div>

{% endblock %}
