{% extends 'base.html' %}
{% load domini_tags %}
{% block top %}
  <p>
    Utente che sta effettuando le operazioni: {{ utenteautorizzato.mail }}@{{ utenteautorizzato.domain.nome }}
  </p>
{% endblock %}

{% block body %}

  <form name='newdomain' method='post'>
    {% csrf_token %}
    <button class="btn btn-primary" type="submit" name='Nuovo Dominio' value="Nuovo Dominio">Nuovo Dominio</button>
    <button type='submit' class='btn btn-secondary' name="Ritorno">Ritorno</button>
    <button type='submit' class='btn btn-secondary' name="Nascondi_Scaduti">{{ Nascondi_Scaduti }} Scaduti</button>
  </form>
  <table class='table table-striped table-hover'>
    <thead class='thead-dark'>
      <tr>
	<form name='newdomain' method='post'>
	  {% csrf_token %}
	  <th scope='col'><button class="btn btn-link btn-ism" type="submit" name="Ordine_Alfabetico" value="Ordine Alfabetico">Dominio</button></th>
        <th scope='col'>*</th>
        <th scope='col'>Attività</th>
	<th scope='col'><button class='btn btn-link btn-sm' type='submit' name='Ordine_Scadenza_Contratto' value='Ordine Scadenza Contratto'>Scadenza Contratto</button></th>
	<th scope='col'><button class='btn btn-link btn-sm' type='submit' name='Ordine_Scadenza_Registrar' value='Ordine Scadenza Registrar'>Scadenza Register</button></th>
	<th scope='col'>Stato</th>
	<th scope='col'>Spazio</th>
        <th scope='col'>!</th>
	</form>
      </tr>
    </thead>
    <tbody>
      {% for d in domainlist %}
      <tr class="{% Expired d.date_expire_contract %}">
		<th scope='row' >
		  <div data-toggle='modal' data-target='#MostraServizi{{ d.id }}'>{% if 'DOMINIEDITDOMAIN' in securitylist %} {{ d.id }}: {% endif %} {{ d.nome }} </div>
  	    {% if d.last_causale.nome %}
	      <div data-toggle='modal' data-target='#AggiornaCausale{{d.id}}'>{{ d.last_causale.nome }}</div>
	    {% endif %}
	  </th>
 
          <td>{% if d.enabled %}*{% else %}-{% endif %}
	      {% if d.contatti %}*{% else %}!{% endif %}</td>
          <td>
		  <form name="editing" method="post">
	          {% csrf_token %}
		  <button class="btn btn-secondary" type="submit" name="Info" value="{{ d.id }}">Info</button>
        	      <button class="btn btn-primary" type="submit" name='Editing' value="{{ d.id }}">Edit</button>
		      {% if d.enabled %}<button class="btn btn-primary" type="submit" name='Servizi' value="{{ d.id }}">Serv</button>{% endif %}
		  </form>
         </td>

	 <td class="{% ExpiredSoon d.date_expire_contract %}">{{ d.date_expire_contract | date:"d/m/Y" }} ({{ d.date_expire_contract | DayExpiration }}) </td>
	 <td class="{% ExpiredSoon d.date_expire_registrar %}">{{ d.date_expire_registrar | date:"d/m/Y" }} ({{ d.date_expire_registrar | DayExpiration }}) </td>
	  <td><button class="btn btn-primary" type="button" 
	              name='{% if d.enabled %}disable{% else %}enable{% endif %}' 
		      data-toggle='modal' data-target='#ConfirmDisableEnable{{ d.id }}'>
                            {% if d.enabled %}Disabilita{% else %}Abilita{% endif %}</button></td>
	  <td><button class="btn btn-primary" type="button"
                      name='Spazio'
		      data-toggle='modal' data-target='#CalcolaSpazio{{ d.id }}'>Spazio</button>
          <td>{% if d.tobedeleted %}*{% endif %}</td>
        </tr>

	<!-- Modal Abilita Dominio -->
        <div class="modal fade" id="ConfirmDisableEnable{{ d.id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal fade" id="exampleModalLongTitle">Cambio Stato</h5>
		Stato attuale del dominio <b>{{ d.nome }}</b>: {% if d.enabled %}Abilitato{% else %}Disabilitato{% endif %}
                  <span aria-hidden="true">&times;</span>
	      </div>
              <div class="modal-body">
                Sei sicuro di voler cambiare stato a questo Dominio?
              </div>
              <div class="modal-footer">
		   <form name="execEnable" method="post">
	           {% csrf_token %}
	           <button type="submit" class="btn btn-primary" 
			name="{% if d.enabled %}disable{% else %}enable{% endif %}" value="{{ d.id }}">
			      {% if d.enabled %}Disabilita{% else %}Abilita{% endif %}</button>
                   <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
		   </form>
              </div>
            </div>
          </div>
        </div>
        <!--modal Fine -->

	<!-- Modal Esegue Calcolo quota per dominio -->
        <div class="modal fade" id="CalcolaSpazio{{ d.id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal fade" id="exampleModalLongTitle">Avviso</h5>
		Avvio Calcolo dello Spazio Occupato per il dominio {{ d.nome }}<br>
		La procedura richiede tempo, attendente la notifica via mail
                  <span aria-hidden="true">&times;</span>
	      </div>
              <div class="modal-body">
                Eseguo?
              </div>
              <div class="modal-footer">
		   <form name="execSpazio" method="post">
	           {% csrf_token %}
	           <button type="submit" class="btn btn-primary" 
			 name="ExecSpazio" value="{{ d.id }}">Calcola Occupazioni</button>
                   <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
		   </form>
              </div>
            </div>
          </div>
        </div>
        <!--modal Fine -->

	<!-- modal Causale -->
        <div class="modal fade" id="AggiornaCausale{{ d.id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <form name='domainedit' method='post'>
              {% csrf_token %}
 
              <div class="modal-header">
                <h5 class="modal fade" id="exampleModalLongTitle">Selezione Causale</h5>
                  <span aria-hidden="true">&times;</span>
	      </div>
              <div class="modal-body">
  	        <p>Dominio Selezionato: <b>{{ d.nome }}</b></p>
		<p>Registrar attuale: <b>{{ d.registrar.nome }}</b></p>
                <select class='form-control' id='ValoreCausale' name='ValoreCausale'>
                  <option value="0">-- -- --</option>
                    {% for i in causali %}
                  <option value="{{ i.id }}" {% if i.id|stringformat:'s' == d.last_causale.id|stringformat:'s' %} selected {% endif %}>{{ i.nome }}</option>
                    {% endfor %}
                </select>
              </div>
              <div class="modal-footer">
  	        <button type="submit" class="btn btn-primary" name="AggiornaCausale" value={{ d.id }}>Conferma</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
              </div>
	      </form>
            </div>
          </div>
        </div>
        <!--modal Fine -->

	<!-- modal Causale -->
        <div class="modal fade" id="MostraServizi{{ d.id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <form name='domservizi' method='post'>
              {% csrf_token %}
 
              <div class="modal-header">
                <h5 class="modal fade" id="exampleModalLongTitle">Selezione Causale</h5>
                  <span aria-hidden="true">&times;</span>
	      </div>
              <div class="modal-body">
		      <p>Dominio Selezionato: <b>{{ d.nome }} {{ d.id }}</b></p>
		<p>Registrar attuale: <b>{{ d.registrar.nome }}</b></p>
                <select class='form-control' id='ValoreCausale' name='ValoreCausale'>
                  <option value="0">-- -- --</option>
                    {% for i in causali %}
                  <option value="{{ i.id }}" {% if i.id|stringformat:'s' == d.last_causale.id|stringformat:'s' %} selected {% endif %}>{{ i.nome }}</option>
                    {% endfor %}
                </select>
              </div>
              <div class="modal-footer">
  	        <button type="submit" class="btn btn-primary" name="AggiornaCausale" value={{ d.id }}>Conferma</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
              </div>
	      </form>
            </div>
          </div>
        </div>
        <!--modal Fine -->

      {% endfor %}
      </form>
    </tbody>
{% endblock %}

