{% extends 'base.html' %}

{% block page_navigation %}<i class="fab fa-wpforms"></i>Formularios{% endblock %}
{% block body %}
    {% if forms %}
        {% if request.user.is_superuser %}
            <div class="row ml-2 justify-content-end">
                <a href="{% url 'descargartodos' %}" id="download-audios" class="btn btn-text btn-primary"><i class="fa fa-download"></i> Descargar todos los audios</a>
            </div>
        {% endif %}

        <div class="card-columns">
            {% for formulario in forms %}
                {% include 'formularioCard.html' %}
            {% endfor %}
        </div>

        <div class="modal fade bd-example-modal-sm" id="urlModal" tabindex="1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title"><i class="fa fa-link mr-3"></i>Link al Formulario</h5>
                    </div>
                    <div class="modal-body">
                        <span class="url-span" id="url"></span>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    {% else %}
        <h3 class="card-title text-dark mt-5 mb-5 row justify-content-center font-weight-bold">No hay ningún formulario.</h3>
    {% endif %}

    {% include 'footer.html' %}

{% endblock %}

{% block footer1 %}
{% endblock %}

{% block action_buttons %}
    <a href="{% url 'nuevoform' %}">
        <button type="button" class="btn btn-secondary bmd-btn-fab">
            <i class="fa fa-plus" aria-hidden="true" style="color: black!important;"></i>
        </button>
    </a>
{% endblock %}

{% block javascripts %}
    <script type="text/javascript">

        function generarUrl(id){
            $.ajax({
                type: "POST",
                url: '{% url 'generarurl' %}',
                data: {id: id},
                dataType: "json",
                success : function(data) {
                    alert(data.result);
                },

            });

        };

        function eliminarForm(id){
            $.ajax({
                type: "POST",
                url: '{% url 'eliminarForm' %}',
                data: {id: id},
                dataType: "json",
                success : function(data) {
                    window.location.reload();
                },

            });
        };
    </script>

{% endblock %}