{% extends "base.html" %}

{% block title %}Editing Template {% endblock %}

{% block top %}
{% endblock %}

{% block body %}
  {% if error_messages %}<p><strong>{{ error_message }}</strong></p>{% endif %}
  <form name='template:edit' method="POST">
    {% csrf_token %}

    <div class='row form-group'>
      <div class='col'>
	<label for='nome'>Nome Template</label>
	<input type='text' class='form-control' id='nome' name='nome' placeholder='Nome' value='{{ template.nome.value }}'>
      </div>
    </div>

    <div class='row form-group'>
      <div class='col'>
	<label for='nome'>Soggetto</label>
	<input type='text' class='form-control' id='soggetto' name='soggetto' placeholder='Soggetto' value='{{ template.soggetto.value }}'>
      </div>
    </div>

    <div class='row form-group'>
      <div class='col'>
        <label for='nota'>Oggetto della mail</label>
        <textarea class='form-control' rows='10' id='oggetto' name='oggetto' placeholder='Oggetto della comunicazione' >{{ template.oggetto.value }}</textarea>
      </div>
    </div>

    <div class='row form-check form-check-inline'>
      <div class='col'>
        <label for='html' class='form-check-label'>Html: </label>
	<input type='checkbox' class='form-check-input' id='html' name='html' {% if template.html.value %} checked {% endif %}>
      </div>
    </div>

    <div class='row form-check form-check-inline'>
      <div class='col'>
        <label for='enabled' class='form-check-label' for='enabled'>Template Abilitato: </label>
        <input type='checkbox' class='form-check-input' id='enabled' name='enabled' {% if template.enabled.value %} checked {% endif %}>
      </div>
    </div>

    <div class='row form-group'>
      <div class='col'>
        <label for='nota'>Note di editing</label>
        <textarea class='form-control' rows='10' id='note' name='note' placeholder='Note di editing' >{{ template.note.value }}</textarea>
      </div>
    </div>

    <div>
      {% if template.errors %}
        <p>Rilevati Errori, impossibile proseguire.</p>
        {% for f in template  %}
          {% for e in f.errors %}
            <div class="alter alter-danger">
              <strong>{{f.label|escape }}: {{ e|escape }}</strong>
            </div>
          {% endfor %}
        {% endfor %}
	{% for e in template.non_field_errors %}
          <div class="alter alter-danger">
            <strong>{{ e|escape }}</strong>
          </div>
        {% endfor %}
      {% endif %}
    </div>

  <div><br></div>

  <div class='form-group btn-group' role='group' aria-label='conferme'>
    <button type='submit' value='Registra' class='btn btn-secondary'>Registra</button>
    <button type='reset'  value='reset' class='btn btn-secondary'>Reset</button>
    <button type='submit' class='btn btn-secondary' name="Ritorno">Ritorno (Senza salvare)</button>
  </div>

  </form>
{% endblock %}
