microblog/app/templates/base.html

174 lines
7.1 KiB
HTML
Raw Permalink Normal View History

2017-09-05 06:28:11 +00:00
<!doctype html>
2017-09-27 06:43:28 +00:00
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% if title %}
<title>{{ title }} - Microblog</title>
{% else %}
2017-09-30 07:21:17 +00:00
<title>{{ _('Welcome to Microblog') }}</title>
2017-09-27 06:43:28 +00:00
{% endif %}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container">
<a class="navbar-brand" href="{{ url_for('main.index') }}">Microblog</a>
2017-09-27 06:43:28 +00:00
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" aria-current="page" href="{{ url_for('main.index') }}">{{ _('Home') }}</a>
2017-09-27 06:43:28 +00:00
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="{{ url_for('main.explore') }}">{{ _('Explore') }}</a>
2017-09-27 06:43:28 +00:00
</li>
2017-09-20 19:51:53 +00:00
{% if g.search_form %}
<form class="navbar-form navbar-left" method="get" action="{{ url_for('main.search') }}">
<div class="form-group">
{{ g.search_form.q(size=20, class='form-control', placeholder=g.search_form.q.label.text) }}
</div>
</form>
{% endif %}
2017-09-27 06:43:28 +00:00
</ul>
<ul class="navbar-nav mb-2 mb-lg-0">
2017-09-13 06:31:39 +00:00
{% if current_user.is_anonymous %}
2017-09-27 06:43:28 +00:00
<li class="nav-item">
<a class="nav-link" aria-current="page" href="{{ url_for('auth.login') }}">{{ _('Login') }}</a>
2017-09-27 06:43:28 +00:00
</li>
2017-09-13 06:31:39 +00:00
{% else %}
2017-11-13 07:53:18 +00:00
<li class="nav-item">
<a class="nav-link" aria-current="page" href="{{ url_for('main.messages') }}">{{ _('Messages') }}
{% set new_messages = current_user.new_messages() %}
<span id="message_count" class="badge text-bg-danger"
style="visibility: {% if new_messages %}visible
{% else %}hidden{% endif %};">
{{ new_messages }}
</span>
</a>
</li>
2017-09-27 06:43:28 +00:00
<li class="nav-item">
<a class="nav-link" aria-current="page" href="{{ url_for('main.user', username=current_user.username) }}">{{ _('Profile') }}</a>
2017-09-27 06:43:28 +00:00
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="{{ url_for('auth.logout') }}">{{ _('Logout') }}</a>
2017-09-27 06:43:28 +00:00
</li>
2017-09-13 06:31:39 +00:00
{% endif %}
2017-09-27 06:43:28 +00:00
</ul>
2017-09-05 07:04:56 +00:00
</div>
2017-09-27 06:43:28 +00:00
</div>
</nav>
<div class="container mt-3">
2017-11-20 07:57:09 +00:00
{% if current_user.is_authenticated %}
{% with tasks = current_user.get_tasks_in_progress() %}
{% if tasks %}
{% for task in tasks %}
<div class="alert alert-success" role="alert">
{{ task.description }}
<span id="{{ task.id }}-progress">{{ task.get_progress() }}</span>%
</div>
{% endfor %}
{% endif %}
{% endwith %}
{% endif %}
2017-09-27 06:43:28 +00:00
{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
<div class="alert alert-info" role="alert">{{ message }}</div>
{% endfor %}
{% endif %}
{% endwith %}
{% block content %}{% endblock %}
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
2017-09-29 05:28:20 +00:00
{{ moment.include_moment() }}
2017-09-30 07:21:17 +00:00
{{ moment.lang(g.locale) }}
2017-10-05 22:34:15 +00:00
<script>
async function translate(sourceElem, destElem, sourceLang, destLang) {
document.getElementById(destElem).innerHTML =
'<img src="{{ url_for('static', filename='loading.gif') }}">';
const response = await fetch('/translate', {
method: 'POST',
headers: {'Content-Type': 'application/json; charset=utf-8'},
body: JSON.stringify({
text: document.getElementById(sourceElem).innerText,
source_language: sourceLang,
dest_language: destLang
})
})
const data = await response.json();
document.getElementById(destElem).innerText = data.text;
}
function initialize_popovers() {
const popups = document.getElementsByClassName('user_popup');
for (let i = 0; i < popups.length; i++) {
const popover = new bootstrap.Popover(popups[i], {
content: 'Loading...',
trigger: 'hover focus',
placement: 'right',
html: true,
sanitize: false,
delay: {show: 500, hide: 0},
container: popups[i],
customClass: 'd-inline',
});
popups[i].addEventListener('show.bs.popover', async (ev) => {
if (ev.target.popupLoaded) {
return;
}
const response = await fetch('/user/' + ev.target.innerText.trim() + '/popup');
const data = await response.text();
const popover = bootstrap.Popover.getInstance(ev.target);
if (popover && data) {
ev.target.popupLoaded = true;
popover.setContent({'.popover-body': data});
flask_moment_render_all();
}
});
}
}
document.addEventListener('DOMContentLoaded', initialize_popovers);
2017-11-13 07:53:18 +00:00
function set_message_count(n) {
const count = document.getElementById('message_count');
count.innerText = n;
count.style.visibility = n ? 'visible' : 'hidden';
}
2017-11-20 07:57:09 +00:00
function set_task_progress(task_id, progress) {
const progressElement = document.getElementById(task_id + '-progress');
if (progressElement) {
progressElement.innerText = progress;
}
}
2017-11-13 07:53:18 +00:00
{% if current_user.is_authenticated %}
function initialize_notifications() {
let since = 0;
setInterval(async function() {
const response = await fetch('{{ url_for('main.notifications') }}?since=' + since);
const notifications = await response.json();
for (let i = 0; i < notifications.length; i++) {
2017-11-20 07:57:09 +00:00
switch (notifications[i].name) {
case 'unread_message_count':
set_message_count(notifications[i].data);
break;
case 'task_progress':
set_task_progress(notifications[i].data.task_id,
notifications[i].data.progress);
break;
}
2017-11-13 07:53:18 +00:00
since = notifications[i].timestamp;
}
}, 10000);
}
document.addEventListener('DOMContentLoaded', initialize_notifications);
{% endif %}
2017-10-05 22:34:15 +00:00
</script>
2017-09-18 05:41:40 +00:00
</body>
2017-09-05 06:28:11 +00:00
</html>