{% extends 'base.html' %}

{% block page_navigation %}<i class="fab fa-wpforms"></i>Formularios{% endblock %}
{% block body %}

    <div id="titulo-secction" class="row justify-content-center">
        <div class="col align-self-center ">
            <div class="card mb-5" style="width:500px !important; margin-left: 25%">
                <div class="card-header">
                    <h3 class="card-title text-dark row justify-content-center">Introduce los nuevos datos para {{ admin_user.username }}</h3>
                    <p class="card-title text-dark row justify-content-center">En caso de no querer cambiar la contraseña, introduce la misma.</p>
                </div>
                <div class="card-body">
                    <span class="bmd-help error"></span>
                    <fieldset class="form-group">
                        <label class="bmd-label-floating" for="password">Contraseña*</label>
                        <input class="form-control" type="password" name="subtitulo" id="password"autofocus>
                    </fieldset>
                    <fieldset class="form-group">
                        <label class="bmd-label-floating" for="firstname">Nombre</label>
                        <input class="form-control" type="text" name="cuerpo" id="firstname" autofocus value="{{ admin_user.first_name }}">
                    </fieldset>
                    <fieldset class="form-group">
                        <label class="bmd-label-floating" for="lastname">Apellidos</label>
                        <input class="form-control" type="text" name="cuerpo" id="lastname" autofocus value="{{ admin_user.last_name }}">
                    </fieldset>
                    <fieldset class="form-group">
                        <label class="bmd-label-floating" for="email">Email*</label>
                        <input class="form-control" type="text" name="cuerpo" id="email" autofocus value="{{ admin_user.email }}">
                    </fieldset>
                    <p class="text-warning mt-3">Los campos marcados con un * son obligatorios.</p>
                </div>
            </div>
            <a href="javascript:void(0);" onclick="action_submit()" style="margin-bottom: 100px; margin-left: 45%;">
                <button  type="button" class="btn btn-secondary bmd-btn-fab">
                    <i class="fa fa-floppy-o" aria-hidden="true" style="color: black!important;"></i>
                </button>
            </a>
        </div>
    </div>


    {% include 'footer.html' %}

{% endblock %}

{% block footer1 %}
{% endblock %}

{% block action_buttons %}

{% endblock %}

{% block javascripts %}
    <script type="text/javascript">
        function action_submit(){
            var password = document.getElementById('password').value;
            var firstname = document.getElementById('firstname').value;
            var lastname = document.getElementById('lastname').value;
            var email = document.getElementById('email').value;

            var data_dict = {'password': password, 'firstname': firstname, "lastname": lastname, "email": email}

            if(!password) {
                alert("Es obligatorio poner la contraseña. Puedes poner la que ya tenias o una nueva.");
                return false;
            }

            if(!email){
                alert("Es obligatorio poner el email.");
                return false;
            }

            $.ajax({
                url: "{% url 'submitDatosAdmin' %}",
                type: "POST",
                data: data_dict,
                success : function(json,data) {
                    alert("Administrador modificado.");
                    location.href = "{% url 'login' %}"
                },
                error : function(xhr, errmsg, err) {
                    alert("No se ha podido modificar.");
                }
            });
        }

    </script>

{% endblock %}