Publication per student: checkbox in lab column, partial state in eye, cursor on Variant

This commit is contained in:
2026-10-02 00:33:16 +03:00
parent 64fdf61d98
commit 95a306c712
14 changed files with 329 additions and 117 deletions

View File

@@ -253,6 +253,47 @@ function removeCommentTemplate(text, done) {
.catch(function () { showToast('Не удалось удалить комментарий.', 'error'); });
}
/* ---------- Публикация оценки и комментариев отдельному студенту ---------- */
function attachPublishToggles() {
var urlEl = $id('pub-url');
if (!urlEl) return;
var csrfEl = document.querySelector('input[name="_csrf"]');
document.querySelectorAll('.pub-toggle').forEach(function (cb) {
cb.addEventListener('change', function () {
var desired = cb.checked;
var body = new URLSearchParams();
body.set('_csrf', csrfEl ? csrfEl.value : '');
body.set('labId', cb.getAttribute('data-lab') || '');
body.set('studentId', cb.getAttribute('data-student') || '');
body.set('published', desired ? 'true' : 'false');
cb.disabled = true;
fetch(urlEl.value, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: body.toString()
})
.then(function (r) { return r.ok ? r.json() : { ok: false }; })
.then(function (res) {
cb.disabled = false;
if (res && res.ok) {
showToast(desired
? 'Оценка и комментарии опубликованы студенту.'
: 'Оценка и комментарии скрыты от студента.');
} else {
cb.checked = !desired;
showToast((res && res.error) || 'Не удалось изменить публикацию.', 'error');
}
})
.catch(function () {
cb.disabled = false;
cb.checked = !desired;
showToast('Не удалось изменить публикацию.', 'error');
});
});
});
}
/* ---------- Индивидуальное задание (защита) ---------- */
function defenseStatusText(status, code, seconds) {
if (status === 'waiting') {
@@ -418,4 +459,5 @@ document.addEventListener('submit', function (ev) {
window.addEventListener('DOMContentLoaded', function () {
focusLab();
tickDefenseCells();
attachPublishToggles();
});