{% include 'panel/p_header.twig' %}

<!-- Grupos -->
<section>
<div class="col-lg-12">
              <div class="card">
                <div class="card-header d-flex align-items-center">
                  <h2 class="h5 display">Aquí se pueden crear, renombrar y borrar grupos para ordenar tus checkeos.</h2>
                </div>
              <div class="card">
                <div class="card-block">
                  <table class="table table-striped table-hover">
                    <thead>
                      <tr>
                        <th>{{T_.name}}</th>
                        <th>{{T_.edit}}</th>
                      </tr>
                    </thead>
                    <tbody>
                      {% if you.fullRights == 1 %}{#New group only admins #}
                      <form action="?page=addgroup" method="POST">
                        <tr>
                          <td><input type="text" name="grpname" placeholder="Nombre del nuevo grupo"/></td>
                          <td>
                            <button type="submit" class="btn btn-info">{{T_.add}}</button>
                          </td>
                        </tr>
                      </form>
                      {% endif %}

                      {% for group in groups %}
                      <tr>
                        <td>{{group.name}}</td>
                        <td>
                          <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#editName_{{group.ID_G}}">{{T_.edit}}</button>
                          <!-- Modal Editar -->
                          <div id="editName_{{group.ID_G}}" class="modal fade" role="dialog">
                            <div class="modal-dialog">
                              <!-- Modal content-->
                              <div class="modal-content" role="document">
                                <div class="modal-header">
                                    <h5 class="modal-title">Nuevo nombre para {{group.name}}</h5>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                                <form action="?page=changegroup&ID_G={{group.ID_G}}" method="POST">
                                <div class="modal-body">
                                  <p><input type="text" name="GN_{{group.ID_G}}" value="{{group.name}}"/></p>
                                </div>
                                <div class="modal-footer">
                                  <button type="submit" class="btn btn-primary">Cambiar</button>
                                </div>
                              </form>
                              </div>
                            </div>
                          </div>
                          <!-- Fin modal -->

                          <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#delGrp_{{group.ID_G}}">{{T_.delete}}</button>
                          <!-- Modal borrar -->
                          <div id="delGrp_{{group.ID_G}}" class="modal fade" role="dialog">
                            <div class="modal-dialog">
                              <!-- Modal content-->
                              <div class="modal-content" role="document">
                                <div class="modal-header">
                                    <h5 class="modal-title">Se va a borrar {{group.name}}</h5>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                                <form action="?page=delgroup&ID_G={{group.ID_G}}" method="POST">
                                <div class="modal-body">
                                  <p class="black">Borrar un grupo es irreversible</p>
                                  {% if group.checks > 0 %}
                                    <h3 class="black">Hay checks dentro de {{group.name}}. Si continúa, se borrarán también.</h3>
                                  {% endif %}
                                </div>
                                <div class="modal-footer">
                                  <button type="submit" class="btn btn-danger">{{T_.delete}}</button>
                                </div>
                              </form>
                              </div>
                            </div>
                          </div>
                          <!-- Fin modal -->
                        </td>
                      </tr>
                      {% endfor %}
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
</section>


<script>
function changeName(Id_G,name){
   var retVal = prompt("Nuevo nombre para "+name+" ", name);
   alert("You have entered : " + retVal);
}
</script>

{% include 'footer.twig' %}