{% extends "dashboard/base.html" %}
{% load staticfiles %}
{% load i18n %}
{% load sizefieldtags %}
{% load crispy_forms_tags %}

{% block title-page %}{{ form.name.value }} | {% trans "template" %}{% endblock %}

{% block content %}

<div class="row">
  <div class="col-md-7">
    <div class="panel panel-default">
      <div class="panel-heading">
        <a class="pull-right btn btn-default btn-xs" href="{% url "dashboard.views.template-list" %}">
          {% trans "Back" %}
        </a>
        <h3 class="no-margin"><i class="fa fa-puzzle-piece"></i> {% trans "Edit template" %}</h3>
      </div>
      <div class="panel-body">
        <form action="" method="POST">
        {% with form=form %}
          {% include "display-form-errors.html" %}
        {% endwith %}

        {% csrf_token %}

        {{ form.name|as_crispy_field }}

        <strong>{% trans "Parent template" %}:</strong>
        {% if parent %}
        <a href="{% url "dashboard.views.template-detail" pk=parent.pk %}">
          {{ parent.name }}
        </a>
        {% else %}
          -
        {% endif %}

        <fieldset class="resources-sliders">
          <legend>{% trans "Resource configuration" %}</legend>
          {% include "dashboard/_resources-sliders.html" with field_priority=form.priority field_num_cores=form.num_cores field_ram_size=form.ram_size %}
{#          {{ form.max_ram_size|as_crispy_field }}#}
        </fieldset>

{#        <fieldset>#}
{#          <legend>{% trans "Virtual machine settings" %}</legend>#}
{#        {{ form.arch|as_crispy_field }}#}
{#        {{ form.access_method|as_crispy_field }}#}
{#        {{ form.boot_menu|as_crispy_field }}#}
{#        {{ form.raw_data|as_crispy_field }}#}
{#        {{ form.req_traits|as_crispy_field }}#}
{#        {{ form.description|as_crispy_field }}#}
{#        {{ form.system|as_crispy_field }}#}
{#        {{ form.has_agent|as_crispy_field }}#}
{#        </fieldset>#}
        <fieldset>
          <legend>{% trans "External resources" %}</legend>
{#        {{ form.networks|as_crispy_field }}#}
        {{ form.lease|as_crispy_field }}
{##}
{#        {{ form.tags|as_crispy_field }}#}
        </fieldset>

        <input type="submit" value="{% trans "Save changes" %}" class="btn btn-primary">
        </form>
      </div>
    </div>
  </div>

  <div class="col-md-5">
    {% if is_owner %}
    <div class="panel panel-default">
      <div class="panel-heading">
        <a href="{% url "dashboard.views.template-delete" pk=object.pk %}"
         class="btn btn-xs btn-danger pull-right template-delete">
          {% trans "Delete" %}
        </a>
        <h4 class="no-margin"><i class="fa fa-times"></i> {% trans "Delete template"  %}</h4>
      </div>
    </div>
    {% endif %}

    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 class="no-margin"><i class="fa fa-group"></i> {% trans "Manage access"  %}</h4>
      </div>
      <div class="panel-body">
        {% include "dashboard/_manage_access.html" with table_id="template-access-table" %}
      </div>
    </div>

    <div class="panel panel-default">
      <div class="panel-heading">
        <h4 class="no-margin"><i class="fa fa-file"></i> {% trans "Disk list" %}</h4>
      </div>
      <div class="panel-body">
        <ul class="template-disk-list">
        {% if not disks %}
          {% trans "No disks are added!" %}
        {% endif %}
        {% for d in disks %}
          <li>
            <i class="fa fa-file"></i>
            {{ d.name }} (#{{ d.id }})
            <a href="{% url "dashboard.views.disk-remove" pk=d.pk %}?next={{ request.path }}"
              data-disk-pk="{{ d.pk }}" class="btn btn-xs btn-danger pull-right disk-remove"
              {% if not long_remove %}title="{% trans "Remove" %}"{% endif %}>
              <i class="fa fa-times"></i>{% if long_remove %} {% trans "Remove" %}{% endif %}
            </a>
          </li>
        {% endfor %}
        </ul>
      </div>
    </div>

    {% if show_graph %}
      <div class="panel panel-default">
        <div class="panel-heading">
          <h3 class="no-margin"><i class="fa fa-area-chart"></i> {% trans "Graphs" %}</h3>
        </div>
        <div class="text-center panel-body">
          <div class="graph-buttons">
            {% include "dashboard/_graph-time-buttons.html" %}
          </div>
          <div class="text-center graph-images">
            <img src="{% url "dashboard.views.template-graph" object.pk "instances" graph_time %}"/>
          </div>

          {% if request.user.is_superuser %}
            <a  href="{% url "dashboard.views.vm-list" %}?s=template:{{object.pk}}&stype=all">
              {% trans "List all template instances" %}
            </a>
          {% endif %}
        </div>
      </div>
    {% endif %}
  </div><!-- .col-md-4 -->
</div><!-- .row -->


<style>
  fieldset {
    margin-top: 40px;
  }
  fieldset legend {
    font-weight: bold;
  }
</style>
{% endblock %}

{% block extra_js %}
  <script>
    $(function() {
      $("#hint_id_num_cores, #hint_id_priority, #hint_id_ram_size").hide();
    });
  </script>
{% endblock %}
