pwa: allow multiple menu entries to display username (#29460)

This commit is contained in:
Frédéric Péters 2019-01-04 16:37:23 +01:00
parent 39a139991e
commit 4b63896c8d
2 changed files with 8 additions and 5 deletions

View File

@ -1,12 +1,13 @@
{% load combo %}
{% if entries|length %}
<div class="pwa-navigation" id="pwa-navigation">
<div class="pwa-navigation" id="pwa-navigation"
{% if include_user_name %}data-pwa-user-name="{% skeleton_extra_placeholder user-name %}{{user.get_full_name}}{% end_skeleton_extra_placeholder %}"{% endif %}>
<div>
<ul>
{% for entry in entries %}
<li class="{{ entry.css_class_names }}" data-entry-pk="{{ entry.pk }}"
{% if entry.notification_count %}data-notification-count-url="{{site_base}}/api/notification/count/"{% endif %}
{% if entry.use_user_name_as_label %}data-pwa-user-name="{% skeleton_extra_placeholder user-name %}{{user.get_full_name}}{% end_skeleton_extra_placeholder %}"{% endif %}>
{% if entry.use_user_name_as_label %}data-include-user-name{% endif %}>
<a href="{% if entry.link_page_id %}{{ site_base }}{% endif %}{{ entry.get_url }}"
{% if entry.icon %}style="background-image: url({{site_base}}{{entry.icon.url}});"{% endif %}
><span>{{ entry.get_label }}</span></a></li>
@ -15,8 +16,8 @@
</div>
</div>
<script>
$('li[data-pwa-user-name]').each(function(idx, elem) {
var user_name = $(this).data('pwa-user-name');
$('li[data-include-user-name]').each(function(idx, elem) {
var user_name = $(this).parents('#pwa-navigation').data('pwa-user-name');
if (user_name) {
$(this).find('span').text(user_name);
}

View File

@ -27,8 +27,10 @@ def pwa_navigation(context):
if settings.TEMPLATE_VARS.get('pwa_display') not in ('standalone', 'fullscreen'):
return ''
pwa_navigation_template = template.loader.get_template('combo/pwa/navigation.html')
entries = list(PwaNavigationEntry.objects.all())
context = {
'entries': list(PwaNavigationEntry.objects.all()),
'entries': entries,
'include_user_name': bool([x for x in entries if x.use_user_name_as_label]),
'user': context.get('user'),
'render_skeleton': context.get('render_skeleton'),
'site_base': context['request'].build_absolute_uri('/')[:-1],