-
-
-
${teacher.name}
-
+ htmlResult += /*html*/ `
+
+
+
+
+
${teacher.name}
+
+
-
-
-
Moyenne
+
+
Moyenne
-
- ${getStarsHtml(
- Math.round(
- (teacher.teaching_quality +
- teacher.kindness +
- teacher.authority +
- teacher.humor) /
- 4
- )
- )}
-
+
+ ${getStarsHtml(
+ Math.round(
+ (teacher.teaching_quality +
+ teacher.kindness +
+ teacher.authority +
+ teacher.humor) /
+ 4
+ )
+ )}
+
-
Autorité
-
- ${getStarsHtml(teacher.authority)}
-
+
Autorité
+
+ ${getStarsHtml(teacher.authority)}
+
-
Humour
-
${getStarsHtml(teacher.humor)}
+
Humour
+
${getStarsHtml(teacher.humor)}
-
Qualité d'enseignement
-
- ${getStarsHtml(teacher.teaching_quality)}
-
+
Qualité d'enseignement
+
+ ${getStarsHtml(teacher.teaching_quality)}
+
-
Gentilesse
-
${getStarsHtml(teacher.kindness)}
-
-
-
+
+
+ Lire les avis
+
-
`;
});
diff --git a/scripts/popup.js b/scripts/popup.js
index 83be28f..7b7b49d 100644
--- a/scripts/popup.js
+++ b/scripts/popup.js
@@ -1,30 +1,47 @@
function openPopup(id) {
- const popup = document.getElementById(id);
- popup.classList.add("show");
- localStorage.setItem("openPopupId", id);
+ const popup = document.getElementById(id);
+ popup.classList.add("show");
+ // localStorage.setItem("openPopupId", id);
+}
+
+function openRatingPopup(popupId, profId) {
+ openPopup(popupId);
+
+ const voteRatingButton = document.getElementById("voteRatingButton");
+ voteRatingButton.addEventListener("click", () => {
+ sendVotes(
+ profId,
+ parseFloat(document.getElementById("ratingTeachingQuality").value),
+ parseFloat(document.getElementById("ratingKindness").value),
+ parseFloat(document.getElementById("ratingAuthority").value),
+ parseFloat(document.getElementById("ratingHumor").value)
+ ).then(() => {
+ closePopup(popupId);
+ });
+ });
}
function closePopup(id) {
- const popup = document.getElementById(id);
- popup.classList.add("closing");
- setTimeout(() => {
- popup.classList.remove("show", "closing");
- }, 250);
- localStorage.removeItem("openPopupId");
+ const popup = document.getElementById(id);
+ popup.classList.add("closing");
+ setTimeout(() => {
+ popup.classList.remove("show", "closing");
+ }, 250);
+ // localStorage.removeItem("openPopupId");
}
-document.addEventListener("DOMContentLoaded", function() {
- const openPopupId = localStorage.getItem("openPopupId");
- if (openPopupId) {
- openPopup(openPopupId);
- }
-});
+// document.addEventListener("DOMContentLoaded", function () {
+// const openPopupId = localStorage.getItem("openPopupId");
+// if (openPopupId) {
+// openPopup(openPopupId);
+// }
+// });
document.addEventListener("keydown", function (event) {
- if (event.key === "Escape") {
- const popups = document.querySelectorAll(".show");
- popups.forEach(function (popup) {
- closePopup(popup.id);
- });
- }
+ if (event.key === "Escape") {
+ const popups = document.querySelectorAll(".show");
+ popups.forEach(function (popup) {
+ closePopup(popup.id);
+ });
+ }
});
diff --git a/scripts/rating.js b/scripts/rating.js
new file mode 100644
index 0000000..78b13a1
--- /dev/null
+++ b/scripts/rating.js
@@ -0,0 +1,16 @@
+async function sendVotes(profId, teachingQuality, kindness, authority, humor) {
+ const formData = new FormData();
+
+ let response = await fetch("api/newRating.php", {
+ method: "POST",
+ body: objectToFormData({
+ teacherId: profId,
+ teachingQuality: teachingQuality,
+ kindness: kindness,
+ authority: authority,
+ humor: humor,
+ }),
+ });
+
+ console.log(response);
+}
diff --git a/scripts/utils/objectToFormData.js b/scripts/utils/objectToFormData.js
new file mode 100644
index 0000000..439e644
--- /dev/null
+++ b/scripts/utils/objectToFormData.js
@@ -0,0 +1,9 @@
+function objectToFormData(obj) {
+ const formData = new FormData();
+ for (const key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ formData.append(key, obj[key]);
+ }
+ }
+ return formData;
+}