From d02fe02385f3887d9b4172e92691ebd6254f0369 Mon Sep 17 00:00:00 2001 From: ffont Date: Thu, 26 Oct 2023 12:52:15 +0200 Subject: [PATCH] Get/set mod cookies in js only --- .../bw-frontend/src/pages/moderation.js | 24 ++++++++++++------- templates_bw/moderation/assigned.html | 6 ++--- tickets/views.py | 4 +--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/freesound/static/bw-frontend/src/pages/moderation.js b/freesound/static/bw-frontend/src/pages/moderation.js index 754e53f7a..ca10355cb 100644 --- a/freesound/static/bw-frontend/src/pages/moderation.js +++ b/freesound/static/bw-frontend/src/pages/moderation.js @@ -1,4 +1,5 @@ -import {stopAllPlayers} from '../components/player/utils' +import { stopAllPlayers } from '../components/player/utils' +import { getCookie, setCookie } from "../utils/cookies"; const selectAllButton = document.getElementById('select-all'); const selectNoneButton = document.getElementById('select-none'); @@ -102,20 +103,27 @@ const shouldAutoscroll = () => { return autoscrollSoundsCheckbox.checked; } -// set cookie when changing checkbox +// set cookie when changing checkbox and set initial cookie value +if (getCookie('mod_include_d') === 'on') { + includeDeferredTicketsCheckbox.checked = true; +} +if (getCookie('mod_autoplay') === 'on') { + autoplaySoundsCheckbox.checked = true; +} +if (getCookie('mod_autoscroll') === 'on') { + autoscrollSoundsCheckbox.checked = true; +} + includeDeferredTicketsCheckbox.addEventListener('change', (evt) => { - const cookieValue = evt.target.checked ? 'on' : 'off'; - document.cookie = `mod_include_d=${cookieValue};path=/`; + setCookie('mod_include_d', evt.target.checked ? 'on' : 'off'); }) autoplaySoundsCheckbox.addEventListener('change', (evt) => { - const cookieValue = evt.target.checked ? 'on' : 'off'; - document.cookie = `mod_autoplay=${cookieValue};path=/`; + setCookie('mod_autoplay', evt.target.checked ? 'on' : 'off'); }) autoscrollSoundsCheckbox.addEventListener('change', (evt) => { - const cookieValue = evt.target.checked ? 'on' : 'off'; - document.cookie = `mod_autoscroll=${cookieValue};path=/`; + setCookie('mod_autoscroll', evt.target.checked ? 'on' : 'off'); }) const correspondingTicketIsDeferred = (checkbox) => { diff --git a/templates_bw/moderation/assigned.html b/templates_bw/moderation/assigned.html index 411703842..a1955bd65 100644 --- a/templates_bw/moderation/assigned.html +++ b/templates_bw/moderation/assigned.html @@ -57,17 +57,17 @@
No sound tickets in your queue... 😟
diff --git a/tickets/views.py b/tickets/views.py index c05eaa02b..91a43e22b 100644 --- a/tickets/views.py +++ b/tickets/views.py @@ -644,9 +644,7 @@ def moderation_assigned(request, user_id): "show_pagination": show_pagination, "max_selected_tickets_in_right_panel": settings.MAX_TICKETS_IN_MODERATION_ASSIGNED_PAGE_SELECTED_COLUMN, # Not used in BW "mod_sound_form": mod_sound_form, - "msg_form": msg_form, - "default_autoplay": request.GET.get('autoplay', 'on') == 'on', - "default_include_deferred": request.GET.get('include_d', '') == 'on', + "msg_form": msg_form } if using_beastwhoosh(request):