{% extends 'base.html' %}

{% block headersupplement %}
  <script>
    function updatemailfrom() {
      var randInt = Math.floor(Math.random()*100000000);
	    $('#mailfrom').val(' {{utenteautorizzato.mail }}'+randInt);
      }
  </script>
{% endblock %}

{% block top %}
  <p>
    utente che sta effettuando gli aggiornamenti: {{ utenteautorizzato.mail }}@{{ utenteautorizzato.domain.nome }}
  </p>
  {% if user %}
    <p>
      si stanno effettuando aggiornamenti sull'alias: {{ alias.mailfrom }}@{{ alias.domain.nome }}
    </p>
  {% endif %}
{% endblock %}

{% block body %}

  <div>Pannello Controllo alias - gestione</div>
  <div><br></div>

  <form name='aliasedit' method='post'>
    {% csrf_token %}
    <div class='row form-group'>
      <div class='col'>
        <label for='mailfrom'>Alias Mail From</label>
	<input type='text' class='form-control' id='mailfrom' name='mailfrom' placeholder='Mail From' value='{{ formalias.mailfrom.value }}' {% if formalias.locked.value %}readonly{% endif %}>
      </div>

      <div class='col'>
        <label for='domain_name'>Dominio</label>
        <input type='text' class='form-control' id='domain_name' name='domain_name' value='{{ alias.domain.nome }}' readonly>
	<input type='hidden' name='domain' value={{ formalias.domain.value }}>
      </div>
    </div>
      <div class='col'>
	<label for='mailfrom_generator'>-</label><br>
	<button type='button' class='btn btn-primary' id='mailfrom_generator' onclick="updatemailfrom()">Casuale</button>
      </div>

  <div class='form-group'>
    <label for='mailto'>Email di destinazione</label>
    <input type='text' class='form-control' id='mailto' name="mailto" value='{{ formalias.mailto.value }}' {% if formalias.locked.value %}readonly{% endif %} placeholder='{{ utenteautorizzato.mail }}@{{ utenteautorizzato.domain.nome }}'>
  </div>

  <div class='form-group'>
     <label for='nota'>Note e appunti</label>
     <textarea class='form-control' rows='3' id='nota' name='nota' placeholder='note e appunti' >{{ formalias.nota.value }}</textarea>
  </div>

  <div class='form-group'>
        {% if 'ALIASLOCKED' in securitylist %}
          <label for='locked'    class='form-check-label' for='locked'>Alias Bloccato:</label>
	  <input type='checkbox' class='form-check-input' id='locked' name='locked'
	  {% if formalias.locked.value %} checked {% endif %}> 
        {% endif %}

        <label for='enabled'   class='form-check-label' for='enabled'>Alias Attivo: </label>
	<input type='checkbox' class='form-check-input' id='enabled' name='enabled'
	{% if formalias.enabled.value %} checked {% endif %} 
	{% if formalias.locked.value %} disabled {% endif %}>

      {% if 'ALIASTOBEDELETED' in securitylist %}
        <label for='tobedeleted' class="form-check-label" for='tobedeleted'>Account da eliminare: </label>
	<input type='checkbox' class='form-check-input' id='tobedeleted' name='tobedeleted' 
	{% if formalias.tobedeleted.value %} checked {% endif %} 
	{% if formalias.locked.value %} disabled {% endif %}>
      {% endif %}
  </div>

  <div>
    {% if formalias.errors %}
      <p>Rilevati Errori, impossibile proseguire.</p>
      {% for f in formalias %}
        {% for e in f.errors %}
          <div class="alter alter-danger">
            <strong>{{f.label|escape }}: {{ e|escape }}</strong>
          </div>
        {% endfor %}
      {% endfor %}
      {% for e in formalias.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' class='btn btn-primary'>Conferma</button>
    <button type='reset' class='btn btn-secondary'>Reset</button>
    <button type='submit' class='btn btn-secondary' name="Ritorno">Ritorno (Senza salvare)</button>
  </div>

</form>
</div>

{% endblock %}

