<%-- 
    Document   : notas
    Created on : jun 10, 2017, 7:53:35 p.m.
    Author     : ryuuji
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Notas</title>
        <link rel="stylesheet" href="css.css"/> 
        <script>
            function cambiar() {
                document.getElementById("asignar").submit();
            }
            function crear() {
                var form = document.getElementById("crear");
                var estudiante = document.createElement("input");
                var curso = document.createElement("input");
                var asignatura = document.createElement("input");
                estudiante.type = "hidden";
                estudiante.value = document.getElementById("estudiante").value;
                estudiante.name = "estudianteCrear";
                asignatura.type = "hidden";
                asignatura.value = document.getElementById("asignatura").value;
                asignatura.name = "asignaturaCrear";
                curso.type = "hidden";
                curso.value = document.getElementById("curso").value;
                curso.name = "cursoCrear";
                form.appendChild(estudiante);
                form.appendChild(asignatura);
                form.appendChild(curso);
                document.getElementById("crear").submit();
            }
            function eliminar() {
                var form = document.getElementById("eliminar");
                var estudiante = document.createElement("input");
                var curso = document.createElement("input");
                var asignatura = document.createElement("input");
                estudiante.type = "hidden";
                estudiante.value = document.getElementById("estudiante").value;
                estudiante.name = "estudianteEliminar";
                asignatura.type = "hidden";
                asignatura.value = document.getElementById("asignatura").value;
                asignatura.name = "asignaturaEliminar";
                curso.type = "hidden";
                curso.value = document.getElementById("curso").value;
                curso.name = "cursoEliminar";
                form.appendChild(estudiante);
                form.appendChild(asignatura);
                form.appendChild(curso);
                document.getElementById("eliminar").submit();
            }
        </script>
    </head>
    <body>
        <ul>
            <li style="float:right"><a href="EstudiantesServlet">Volver</a></li>
        </ul>
        <div class="bottom">
            <div class="query">
                <form action="NotasServlet" method="get" id="asignar">
                    <table style="width:40em">
                        <tr>
                            <td>Curso</td>
                            <td>Estudiante</td>
                            <td>Asignatura</td>
                        </tr>
                        <tr>
                            <td>
                                <div class="select">
                                    <select name="cursoSelected" onchange="cambiar.call(this, event)" id="curso">
                                        <c:forEach items="${listaCurso}" var="curso">
                                            <c:choose> 
                                                <c:when test = "${cursoSelected==curso}">
                                                    <option selected="true" value="${curso}"><c:out value="${curso}"/></option>
                                                </c:when>
                                                <c:otherwise>
                                                    <option value="${curso}"><c:out value="${curso}"/></option>
                                                </c:otherwise>
                                            </c:choose>
                                        </c:forEach>
                                    </select>
                                </div>
                            </td> 
                            <td>
                                <div class="select">
                                    <select name="estudianteSelected" onchange="cambiar.call(this, event)" id="estudiante">
                                        <c:forEach items="${listaEstudiante}" var="estudiante">
                                            <c:choose> 
                                                <c:when test = "${estudianteSelected==estudiante[1]}">
                                                    <option selected="true" value="${estudiante[1]}"><c:out value="${estudiante[1]}"/></option>
                                                </c:when>
                                                <c:otherwise>
                                                    <option value="${estudiante[1]}"><c:out value="${estudiante[1]}"/></option>
                                                </c:otherwise>
                                            </c:choose>
                                        </c:forEach>
                                    </select>
                                </div>
                            </td>
                            <td>
                                <div class="select">
                                    <select name="asignaturaSelected" onchange="cambiar.call(this, event)" id="asignatura">
                                        <c:forEach items="${listaAsignatura}" var="asignatura">
                                            <c:choose> 
                                                <c:when test = "${asignaturaSelected==asignatura}">
                                                    <option selected="true" value="${asignatura}"><c:out value="${asignatura}"/></option>
                                                </c:when>
                                                <c:otherwise>
                                                    <option value="${asignatura}"><c:out value="${asignatura}"/></option>
                                                </c:otherwise>
                                            </c:choose>
                                        </c:forEach>
                                    </select>
                                </div>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
            <div class="overflow">
                <table class="table">
                    <tr>
                        <th class="th">Notas</th>
                            <c:forEach items="${listaNotas}" var="nota">
                            <td style="border-right: 1px solid #ddd " class="td"><c:out value="${nota.valor}"/></td>
                        </c:forEach>
                    </tr>
                </table>
            </div>
            <form action="CrearNota" method="post" id="crear" class="query">
                <table>
                    <tr><td>Valor</td></tr>
                    <tr>
                        <td><input type="number" name="valor" min="0" max="7" value="5" step="0.1"/></td>
                    </tr>
                    <tr>
                        <td><button onClick="crear()">Añadir</button></td>
                    </tr>
                    <tr>
                        <td><c:out value="${errorCrear}"/></td>
                    </tr>
                </table>
            </form>
            <form action="EliminarNota" method="post" id="eliminar" class="query">
                <table>
                    <tr><td>Valor</td></tr>
                    <tr>
                        <td><input type="number" name="valor" min="0" max="7" value="5" step="0.1"/></td>
                    </tr>
                    <tr>
                        <td><button onClick="eliminar()">Eliminar</button></td>
                    </tr>
                    <tr>
                        <td><c:out value="${errorEliminar}"/></td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
</html>
