// initial state const días = ["lunes", "martes", "miércoles", "jueves", "viernes", "sábado"]; const horas_estándar = /* range from 7 to 22 */ Array.from(Array(22 - 7 + 1).keys()).map(x => x + 7); // fill the table with empty cells for (let i = 0; i < horas_estándar.length - 1; i++) { const hora = horas_estándar[i]; const tr = document.createElement("tr"); tr.id = `hora-${hora}-00`; tr.classList.add(hora > 13 ? "tarde" : "mañana"); const th = document.createElement("th"); th.classList.add("text-center"); th.scope = "row"; th.rowSpan = 4; th.innerText = `${hora}:00`; th.style.verticalAlign = "middle"; tr.appendChild(th); for (let j = 0; j < días.length; j++) { const día = días[j]; const td = document.createElement("td"); td.id = `hora-${hora}-00-${día}`; tr.appendChild(td); } document.querySelector("tbody#horario")?.appendChild(tr); // add 7 rows for each hour const hours = [15, 30, 45]; for (let j = 1; j < 4; j++) { const tr = document.createElement("tr"); tr.id = `hora-${hora}-${hours[j - 1]}`; tr.classList.add(hora > 13 ? "tarde" : "mañana"); for (let k = 0; k < días.length; k++) { const día = días[k]; const td = document.createElement("td"); td.id = `hora-${hora}-${hours[j - 1]}-${día}`; // td.innerText = `hora-${hora}-${hours[j - 1]}-${día}`; tr.appendChild(td); } document.querySelector("tbody#horario")?.appendChild(tr); } } // add an inital height to the table cells const tds = document.querySelectorAll("tbody#horario td"); tds.forEach(td => td.style.height = "2rem"); var table = document.querySelector("table"); var empty_table = table?.innerHTML || ""; // hide the table table.style.display = "none"; document.getElementById('dlProfesor')?.addEventListener('input', function () { var input = document.getElementById('dlProfesor'); var value = input.value; var option = document.querySelector(`option[value="${value}"]`); if (option) { var id = option.getAttribute('data-id'); const input_profesor = document.getElementById('editor_profesor'); input_profesor.value = id; // remove is invalid class input.classList.remove("is-invalid"); // add is valid class input.classList.add("is-valid"); } else { const input_profesor = document.getElementById('editor_profesor'); input_profesor.value = ""; // remove is valid class input.classList.remove("is-valid"); // add is invalid class input.classList.add("is-invalid"); } }); /** * Functions and Methods **/ const buscarGrupo = async () => { // Add loading animation in the button const btn = document.querySelector("#btn-buscar"); btn.innerHTML = ' Cargando...'; btn.disabled = true; const carrera = document.querySelector("#filter_carrera")?.value; const grupo = document.querySelector("#filter_grupo")?.value; console.log(`Carrera: ${carrera}, Grupo: ${grupo}`); if (carrera == "" || grupo == "") { triggerMessage("El nombre del grupo y la carrera son requeridos", "Faltan campos"); // Remove loading animation in the button btn.innerHTML = ' Buscar'; btn.disabled = false; return; } const formData = new FormData(); formData.append("carrera", carrera); formData.append("grupo", grupo); formData.append("periodo", document.querySelector("#periodo")?.value); const thisScript = document.currentScript; const facultad = thisScript.getAttribute("data-facultad"); formData.append('facultad', facultad); try { const response = await fetch("action/action_horario.php", { method: "POST", body: formData }).then(res => res.json()); if (response.status == "success") { let limits = { min: 22, max: 7 }; let sábado = false; const horario = response.horario; // show the table table.style.display = "table"; // clear the table table.innerHTML = empty_table; // fill the table for (let i = 0; i < horario.length; i++) { const dia = horario[i].dia; if (dia == "sábado") sábado = true; const { hora, minutos } = { hora: parseInt(horario[i].hora.split(":")[0]), minutos: horario[i].hora.split(":")[1] }; // update the limits if (hora < limits.min) { limits.min = hora; } if (hora > limits.max) { limits.max = hora; } const materia = horario[i].materia; const profesor = horario[i].profesor; const salon = horario[i].salon; const id = horario[i].horario_id; const prof_id = horario[i].profesor_id; const cell = document.querySelector(`#hora-${hora}-${minutos}-${dia}`); cell.innerHTML = `