2024-11-07 10:32:00 +04:00
|
|
|
<!doctype html>
|
|
|
|
<html lang="ru" class="h-100">
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
<title>Моя страница</title>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
|
<script type="module" src="./node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
|
|
|
<link href="./node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
|
|
|
|
<link href="./node_modules/bootstrap-icons/font/bootstrap-icons.min.css" rel="stylesheet" />
|
|
|
|
<link rel="stylesheet" href="./css/style.css" />
|
|
|
|
</head>
|
2024-10-09 15:13:24 +04:00
|
|
|
|
2024-11-07 10:32:00 +04:00
|
|
|
<body class="h-100 d-flex flex-column">
|
|
|
|
<header>
|
|
|
|
<nav class="navbar navbar-expand-md navbar-dark">
|
|
|
|
<div class="container-fluid">
|
|
|
|
<a class="navbar-brand" href="/">
|
|
|
|
<i class="bi bi-app"></i>
|
|
|
|
Мой сайт
|
|
|
|
</a>
|
|
|
|
<button
|
|
|
|
class="navbar-toggler"
|
|
|
|
type="button"
|
|
|
|
data-bs-toggle="collapse"
|
|
|
|
data-bs-target="#navbarNav"
|
|
|
|
aria-controls="navbarNav"
|
|
|
|
aria-expanded="false"
|
|
|
|
aria-label="Toggle navigation"
|
|
|
|
>
|
|
|
|
<span class="navbar-toggler-icon"></span>
|
|
|
|
</button>
|
|
|
|
<div class="navbar-collapse collapse justify-content-end" id="navbarNav">
|
|
|
|
<div class="navbar-nav">
|
|
|
|
<a class="nav-link" href="./index.html">Главная страница</a>
|
|
|
|
<a class="nav-link" href="./page2.html">Вторая страница</a>
|
|
|
|
<a class="nav-link" href="./page3.html">Третья страница</a>
|
|
|
|
<a class="nav-link active" href="./page-js.html">JavaScript</a>
|
|
|
|
</div>
|
2024-10-09 15:13:24 +04:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-11-07 10:32:00 +04:00
|
|
|
</nav>
|
|
|
|
</header>
|
|
|
|
<main class="container-fluid p-3">
|
2024-11-14 15:11:00 +04:00
|
|
|
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#studentModal">
|
|
|
|
New student
|
|
|
|
</button>
|
|
|
|
<table class="table table-sm table-hover mt-2">
|
2024-11-07 10:32:00 +04:00
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th scope="col">#</th>
|
|
|
|
<th scope="col">Last</th>
|
|
|
|
<th scope="col">First</th>
|
|
|
|
<th scope="col">Birthday</th>
|
|
|
|
<th scope="col">E-Mail</th>
|
|
|
|
<th scope="col">Phone</th>
|
|
|
|
<th scope="col">Group</th>
|
|
|
|
<th scope="col"></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody id="students"></tbody>
|
|
|
|
</table>
|
2024-11-14 15:11:00 +04:00
|
|
|
|
|
|
|
<div class="modal fade" id="studentModal" tabindex="-1">
|
|
|
|
<div class="modal-dialog">
|
|
|
|
<div class="modal-content">
|
|
|
|
<form>
|
|
|
|
<div class="modal-header">
|
|
|
|
<h1 class="modal-title fs-5">Student</h1>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="btn-close"
|
|
|
|
data-bs-dismiss="modal"
|
|
|
|
aria-label="Close"
|
|
|
|
></button>
|
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="id" class="form-label">ID:</label>
|
|
|
|
<input type="text" class="form-control" id="id" disabled />
|
|
|
|
</div>
|
|
|
|
<div class="mb-3">
|
2024-11-28 14:35:33 +04:00
|
|
|
<label for="last_name" class="form-label">Last Name:</label>
|
|
|
|
<input type="text" class="form-control" id="last_name" required />
|
2024-11-14 15:11:00 +04:00
|
|
|
</div>
|
|
|
|
<div class="mb-3">
|
2024-11-28 14:35:33 +04:00
|
|
|
<label for="first_name" class="form-label">First Name:</label>
|
|
|
|
<input type="text" class="form-control" id="first_name" required />
|
2024-11-14 15:11:00 +04:00
|
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="bdate" class="form-label">Birth date:</label>
|
|
|
|
<input type="date" class="form-control" id="bdate" required />
|
|
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="email" class="form-label">Email:</label>
|
|
|
|
<input type="email" class="form-control" id="email" required />
|
|
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
|
|
<label for="phone" class="form-label">Phone:</label>
|
|
|
|
<input type="text" class="form-control" id="phone" required />
|
|
|
|
</div>
|
|
|
|
<div class="mb-3">
|
2024-11-28 14:35:33 +04:00
|
|
|
<select class="form-select" aria-label="Select group" required>
|
|
|
|
<option value="">Select group</option>
|
2024-11-14 15:11:00 +04:00
|
|
|
<option value="1">One</option>
|
|
|
|
<option value="2">Two</option>
|
|
|
|
<option value="3">Three</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
|
|
|
<button id="saveStudent" type="submit" class="btn btn-primary">Save</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-11-07 10:32:00 +04:00
|
|
|
</main>
|
|
|
|
<footer class="footer mt-auto d-flex flex-shrink-0 justify-content-center align-items-center">
|
|
|
|
Автор, 2022
|
|
|
|
</footer>
|
|
|
|
<script type="module">
|
2024-12-17 12:06:26 +04:00
|
|
|
import { addStudent, editStudent, getStudents, deleteStudent, getGroups } from "./js/api";
|
|
|
|
import studentModal from "./js/uimodal";
|
|
|
|
import studentTable from "./js/uitable";
|
2024-11-28 14:35:33 +04:00
|
|
|
|
2024-12-17 12:06:26 +04:00
|
|
|
const studentModalDialog = studentModal("studentModal", async (studentId, data) => {
|
|
|
|
if (!studentId) {
|
|
|
|
await addStudent(data);
|
|
|
|
} else {
|
|
|
|
await editStudent(studentId, data);
|
2024-11-28 14:35:33 +04:00
|
|
|
}
|
2024-12-17 12:06:26 +04:00
|
|
|
// eslint-disable-next-line no-use-before-define
|
|
|
|
getStudentsLogic();
|
2024-11-28 14:35:33 +04:00
|
|
|
});
|
|
|
|
|
2024-12-17 12:06:26 +04:00
|
|
|
const deleteStudentLogic = async (id) => {
|
2024-11-07 10:32:00 +04:00
|
|
|
// eslint-disable-next-line no-restricted-globals, no-alert
|
|
|
|
const answer = confirm(`Do you want to delete student with id = ${id}?`);
|
|
|
|
if (!answer) {
|
|
|
|
return;
|
|
|
|
}
|
2024-12-17 12:06:26 +04:00
|
|
|
deleteStudent(id);
|
2024-11-07 10:32:00 +04:00
|
|
|
};
|
2024-11-07 10:24:20 +04:00
|
|
|
|
2024-12-17 12:06:26 +04:00
|
|
|
const studentTableUI = studentTable(
|
|
|
|
"students",
|
|
|
|
async (element) => studentModalDialog.setData(element),
|
|
|
|
async (id) => deleteStudentLogic(id)
|
|
|
|
);
|
2024-11-06 15:38:00 +04:00
|
|
|
|
2024-12-17 12:06:26 +04:00
|
|
|
const getGroupsLogic = async () => {
|
|
|
|
const groups = document.querySelector("#studentModal form select");
|
|
|
|
groups.innerHTML = `<option value="">Select group</option>`;
|
|
|
|
const data = await getGroups();
|
|
|
|
data.forEach((element) => {
|
|
|
|
groups.innerHTML += `<option value="${element.id}">${element.name}</option>`;
|
2024-11-07 10:24:20 +04:00
|
|
|
});
|
2024-12-17 12:06:26 +04:00
|
|
|
console.log("groups", data);
|
|
|
|
};
|
|
|
|
|
|
|
|
const getStudentsLogic = async () => {
|
|
|
|
getGroupsLogic();
|
|
|
|
const data = await getStudents();
|
|
|
|
studentTableUI.draw(data);
|
2024-11-07 10:32:00 +04:00
|
|
|
};
|
2024-10-23 16:01:04 +04:00
|
|
|
|
2024-11-07 10:32:00 +04:00
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
2024-12-17 12:06:26 +04:00
|
|
|
getStudentsLogic();
|
2024-11-07 10:32:00 +04:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|