added set_session, made hide_header work properly
This commit is contained in:
parent
0f141f3525
commit
abecc430a9
|
@ -1,36 +1,39 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<title>{% block title %}{% endblock %} - Titivillus</title>
|
||||
<link rel="stylesheet" type="text/css" href="{{ static('base.css') }}">
|
||||
<script>
|
||||
function toggleHeaderCookie(state) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', '{# url_for(".set_session", hide_header="on") #}', true);
|
||||
xhr.send();
|
||||
xhr.open('POST', '{{ url("set_session:index") }}', true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
xhr.setRequestHeader('X-CSRFToken', '{{ csrf_token }}');
|
||||
xhr.send('hide_header=' + state);
|
||||
}
|
||||
function toggleHeader() {
|
||||
if (document.getElementById('header').style.display == 'initial') {
|
||||
document.getElementById('header').style.display = 'none';
|
||||
document.getElementById('headerHidden').style.display = 'initial';
|
||||
//toggleHeaderCookie('on');
|
||||
toggleHeaderCookie('on');
|
||||
}
|
||||
else {
|
||||
document.getElementById('header').style.display = 'initial';
|
||||
document.getElementById('headerHidden').style.display = 'none';
|
||||
//toggleHeaderCookie('off');
|
||||
toggleHeaderCookie('off');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% block head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<ul id="header" class="header" style="{# if session.get("hide_header") == True %}display:none;{% else %}display:initial;{% endif #}">
|
||||
<ul id="header" class="header" style="{% if request.session.get("hide_header") == True %}display:none;{% else %}display:initial;{% endif %}">
|
||||
<li><a onclick="toggleHeader();" href="javascript:void(0);">⤒</a></li>
|
||||
<li><a href="{{ url('homepage:index') }}">Home</a></li>
|
||||
{% block header %}{% endblock %}
|
||||
</ul>
|
||||
<ul id="headerHidden" class="header" style="{# if session.get("hide_header") == True %}display:initial;{% else #}display:none;{# endif #}">
|
||||
<ul id="headerHidden" class="header" style="{% if request.session.get("hide_header") == True %}display:initial;{% else %}display:none;{% endif %}">
|
||||
<li><a onclick="toggleHeader();" href="javascript:void(0);">⤓</a></li>
|
||||
</ul>
|
||||
<div id="content">{% block content %}{% endblock %} </div>
|
||||
|
|
0
set_session/__init__.py
Normal file
0
set_session/__init__.py
Normal file
3
set_session/admin.py
Normal file
3
set_session/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
5
set_session/apps.py
Normal file
5
set_session/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SetSessionConfig(AppConfig):
|
||||
name = 'set_session'
|
0
set_session/migrations/__init__.py
Normal file
0
set_session/migrations/__init__.py
Normal file
3
set_session/models.py
Normal file
3
set_session/models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
3
set_session/tests.py
Normal file
3
set_session/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
12
set_session/urls.py
Normal file
12
set_session/urls.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
set_session app URL configuration.
|
||||
"""
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = 'set_session'
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
]
|
15
set_session/views.py
Normal file
15
set_session/views.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
/set_session app views.
|
||||
"""
|
||||
from django.http import HttpResponse
|
||||
|
||||
def index(request):
|
||||
"""
|
||||
A simple API endpoint for setting certain values in the users session.
|
||||
"""
|
||||
if request.POST.get('hide_header') == 'on':
|
||||
request.session['hide_header'] = True
|
||||
elif request.POST.get('hide_header') == 'off':
|
||||
request.session['hide_header'] = False
|
||||
return HttpResponse('true')
|
|
@ -7,7 +7,8 @@ from django.urls import include, path
|
|||
|
||||
urlpatterns = [
|
||||
path('', include('homepage.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
path('admin/', admin.site.urls),
|
||||
path('quest/', include('quest.urls')),
|
||||
path('create_quest/', include('create_quest.urls')),
|
||||
path('set_session/', include('set_session.urls')),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue
Block a user