mirror of
https://github.com/ae-utbm/sith.git
synced 2026-05-19 15:30:54 +00:00
fix: wrong notification update with fragments
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
<div id="quick-notifications"
|
<div id="quick-notifications"
|
||||||
x-data='{ messages: $notifications.getAll() }'
|
|
||||||
x-init='$notifications.addMany([
|
x-init='$notifications.addMany([
|
||||||
{%- for message in messages -%}
|
{%- for message in messages -%}
|
||||||
{%- if not message.extra_tags -%}
|
{%- if not message.extra_tags -%}
|
||||||
@@ -8,7 +7,7 @@
|
|||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
])'
|
])'
|
||||||
>
|
>
|
||||||
<template x-for="(message, index) in messages">
|
<template x-for="(message, index) in $notifications.getAll()">
|
||||||
<div class="alert" :class="`alert-${message.tag}`" x-transition>
|
<div class="alert" :class="`alert-${message.tag}`" x-transition>
|
||||||
<span class="alert-main" x-text="message.text"></span>
|
<span class="alert-main" x-text="message.text"></span>
|
||||||
<span class="clickable" @click="messages = messages.filter((item, i) => i !== index)">
|
<span class="clickable" @click="messages = messages.filter((item, i) => i !== index)">
|
||||||
|
|||||||
@@ -226,7 +226,7 @@
|
|||||||
<button type="button" onclick="checkbox_{{form_id}}(false);">{% trans %}Unselect All{% endtrans %}</button>
|
<button type="button" onclick="checkbox_{{form_id}}(false);">{% trans %}Unselect All{% endtrans %}</button>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro update_notifications(messages, clear) %}
|
{% macro update_notifications(messages, clear = True) %}
|
||||||
{# Update notification area from new messages sent by django backend
|
{# Update notification area from new messages sent by django backend
|
||||||
This is useful when performing fragment swaps to keep messages up to date
|
This is useful when performing fragment swaps to keep messages up to date
|
||||||
Without this, the fragment would need to take control of the notification area and
|
Without this, the fragment would need to take control of the notification area and
|
||||||
@@ -236,15 +236,14 @@
|
|||||||
messages: messages from django.contrib
|
messages: messages from django.contrib
|
||||||
clear : optional boolean that controls if notifications should be cleared first. True is the default
|
clear : optional boolean that controls if notifications should be cleared first. True is the default
|
||||||
#}
|
#}
|
||||||
{% set clear = clear|default(true) %}
|
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
<div x-init="() => {
|
<div x-init="() => {
|
||||||
{% if clear %}
|
{%- if clear -%}
|
||||||
$notifications.clear()
|
$notifications.clear();
|
||||||
{% endif %}
|
{%- endif -%}
|
||||||
{% for message in messages %}
|
{%- for message in messages -%}
|
||||||
$notifications.{{ message.tags }}('{{ message }}')
|
$notifications.{{ message.tags }}('{{ message }}');
|
||||||
{% endfor %}
|
{%- endfor -%}
|
||||||
}"></div>
|
}"></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class FragmentRenderer(Protocol):
|
|||||||
) -> SafeString: ...
|
) -> SafeString: ...
|
||||||
|
|
||||||
|
|
||||||
class FragmentMixin(TemplateResponseMixin, ContextMixin):
|
class FragmentMixin(TemplateResponseMixin, AllowFragment, ContextMixin):
|
||||||
"""Make a view buildable as a fragment that can be embedded in a template.
|
"""Make a view buildable as a fragment that can be embedded in a template.
|
||||||
|
|
||||||
Most fragments are used in two different ways :
|
Most fragments are used in two different ways :
|
||||||
|
|||||||
@@ -32,5 +32,7 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
|
{% if is_fragment %}
|
||||||
{{ update_notifications(messages) }}
|
{{ update_notifications(messages) }}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user