diff --git a/korektury/api/views.py b/korektury/api/views.py index dff32f19..5aa39837 100644 --- a/korektury/api/views.py +++ b/korektury/api/views.py @@ -1,15 +1,14 @@ from http import HTTPStatus -from django.http import HttpResponseForbidden, JsonResponse, HttpResponse +from django.http import JsonResponse, HttpResponse from django.shortcuts import get_object_or_404 from django.utils.html import linebreaks -from django.views.decorators.csrf import csrf_exempt from rest_framework import serializers from korektury.utils import send_email_notification_komentar from korektury.models import Oprava, KorekturovanePDF, Komentar, KorekturaTag -from personalni.models import Organizator, Osoba +from personalni.models import Organizator def korektury_stav_view(request, pdf_id: int, **kwargs): @@ -122,6 +121,7 @@ def opravy_a_komentare_view(request, pdf_id: int, **kwargs): tagy = list(map(int, tagy_raw.split(","))) oprava.tagy.add(*KorekturaTag.objects.filter(id__in=tagy)) Komentar.objects.create(oprava=oprava, autor=autor, text=text) + send_email_notification_komentar(oprava, autor, request) opravy = Oprava.objects.filter(pdf=pdf_id).all() diff --git a/korektury/templates/korektury/korekturovatko/__komentar.html b/korektury/templates/korektury/korekturovatko/__komentar.html index eaeb1171..b8525a20 100644 --- a/korektury/templates/korektury/korekturovatko/__komentar.html +++ b/korektury/templates/korektury/korekturovatko/__komentar.html @@ -91,11 +91,16 @@ fetch('{% url "korektury_api_komentar_smaz" %}', {method: 'POST', body: data}) .then(response => { if (!response.ok) {alert('Něco se nepovedlo:' + response.statusText);} - this.htmlElement.remove(); + this.smaz_pouze_na_strance(); place_comments(); }) .catch(error => {alert('Něco se nepovedlo:' + error);}); } } + + smaz_pouze_na_strance() { + delete komentare[this.id]; + this.htmlElement.remove(); + } } diff --git a/korektury/templates/korektury/korekturovatko/__oprava.html b/korektury/templates/korektury/korekturovatko/__oprava.html index 78f3a829..56d4d93b 100644 --- a/korektury/templates/korektury/korekturovatko/__oprava.html +++ b/korektury/templates/korektury/korekturovatko/__oprava.html @@ -163,11 +163,21 @@ fetch('{% url "korektury_api_oprava_smaz" %}', {method: 'POST', body: data}) .then(response => { if (!response.ok) {alert('Něco se nepovedlo:' + response.statusText);} - comments[this.img_id].splice(comments[this.img_id].indexOf(this), 1); + this.#smaz_pouze_na_strance() + updatuj_pocty_stavu(); + updatuj_pocty_zasluh(); place_comments(); }) .catch(error => {alert('Něco se nepovedlo:' + error);}); } } + + #smaz_pouze_na_strance() { + comments[this.img_id].splice(comments[this.img_id].indexOf(this), 1); + delete opravy[this.id]; + for (const komentar of Object.values(komentare)) if (komentar.oprava === this) komentar.smaz_pouze_na_strance(); + this.htmlElement.remove(); + this.pointer.remove(); + } } diff --git a/korektury/templates/korektury/korekturovatko/_main.html b/korektury/templates/korektury/korekturovatko/_main.html index e9a0a517..8dbbf7f6 100644 --- a/korektury/templates/korektury/korekturovatko/_main.html +++ b/korektury/templates/korektury/korekturovatko/_main.html @@ -22,7 +22,6 @@ .then(response => { if (!response.ok && catchError) {alert('Něco se nepovedlo:' + response.statusText);} else response.json().then(data => { - if (pri_uspechu) pri_uspechu(); for (const oprava_data of data["context"]) { const oprava = Oprava.update_or_create(oprava_data); for (const komentar_data of oprava_data["komentare"]) { @@ -33,12 +32,17 @@ updatuj_pocty_stavu(); updatuj_pocty_zasluh(); place_comments(); + if (pri_uspechu) pri_uspechu(); }); }) .catch(error => {if (catchError) alert('Něco se nepovedlo:' + error);}); } - update_all(); + window.addEventListener("load", _ => { + update_all({}, true, _ => { + if (location.hash !== "") location.hash = location.hash; // Po rozházení korektur sescrollujeme na kotvu v URL + }); + }); // FIXME není mi jasné, zda v {} nemá být `cache: "no-store"`, aby prohlížeč necachoval GET. document.getElementById("korektury-aktualizace").addEventListener("click", _ => update_all({}, false));