Spaces:
Sleeping
Sleeping
Evaluacion Fase 3 PF, manejo de notificaciones y prevencion de envio datos
Browse files
tecnicas/static/js/span-notification.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function spanNotifaction(messageError, isError = true, time = 4500) {
|
| 2 |
+
const span = document.createElement("span");
|
| 3 |
+
span.textContent = messageError;
|
| 4 |
+
|
| 5 |
+
const div = document.createElement("div");
|
| 6 |
+
div.classList.add("alert", isError ? "alert-error" : "alert-success");
|
| 7 |
+
div.appendChild(span);
|
| 8 |
+
|
| 9 |
+
document.querySelector(".toast").append(div);
|
| 10 |
+
|
| 11 |
+
setTimeout(() => {
|
| 12 |
+
document.querySelector(".toast").removeChild(div);
|
| 13 |
+
}, time);
|
| 14 |
+
}
|
tecnicas/static/js/test_pf_rating_list.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
let dragged = null;
|
| 2 |
+
const nextProduct = `
|
| 3 |
+
<h2 class="text-2xl font-bold text-center">Éxito al guardar los datos</h2>
|
| 4 |
+
<div class="flex justify-center">
|
| 5 |
+
<button class="cts-btn-general cts-btn-primary btn-push" onclick="window.location.reload()">
|
| 6 |
+
Evaluar siguiente atributo
|
| 7 |
+
</button>
|
| 8 |
+
</div>`;
|
| 9 |
+
|
| 10 |
+
document.querySelectorAll(".draggable").forEach((el) => {
|
| 11 |
+
el.addEventListener("dragstart", () => {
|
| 12 |
+
dragged = el;
|
| 13 |
+
setTimeout(() => el.classList.add("opacity-50"), 0);
|
| 14 |
+
});
|
| 15 |
+
|
| 16 |
+
el.addEventListener("dragend", () => {
|
| 17 |
+
dragged = null;
|
| 18 |
+
el.classList.remove("opacity-50");
|
| 19 |
+
});
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
+
document.querySelectorAll(".dropzone").forEach((zone) => {
|
| 23 |
+
zone.addEventListener("dragover", (e) => e.preventDefault());
|
| 24 |
+
|
| 25 |
+
zone.addEventListener("drop", () => {
|
| 26 |
+
zone.appendChild(dragged);
|
| 27 |
+
});
|
| 28 |
+
});
|
| 29 |
+
|
| 30 |
+
document
|
| 31 |
+
.getElementById("question-save")
|
| 32 |
+
.addEventListener("click", showOptionsSave);
|
| 33 |
+
|
| 34 |
+
document
|
| 35 |
+
.getElementById("cancel-save")
|
| 36 |
+
.addEventListener("click", showQuestionSave);
|
| 37 |
+
|
| 38 |
+
document.getElementById("save-data").addEventListener("click", async () => {
|
| 39 |
+
showLoading();
|
| 40 |
+
const currentDataRatend = [];
|
| 41 |
+
|
| 42 |
+
document.querySelectorAll(".dropzone").forEach((zone) => {
|
| 43 |
+
const index = parseInt(zone.dataset.index);
|
| 44 |
+
const children = zone.querySelectorAll(".draggable");
|
| 45 |
+
|
| 46 |
+
children.forEach((el) => {
|
| 47 |
+
currentDataRatend.push({
|
| 48 |
+
name: el.dataset.code,
|
| 49 |
+
container: index,
|
| 50 |
+
});
|
| 51 |
+
});
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
if (!currentDataRatend.length) {
|
| 55 |
+
cancelLoading();
|
| 56 |
+
spanNotifaction("No has ordenado los productos");
|
| 57 |
+
} else if (
|
| 58 |
+
currentDataRatend.length != document.querySelectorAll(".draggable").length
|
| 59 |
+
) {
|
| 60 |
+
cancelLoading();
|
| 61 |
+
spanNotifaction("Faltan productos por calificar");
|
| 62 |
+
} else {
|
| 63 |
+
saveData(currentDataRatend);
|
| 64 |
+
}
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
async function saveData(dataToSend = []) {
|
| 68 |
+
const URL = "/cata/testers/api/ratingword/pf/list";
|
| 69 |
+
|
| 70 |
+
const csrfToken = document.querySelector("[name=csrfmiddlewaretoken]").value;
|
| 71 |
+
|
| 72 |
+
const requestData = {
|
| 73 |
+
phase: parseInt(document.querySelector(".cts-phase-pf").dataset.phase),
|
| 74 |
+
word: document.querySelector(".cts-phase-pf").dataset.nameWord,
|
| 75 |
+
data: dataToSend,
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
console.log(requestData);
|
| 79 |
+
|
| 80 |
+
try {
|
| 81 |
+
// const response = await fetch(URL, {
|
| 82 |
+
// method: "POST",
|
| 83 |
+
// headers: {
|
| 84 |
+
// "Content-Type": "application/json",
|
| 85 |
+
// "X-CSRFToken": csrfToken,
|
| 86 |
+
// "X-Requested-With": "XMLHttpRequest",
|
| 87 |
+
// },
|
| 88 |
+
// body: JSON.stringify(requestData),
|
| 89 |
+
// });
|
| 90 |
+
|
| 91 |
+
// if (!response.ok) {
|
| 92 |
+
// spanNotifaction("Fallo con la respuesta recibida");
|
| 93 |
+
// cancelLoading();
|
| 94 |
+
// return false;
|
| 95 |
+
// }
|
| 96 |
+
|
| 97 |
+
// const result = await response.json();
|
| 98 |
+
|
| 99 |
+
// const messError = result.error;
|
| 100 |
+
|
| 101 |
+
// if (messError) {
|
| 102 |
+
// spanNotifaction(messError);
|
| 103 |
+
// cancelLoading();
|
| 104 |
+
// return false;
|
| 105 |
+
// }
|
| 106 |
+
|
| 107 |
+
// spanNotifaction(result.message, false);
|
| 108 |
+
const containerRatings = document.querySelector(".container-rating-word");
|
| 109 |
+
containerRatings.innerHTML = "";
|
| 110 |
+
containerRatings.innerHTML = nextProduct;
|
| 111 |
+
cancelLoading();
|
| 112 |
+
return true;
|
| 113 |
+
} catch (error) {
|
| 114 |
+
console.log(error);
|
| 115 |
+
cancelLoading();
|
| 116 |
+
spanNotifaction("¡Oh! Ocurrió un error al tratar de guardar los datos");
|
| 117 |
+
return false;
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
function showLoading() {
|
| 122 |
+
document.getElementById("save-data").classList.add("hidden");
|
| 123 |
+
document.getElementById("cancel-save").classList.add("hidden");
|
| 124 |
+
document.getElementById("loading-data-save").classList.remove("hidden");
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
function cancelLoading() {
|
| 128 |
+
document.getElementById("loading-data-save").classList.add("hidden");
|
| 129 |
+
document.getElementById("question-save").classList.remove("hidden");
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
function showOptionsSave() {
|
| 133 |
+
document.getElementById("question-save").classList.add("hidden");
|
| 134 |
+
document.getElementById("save-data").classList.remove("hidden");
|
| 135 |
+
document.getElementById("cancel-save").classList.remove("hidden");
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
function showQuestionSave() {
|
| 139 |
+
document.getElementById("question-save").classList.remove("hidden");
|
| 140 |
+
document.getElementById("save-data").classList.add("hidden");
|
| 141 |
+
document.getElementById("cancel-save").classList.add("hidden");
|
| 142 |
+
}
|
tecnicas/templates/tecnicas/components/toast-container.html
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% load static %}
|
| 2 |
+
<div class="toast toast-center"></div>
|
| 3 |
+
<script src="{% static 'js/span-notification.js' %}"></script>
|
tecnicas/templates/tecnicas/forms_tester/test_pf_rating_list.html
CHANGED
|
@@ -4,34 +4,6 @@
|
|
| 4 |
|
| 5 |
{% block title %}Convencional{% endblock %}
|
| 6 |
|
| 7 |
-
{% block extra_css %}
|
| 8 |
-
<style>
|
| 9 |
-
input[type="range"]::-webkit-slider-thumb {
|
| 10 |
-
-webkit-appearance: none;
|
| 11 |
-
appearance: none;
|
| 12 |
-
width: 24px;
|
| 13 |
-
height: 24px;
|
| 14 |
-
border-radius: 50%;
|
| 15 |
-
background: var(--color-blue-500);
|
| 16 |
-
cursor: pointer;
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
input[type="range"]::-moz-range-thumb {
|
| 20 |
-
width: 24px;
|
| 21 |
-
height: 24px;
|
| 22 |
-
border-radius: 50%;
|
| 23 |
-
background: #3b82f6;
|
| 24 |
-
cursor: pointer;
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
@media (width < 40rem) {
|
| 28 |
-
.container-forms {
|
| 29 |
-
width: inherit;
|
| 30 |
-
}
|
| 31 |
-
}
|
| 32 |
-
</style>
|
| 33 |
-
{% endblock %}
|
| 34 |
-
|
| 35 |
{% block content %}
|
| 36 |
<article class="cts-container-main">
|
| 37 |
<article class="cts-wrap-content text-black">
|
|
@@ -88,29 +60,72 @@
|
|
| 88 |
</div>
|
| 89 |
</section>
|
| 90 |
|
| 91 |
-
<section class="flex
|
| 92 |
-
<p>
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
</section>
|
| 97 |
</article>
|
| 98 |
|
| 99 |
-
<article class="
|
| 100 |
-
|
| 101 |
-
<
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
{% for product in products %}
|
| 105 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
{% endfor %}
|
| 107 |
-
</
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
</article>
|
|
|
|
|
|
|
| 110 |
</article>
|
| 111 |
</article>
|
| 112 |
{% endblock %}
|
| 113 |
|
| 114 |
{% block extra_js %}
|
| 115 |
<script src="{% static 'js/actions-form.js' %}"></script>
|
|
|
|
| 116 |
{% endblock %}
|
|
|
|
| 4 |
|
| 5 |
{% block title %}Convencional{% endblock %}
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
{% block content %}
|
| 8 |
<article class="cts-container-main">
|
| 9 |
<article class="cts-wrap-content text-black">
|
|
|
|
| 60 |
</div>
|
| 61 |
</section>
|
| 62 |
|
| 63 |
+
<section class="flex items-center justify-center flex-wrap gap-4">
|
| 64 |
+
<div class="bg-surface-ligt p-2 rounded-lg flex-1">
|
| 65 |
+
<p class="text-lg font-bold text-center">
|
| 66 |
+
El atributo que se está evaluando:
|
| 67 |
+
</p>
|
| 68 |
+
<p class="word-rating text-2xl font-bold text-center" data-name-word="{{ word }}">
|
| 69 |
+
{{ word }}
|
| 70 |
+
</p>
|
| 71 |
+
</div>
|
| 72 |
</section>
|
| 73 |
</article>
|
| 74 |
|
| 75 |
+
<article class="container-rating-word p-6 space-y-6 bg-surface-ligt rounded">
|
| 76 |
+
<!-- Definir toddos los productos para la escala -->
|
| 77 |
+
<h2 class="text-xl font-bold">Productos en la sesión</h2>
|
| 78 |
+
<div id="items" class="flex gap-4 flex-wrap justify-center">
|
| 79 |
+
{% for product in products %}
|
| 80 |
+
<div class="draggable bg-surface-sweet text-black font-bold px-4 py-2 rounded cursor-grab"
|
| 81 |
+
draggable="true" data-code="{{ product.codigoProducto }}">{{ product.codigoProducto }}</div>
|
| 82 |
+
{% endfor %}
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<section>
|
| 86 |
+
<!-- Definir toddos los espacion de escala ordinaria -->
|
| 87 |
+
<h2 class="text-xl font-bold mb-6">Escala ordinaria</h2>
|
| 88 |
+
<div id="containers" class="flex gap-6 flex-wrap justify-center">
|
| 89 |
{% for product in products %}
|
| 90 |
+
<section class="w-fit space-y-2">
|
| 91 |
+
<div class="dropzone w-32 min-h-16 bg-surface-alter-card border-2 border-dashed border-gray-500 rounded p-2 space-y-2"
|
| 92 |
+
data-index="{{ forloop.counter }}"></div>
|
| 93 |
+
<p class="text-center text-2xl">{{ forloop.counter }}</p>
|
| 94 |
+
</section>
|
| 95 |
{% endfor %}
|
| 96 |
+
</div>
|
| 97 |
+
|
| 98 |
+
<!-- Linea de menor a mayor -->
|
| 99 |
+
<section>
|
| 100 |
+
<div class="flex justify-center items-center gap-4">
|
| 101 |
+
<span class="text-2xl">➖</span>
|
| 102 |
+
<hr class="border-2 flex-1">
|
| 103 |
+
<SPan class="text-2xl">➕</SPan>
|
| 104 |
+
</div>
|
| 105 |
+
<p class="text-center text-sm">Valores de menor a mayor</p>
|
| 106 |
+
</section>
|
| 107 |
+
</section>
|
| 108 |
+
|
| 109 |
+
<section class="flex justify-end gap-4">
|
| 110 |
+
<button id="question-save" class="cts-btn-general cts-btn-secondary btn-push">
|
| 111 |
+
¿Guardar datos actuales?
|
| 112 |
+
</button>
|
| 113 |
+
<button id="save-data" class="cts-btn-general cts-btn-primary btn-push hidden">
|
| 114 |
+
Guardar
|
| 115 |
+
</button>
|
| 116 |
+
<button id="cancel-save" class="cts-btn-general cts-btn-error btn-push hidden">
|
| 117 |
+
Cancelar
|
| 118 |
+
</button>
|
| 119 |
+
<span id="loading-data-save" class="loading loading-spinner loading-xl text-accent hidden"></span>
|
| 120 |
+
</section>
|
| 121 |
</article>
|
| 122 |
+
|
| 123 |
+
{% include "../components/toast-container.html" %}
|
| 124 |
</article>
|
| 125 |
</article>
|
| 126 |
{% endblock %}
|
| 127 |
|
| 128 |
{% block extra_js %}
|
| 129 |
<script src="{% static 'js/actions-form.js' %}"></script>
|
| 130 |
+
<script src="{% static 'js/test_pf_rating_list.js' %}"></script>
|
| 131 |
{% endblock %}
|