1
0
forked from ScoDoc/ScoDoc
ScoDoc/app/scodoc/html_sco_header.py

247 lines
8.2 KiB
Python
Raw Normal View History

2020-09-26 16:19:37 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
2023-12-31 23:04:06 +01:00
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
2020-09-26 16:19:37 +02:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Emmanuel Viennet emmanuel.viennet@viennet.net
#
##############################################################################
"""HTML Header/Footer for ScoDoc pages"""
from flask import g, render_template, url_for
from flask_login import current_user
import app.scodoc.sco_utils as scu
2022-03-04 20:02:50 +01:00
from app import scodoc_flash_status_messages
from app.scodoc import html_sidebar
2021-08-21 17:07:44 +02:00
import sco_version
2020-09-26 16:19:37 +02:00
# Some constants:
2024-07-31 13:40:30 +02:00
BOOTSTRAP_JS = ["libjs/bootstrap/js/bootstrap.min.js", "libjs/purl.js"]
BOOTSTRAP_CSS = ["libjs/bootstrap/css/bootstrap.min.css"]
2020-09-26 16:19:37 +02:00
2021-06-13 18:29:53 +02:00
def standard_html_header():
"""Standard HTML header for pages outside depts"""
# not used in ZScolar, see sco_header
return f"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2021-06-13 18:29:53 +02:00
<html><head>
<title>ScoDoc: accueil</title>
<META http-equiv="Content-Type" content="text/html; charset={scu.SCO_ENCODING}">
2021-06-13 18:29:53 +02:00
<META http-equiv="Content-Style-Type" content="text/css">
<META name="LANG" content="fr">
<META name="DESCRIPTION" content="ScoDoc: gestion scolarite">
<link href="{scu.STATIC_DIR}/css/scodoc.css" rel="stylesheet" type="text/css"/>
2021-06-13 18:29:53 +02:00
</head><body>{scu.CUSTOM_HTML_HEADER_CNX}"""
2021-06-13 18:29:53 +02:00
def standard_html_footer():
"""Le pied de page HTML de la page d'accueil."""
return f"""<p class="footer">
2021-06-13 18:29:53 +02:00
Problème de connexion (identifiant, mot de passe): <em>contacter votre responsable ou chef de département</em>.</p>
<p>Probl&egrave;mes et suggestions sur le logiciel: <a href="mailto:{scu.SCO_USERS_LIST}">{scu.SCO_USERS_LIST}</a></p>
2021-06-13 18:29:53 +02:00
<p><em>ScoDoc est un logiciel libre développé par Emmanuel Viennet.</em></p>
</body></html>"""
2021-06-13 18:29:53 +02:00
_HTML_BEGIN = f"""<!DOCTYPE html>
2021-11-18 00:24:56 +01:00
<html lang="fr">
2021-06-13 18:29:53 +02:00
<head>
2021-11-18 00:24:56 +01:00
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2021-06-13 18:29:53 +02:00
<meta http-equiv="Content-Type" content="text/html; charset=%(encoding)s" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="LANG" content="fr" />
<meta name="DESCRIPTION" content="ScoDoc" />
2021-11-18 00:24:56 +01:00
<title>%(page_title)s</title>
2021-06-13 18:29:53 +02:00
<link type="text/css" rel="stylesheet" href="{scu.STATIC_DIR}/libjs/jquery-ui-1.10.4.custom/css/smoothness/jquery-ui-1.10.4.custom.min.css" />
2023-11-15 20:38:51 +01:00
<link href="{scu.STATIC_DIR}/css/scodoc.css" rel="stylesheet" type="text/css" />
<link href="{scu.STATIC_DIR}/css/menu.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="{scu.STATIC_DIR}/DataTables/datatables.min.css" />
2024-07-28 17:40:40 +02:00
<link href="{scu.STATIC_DIR}/css/gt_table.css" rel="stylesheet" type="text/css" />
<script src="{scu.STATIC_DIR}/libjs/menu.js"></script>
<script src="{scu.STATIC_DIR}/libjs/bubble.js"></script>
2024-07-28 19:15:51 +02:00
2021-06-13 18:29:53 +02:00
<script src="{scu.STATIC_DIR}/jQuery/jquery.js"></script>
2024-07-28 19:15:51 +02:00
<script src="{scu.STATIC_DIR}/jQuery/jquery-migrate-3.5.2.min.js"></script>
<script src="{scu.STATIC_DIR}/libjs/jquery.field.min.js"></script>
2021-06-13 18:29:53 +02:00
<script src="{scu.STATIC_DIR}/libjs/jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script>
<script src="{scu.STATIC_DIR}/DataTables/datatables.min.js"></script>
2021-06-13 18:29:53 +02:00
<script src="{scu.STATIC_DIR}/libjs/qtip/jquery.qtip-3.0.3.min.js"></script>
<link type="text/css" rel="stylesheet" href="{scu.STATIC_DIR}/libjs/qtip/jquery.qtip-3.0.3.min.css" />
2021-06-13 18:29:53 +02:00
2024-07-28 17:40:40 +02:00
<link type="text/css" rel="stylesheet" href="{scu.STATIC_DIR}/libjs/timepicker-1.3.5/jquery.timepicker.min.css" />
<script src="{scu.STATIC_DIR}/libjs/timepicker-1.3.5/jquery.timepicker.min.js"></script>
<script src="{scu.STATIC_DIR}/js/scodoc.js"></script>
<script src="{scu.STATIC_DIR}/js/etud_info.js"></script>
2024-07-28 17:40:40 +02:00
<script src="{scu.STATIC_DIR}/libjs/qtip/jquery.qtip-3.0.3.min.js"></script>
<link type="text/css" rel="stylesheet" href="{scu.STATIC_DIR}/libjs/qtip/jquery.qtip-3.0.3.min.css" />
2024-07-28 19:15:51 +02:00
<script>
document.addEventListener('DOMContentLoaded', function() {{
if (document.getElementById('gtrcontent')) {{
enableTooltips("gtrcontent");
}}
if (document.getElementById('sidebar')) {{
enableTooltips("sidebar");
}}
}});
</script>
2021-06-13 18:29:53 +02:00
"""
def scodoc_top_html_header(page_title="ScoDoc: bienvenue"):
2024-07-28 17:40:40 +02:00
"""HTML header for top level pages"""
2021-06-13 18:29:53 +02:00
H = [
_HTML_BEGIN % {"page_title": page_title, "encoding": scu.SCO_ENCODING},
2021-12-04 21:06:32 +01:00
"""</head><body id="gtrcontent">""",
2021-06-13 18:29:53 +02:00
scu.CUSTOM_HTML_HEADER_CNX,
]
return "\n".join(H)
2020-09-26 16:19:37 +02:00
# Header:
def sco_header(
# optional args
page_title="", # page title
2024-08-15 17:06:07 +02:00
no_sidebar=False, # hide sidebar
2022-06-09 07:39:58 +02:00
cssstyles=(), # additionals CSS sheets
javascripts=(), # additionals JS filenames to load
scripts=(), # script to put in page header
2020-09-26 16:19:37 +02:00
init_google_maps=False, # Google maps
titrebandeau="", # titre dans bandeau superieur
2022-06-09 07:39:58 +02:00
etudid=None,
formsemestre_id=None,
2020-09-26 16:19:37 +02:00
):
"""Main HTML page header for ScoDoc
Utilisé dans les anciennes pages. Les nouvelles pages utilisent le template Jinja.
"""
from app.scodoc.sco_formsemestre_status import formsemestre_page_title
2020-09-26 16:19:37 +02:00
if etudid is not None:
g.current_etudid = etudid
2022-03-04 20:02:50 +01:00
scodoc_flash_status_messages()
2020-09-26 16:19:37 +02:00
params = {
2021-08-21 17:07:44 +02:00
"page_title": page_title or sco_version.SCONAME,
2024-08-15 17:06:07 +02:00
"no_sidebar": no_sidebar,
"ScoURL": url_for("scolar.index_html", scodoc_dept=g.scodoc_dept),
2021-02-04 20:02:44 +01:00
"encoding": scu.SCO_ENCODING,
2020-09-26 16:19:37 +02:00
"titrebandeau_mkup": "<td>" + titrebandeau + "</td>",
"authuser": current_user.user_name,
2020-09-26 16:19:37 +02:00
}
2024-08-15 17:06:07 +02:00
if no_sidebar:
2020-09-26 16:19:37 +02:00
params["margin_left"] = "1em"
else:
params["margin_left"] = "140px"
2024-07-28 17:40:40 +02:00
H = [_HTML_BEGIN % params]
2020-09-26 16:19:37 +02:00
if init_google_maps:
# It may be necessary to add an API key:
2021-09-15 22:13:04 +02:00
H.append('<script src="https://maps.google.com/maps/api/js"></script>')
2020-09-26 16:19:37 +02:00
# Feuilles de style additionnelles:
for cssstyle in cssstyles:
H.append(
f"""<link type="text/css" rel="stylesheet" href="{scu.STATIC_DIR}/{cssstyle}" />\n"""
2020-09-26 16:19:37 +02:00
)
H.append(
f"""
2021-09-15 22:13:04 +02:00
<script>
const SCO_URL="{url_for("scolar.index_html", scodoc_dept=g.scodoc_dept)}";
2023-11-20 16:55:26 +01:00
const SCO_TIMEZONE="{scu.TIME_ZONE}";
2020-09-26 16:19:37 +02:00
</script>"""
)
2024-07-28 17:40:40 +02:00
if init_google_maps: # utilisé uniquement pour carte lycées
2020-09-26 16:19:37 +02:00
H.append(
f'<script src="{scu.STATIC_DIR}/libjs/jquery.ui.map.full.min.js"></script>'
2020-09-26 16:19:37 +02:00
)
2024-07-28 17:40:40 +02:00
2020-09-26 16:19:37 +02:00
# JS additionels
for js in javascripts:
H.append(f"""<script src="{scu.STATIC_DIR}/{js}"></script>\n""")
2020-09-26 16:19:37 +02:00
H.append(
f"""<style>
#gtrcontent {{
margin-left: {params["margin_left"]};
2020-09-26 16:19:37 +02:00
height: 100%%;
margin-bottom: 16px;
}}
2020-09-26 16:19:37 +02:00
</style>
"""
)
# Scripts de la page:
if scripts:
2021-09-15 22:13:04 +02:00
H.append("""<script>""")
2020-09-26 16:19:37 +02:00
for script in scripts:
H.append(script)
H.append("""</script>""")
2024-07-28 17:40:40 +02:00
# Fin head, Body et bandeau haut:
H.append(
f"""</head>
<!-- Legacy ScoDoc header -->
<body>
{scu.CUSTOM_HTML_HEADER}
2024-08-15 17:06:07 +02:00
{'' if no_sidebar else html_sidebar.sidebar(etudid)}
<div id="mobileNav" mobile="true" style="display:none;"></div>
2024-07-28 17:40:40 +02:00
<div id="gtrcontent">
"""
)
# En attendant le replacement complet de cette fonction,
# inclusion ici des messages flask
H.append(render_template("flashed_messages.j2"))
2020-09-26 16:19:37 +02:00
#
# Barre menu semestre:
2022-06-09 07:39:58 +02:00
H.append(formsemestre_page_title(formsemestre_id))
2020-09-26 16:19:37 +02:00
# div pour affichage messages temporaires
H.append('<div id="sco_msg" class="head_message"></div>')
#
H.append('<div class="sco-app-content">')
2021-07-12 15:13:10 +02:00
return "".join(H)
2020-09-26 16:19:37 +02:00
def sco_footer():
2021-01-01 18:40:47 +01:00
"""Main HTMl pages footer"""
2021-02-04 20:02:44 +01:00
return (
"""</div></div><!-- /gtrcontent -->"""
+ scu.CUSTOM_HTML_FOOTER
+ """</body></html>"""
2021-02-04 20:02:44 +01:00
)