Fix in app

This commit is contained in:
absurdo 2023-11-26 20:40:18 +01:00
parent 3a38dd8952
commit 12ea2a085a
2 changed files with 69 additions and 2 deletions

View file

@ -115,6 +115,7 @@ for app_load in config_admin:
@admin_app.route('/admin/') @admin_app.route('/admin/')
def admin(): def admin():
return t.load_template('home.phtml', title=I18n.lang('admin', 'admin', 'Admin')) return t.load_template('home.phtml', title=I18n.lang('admin', 'admin', 'Admin'))
""" """
@ -394,6 +395,17 @@ def auth_check():
return {'error': error, 'you_cannot_login': you_cannot_login} return {'error': error, 'you_cannot_login': you_cannot_login}
@admin_app.route('/admin/change_theme/')
def change_theme():
theme_selected=str(request.args.get('theme', '0'))
print('Theme '+theme_selected)
session['theme']=theme_selected
error=0
return {'error': error}
""" """
@admin_app.route('/admin/recovery_password/') @admin_app.route('/admin/recovery_password/')
def recovery_password(): def recovery_password():

View file

@ -1,3 +1,16 @@
<%
from flask import session
dark_checked=''
dark_css=''
if session.get('theme', '0')=='1':
dark_checked='checked'
dark_css='dark'
%>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -20,7 +33,7 @@ ${load_js()|n}
<%block name="extra_header"> <%block name="extra_header">
</%block> </%block>
</head> </head>
<body> <body class="${dark_css}">
<div id="layer_loading" style="display:none;"><div id="container_loading"><div class="lds-dual-ring"></div></div></div> <div id="layer_loading" style="display:none;"><div id="container_loading"><div class="lds-dual-ring"></div></div></div>
<div id="languages_general"> <div id="languages_general">
</div> </div>
@ -98,7 +111,7 @@ ${load_js()|n}
</div> </div>
<div class="switch-slider"> <div class="switch-slider">
<label class="switch"> <label class="switch">
<input type="checkbox" name="theme" /> <input type="checkbox" name="theme" value="1" id="theme" ${dark_checked}/>
<span class="slider round"></span> <span class="slider round"></span>
</label> </label>
</div> </div>
@ -133,11 +146,53 @@ ${load_js()|n}
const slider = document.querySelector('input[name="theme"]'); const slider = document.querySelector('input[name="theme"]');
slider.addEventListener("change", function () { slider.addEventListener("change", function () {
//Block button while send to ajax.
$(this).prop("disabled",true);
var dark='';
if (this.checked) { if (this.checked) {
document.body.classList.add("dark"); document.body.classList.add("dark");
dark='1';
} else { } else {
document.body.classList.remove("dark"); document.body.classList.remove("dark");
dark='0';
} }
$.ajax({
url: "${url_for('admin_app.change_theme')}?theme="+dark,
type: 'GET',
data: {},
success: function (data) {
if(!data.error) {
console.log('Changed to dark in all pages');
}
else {
console.log('Cannot set dark theme in all pages!');
}
$(slider).prop("disabled",false);
},
error: function (data) {
alert('Error: '+data.status+' '+data.statusText);
$(slider).prop("disabled", false);
},
dataType: 'json'
});
}); });