Skip to content

Commit

Permalink
Get/set mod cookies in js only
Browse files Browse the repository at this point in the history
  • Loading branch information
ffont committed Oct 26, 2023
1 parent e301c22 commit d02fe02
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
24 changes: 16 additions & 8 deletions freesound/static/bw-frontend/src/pages/moderation.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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) => {
Expand Down
6 changes: 3 additions & 3 deletions templates_bw/moderation/assigned.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ <h5>No sound tickets in your queue... &#128543</h5>
<div class="v-spacing-4">
<div>
<label for="include-deferred">
<input type="checkbox" class="bw-checkbox" id="include-deferred" {% if default_include_deferred %}checked="checked"{% endif %}/>Include deferred tickets when selecting
<input type="checkbox" class="bw-checkbox" id="include-deferred" />Include deferred tickets when selecting
</label>
</div>
<div>
<label for="autoplay-sounds">
<input type="checkbox" class="bw-checkbox" id="autoplay-sounds" {% if default_autoplay %}checked="checked"{% endif %}/>Autoplay sounds when selecting
<input type="checkbox" class="bw-checkbox" id="autoplay-sounds" />Autoplay sounds when selecting
</label>
</div>
<div>
<label for="autoscroll-sounds">
<input type="checkbox" class="bw-checkbox" id="autoscroll-sounds" {% if default_autoscroll %}checked="checked"{% endif %}/>Scroll to sounds when selecting
<input type="checkbox" class="bw-checkbox" id="autoscroll-sounds" />Scroll to sounds when selecting
</label>
</div>
<div class="text-grey">
Expand Down
4 changes: 1 addition & 3 deletions tickets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d02fe02

Please sign in to comment.