diff --git a/paramecio2/modules/admin/app.py b/paramecio2/modules/admin/app.py index a4755f2..6d422a0 100644 --- a/paramecio2/modules/admin/app.py +++ b/paramecio2/modules/admin/app.py @@ -115,6 +115,7 @@ for app_load in config_admin: @admin_app.route('/admin/') def 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} +@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/') def recovery_password(): diff --git a/paramecio2/modules/admin/templates/dashboard.phtml b/paramecio2/modules/admin/templates/dashboard.phtml index 87fc458..cfc1d11 100644 --- a/paramecio2/modules/admin/templates/dashboard.phtml +++ b/paramecio2/modules/admin/templates/dashboard.phtml @@ -1,3 +1,16 @@ +<% + +from flask import session + +dark_checked='' +dark_css='' + +if session.get('theme', '0')=='1': + dark_checked='checked' + dark_css='dark' + + +%> @@ -20,7 +33,7 @@ ${load_js()|n} <%block name="extra_header"> - +
@@ -98,7 +111,7 @@ ${load_js()|n}
@@ -133,11 +146,53 @@ ${load_js()|n} const slider = document.querySelector('input[name="theme"]'); slider.addEventListener("change", function () { + + //Block button while send to ajax. + + $(this).prop("disabled",true); + + var dark=''; + if (this.checked) { document.body.classList.add("dark"); + + dark='1'; + } else { 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' + }); });