{% extends "base.html" %}
{% load i18n %}
{% load translations %}
{% load crispy_forms_tags %}

{% block breadcrumbs %}
<li><a href="{% url 'manage' %}">{% trans "Manage" %}</a></li>
<li><a href="{% url 'manage-backups' %}">{% trans "Backups" %}</a></li>
{% endblock %}

{% block content %}

{% for service in services %}
    <form method="post">
    {% csrf_token %}
<div class="panel panel-default">
<div class="panel-heading">
  <h4 class="panel-title">
    {% documentation_icon 'admin/backup' right=True %}
    {% blocktrans with url=service.repository %}Backup service: {{ url }}{% endblocktrans %}
    {% if not service.enabled %}
    <span class="badge">{% trans "Turned off" %}</span>
    {% endif %}
  </h4>
</div>
<div class="panel-body">
<div class="panel-group" id="accordion-{{ service.pk }}" role="tablist" aria-multiselectable="true">
  <div class="panel panel-default">
    <div class="panel-heading" role="tab">
      <h4 class="panel-title">
        <a class="collapsed createdbackup" role="button" data-toggle="collapse" data-parent="#accordion-{{ service.pk }}" href="#collapse-{{ service.pk }}" aria-expanded="false" aria-controls="collapse-{{ service.pk }}">
          <span class="badge pull-right flip">{{ service.timestamp|date }}</span>
          {% trans "Backup service credentials" %}
        </a>
      </h4>
    </div>
    <div id="collapse-{{ service.pk }}" class="panel-collapse collapse" role="tabpanel">
        {% include "manage/snippets/backup-credentials.html" %}
    </div>
  </div>
  {% for log in service.last_logs %}
  <div class="panel {% if log.event == "error" %}panel-danger{% else %}panel-default{% endif %}">
    <div class="panel-heading" role="tab">
      <h4 class="panel-title">
        <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion-{{ service.pk }}" href="#collapse-{{ service.pk }}-{{ log.pk }}" aria-expanded="false" aria-controls="collapse-{{ service.pk }}-{{ log.pk }}">
          <span class="badge pull-right flip">{{ log.timestamp|date }}</span>
          {{ log.get_event_display }}
        </a>
      </h4>
    </div>
    <div id="collapse-{{ service.pk }}-{{ log.pk }}" class="panel-collapse collapse" role="tabpanel">
      <div class="panel-body">
        <pre>{{ log.log }}</pre>
      </div>
    </div>
  </div>
  {% endfor %}
</div>
</div>
  <div class="panel-footer">
    <input type="hidden" name="service" value="{{ service.pk }}" />
    <input type="submit" class="btn btn-primary" name="toggle" value="{% if service.enabled %}{% trans "Turn off" %}{% else %}{% trans "Turn on" %}{% endif %}" />
    <input type="submit" class="btn btn-primary runbackup" name="trigger" value="{% trans "Perform backup" %}" />
    <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#remove-{{ service.pk }}">{% trans "Delete" %}</button>
</button>
    </div>
    </div>
    </form>

    <form method="post">
    {% csrf_token %}
    <input type="hidden" name="service" value="{{ service.pk }}" />
    <div class="modal fade" tabindex="-1" role="dialog" id="remove-{{ service.pk }}">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="{% trans "Close" %}"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">{% trans "Are you absolutely sure?" %}</h4>
          </div>
          <div class="modal-body">
            <p><strong>{% trans "By removing the backup service, the credentials will be removed and you might lose access to the backups." %}</strong></p>
            <p>{% trans "In case you want to be able to restore the backups, please record credentials below." %}</p>
            {% include "manage/snippets/backup-credentials.html" %}
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-primary" data-dismiss="modal">{% trans "Close" %}</button>
            <input type="submit" class="btn btn-danger" name="remove" value="{% trans "Delete" %}" />
          </div>
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    </form>

{% endfor %}

{% include "manage/snippets/activation-form.html" %}

    <form method="post">
<div class="panel panel-default">
<div class="panel-heading">
  <h4 class="panel-title">
    {% documentation_icon 'admin/backup' right=True %}
    {% trans "Add backup service" %}
  </h4>
</div>
<div class="panel-body">
    {% crispy form %}
</div>
  <div class="panel-footer">
    <input type="submit" id="generate-ssh-button" class="btn btn-primary" value="{% trans "Add" %}" />
    </div>
    </div>
    </form>


{% endblock %}
