<%-- 
    Document   : actividades
    Created on : jun 8, 2017, 3:55:39 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>Actividad</title>
        <link rel="stylesheet" href="css.css"/>
        <script>
            function cambiar() {
                document.getElementById("asignar").submit();
            }
            function crear() {
                var form = document.getElementById("crear");
                var curso = document.createElement("input");
                var asignatura = document.createElement("input");
                curso.type = "hidden";
                curso.value = document.getElementById("curso").value;
                curso.name = "cursoCrear";
                asignatura.type = "hidden";
                asignatura.value = document.getElementById("asignatura").value;
                asignatura.name = "asignaturaCrear";
                form.appendChild(curso);
                form.appendChild(asignatura);
                document.getElementById("crear").submit();
            }
            function eliminar() {
                var form = document.getElementById("eliminar");
                var curso = document.createElement("input");
                var asignatura = document.createElement("input");
                curso.type = "hidden";
                curso.value = document.getElementById("curso").value;
                curso.name = "cursoEliminar";
                asignatura.type = "hidden";
                asignatura.value = document.getElementById("asignatura").value;
                asignatura.name = "asignaturaEliminar";
                form.appendChild(curso);
                form.appendChild(asignatura);
                document.getElementById("eliminar").submit();
            }
        </script>
    </head>
    <body>
        <%--TOP--%>
        <ul>
            <li style="float:right"><a href="AsignaturaServlet">Volver</a></li>
        </ul>
        <%--BOT--%>
        <div class="bottom">
            <%--Seleccion--%>
            <div class="query">
                <form action="ActividadServlet" method="get" id="asignar">
                    <table style="width:20em"/>
                    <tr>
                        <td>Curso</td>
                        <td>Asignatura</td>
                    </tr>
                    <tr>
                        <td>
                            <div class="select">
                                <select name="cursoSelected" onchange="cambiar.call(this, event)" id="curso">
                                    <c:forEach items="${cursos}" 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="asignaturaSelected" onchange="cambiar.call(this, event)" id="asignatura">
                                    <c:forEach items="${asignaturas}" 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>
            <%--Table--%>
            <div class="overflow">
                <table class="table">
                    <tr>
                        <th class="th">Tipo</th>
                        <th class="th">Fecha</th>
                    </tr>
                    <c:forEach items="${actividades}" var="actividad">
                        <tr>
                            <td class="td"><c:out value="${actividad.tipo}"/></td>
                            <td class="td"><c:out value="${actividad.fecha}"/></td>
                        </tr>
                    </c:forEach>
                </table>
            </div>

            <div class="query">
                <form action="CrearActividad" method="post" id="crear">
                    <table>
                        <tr>
                            <td>Tipo</td>
                        </tr>
                        <tr>
                            <td><input type="text" name="tipo"/></td>
                        </tr>
                        <tr>
                            <td>Fecha</td>
                        </tr>
                        <tr>
                            <td><input type="date" value="${today}" name="fecha"/></td>
                        </tr>
                        <tr>
                            <td><button onClick="crear()">Crear</button></td>
                        </tr>
                        <tr>
                            <td><c:out value="${errorCrear}"/></td>
                        </tr>
                    </table>
                </form>
            </div>
            <div class="query">
                <form action="EliminarActividad" method="post" id="eliminar">
                    <table>
                        <tr>
                            <td>Tipo</td>
                        </tr>
                        <tr>
                            <td><input type="text" name="tipo"/></td>
                        </tr>
                        <tr>
                            <td>Fecha</td>
                        </tr>
                        <tr>
                            <td><input type="date" value="${today}" name="fecha"/></td>
                        </tr>
                        <tr>
                            <td><button onClick="eliminar()">Eliminar</button></td>
                        </tr>
                        <tr>
                            <td><c:out value="${errorEliminar}"/></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </body>
</html>
