{% extends "admin/base_site.html" %}
{% load i18n l10n admin_urls static %}

{% block extrahead %}
    {{ block.super }}
    {{ media }}
    <script type="text/javascript" src="{% static 'admin/js/cancel.js' %}"></script>
{% endblock %}

{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} delete-confirmation delete-selected-confirmation{% endblock %}

{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
&rsaquo; <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
&rsaquo; <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
&rsaquo; {% trans 'Upgrade devices of the selected build' %}
</div>
{% endblock %}

{% block content %}
  {% if related_count or firmwareless_count %}
  <p>{% blocktrans %}Are you sure you want to proceed with this batch upgrade operation?{% endblocktrans %}</p>
  {% elif not related_count and not firmwareless_count %}
  <p>{% blocktrans %}No devices to upgrade were found.
     Hint: Maybe they have been all already updated previously.{% endblocktrans %}</p>
  {% endif %}
  {% if related_count %}
  <h2>{% trans "Devices related to build" %} {{ build }} ({{ related_count }})</h2>
  <ul>
      {% for device_fw in related_device_fw %}
      <li>{{ device_fw.device.name }}</li>
      {% endfor %}
  </ul>
  {% endif %}
  {% if firmwareless_count %}
  <h2>{% trans "Devices which the system has never upgraded yet" %} ({{ firmwareless_count }})</h2>
  <ul>
      {% for device in firmwareless_devices %}
      <li>{{ device.name }}</li>
      {% endfor %}
  </ul>
  {% endif %}

  <form method="post">{% csrf_token %}
  <div>
  <input type="hidden" name="{{ action_checkbox_name }}" value="{{ build.pk|unlocalize }}">
  <input type="hidden" name="action" value="upgrade_selected">
  {% if firmwareless_count or related_count %}
  <div>{% if form.errors %}{{ form.errors }} {% endif %}</div>
  <div class="form-row{% if form.errors.upgrade_options %} errors{% endif %}">
    {{ form }}
  </div>
  <input type="submit" name="upgrade_all" value="{% trans "Upgrade all devices" %}">
  {% if firmwareless_count and related_count %}
  <input type="submit" name="upgrade_related" value="{% trans "Upgrade only related devices" %}">
  {% endif %}
  {% endif %}
  {% if related_count or firmwareless_count %}
  <a href="#" class="button cancel-link">{% trans "Cancel the upgrade" %}</a>
  {% else %}
  <a href="#" class="button cancel-link">{% trans "Go back" %}</a>
  {% endif %}

  </div>
  </form>
{% endblock %}

{% block footer %}
{{ block.super }}
<script>
    var firmwareUpgraderSchema = {{ firmware_upgrader_schema | safe }}
</script>
{{ form.media }}
{% endblock footer %}
