06/19 Fix notification mark as read button
This commit is contained in:
@@ -71,15 +71,13 @@
|
|||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if not n.is_read %}
|
{% if not n.is_read %}
|
||||||
<form method="post"
|
<button type="button"
|
||||||
action="{{ url_for('notifications.mark_read', notif_id=n.id) }}"
|
class="btn btn-sm btn-outline-secondary mark-read-btn"
|
||||||
class="mb-0">
|
data-notif-id="{{ n.id }}"
|
||||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
data-url="{{ url_for('notifications.mark_read', notif_id=n.id) }}"
|
||||||
<button type="submit" class="btn btn-sm btn-outline-secondary"
|
title="Mark as read">
|
||||||
title="Mark as read">
|
<i class="bi bi-check2"></i>
|
||||||
<i class="bi bi-check2"></i>
|
</button>
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -125,3 +123,42 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_js %}
|
||||||
|
<script>
|
||||||
|
document.querySelectorAll('.mark-read-btn').forEach(function(btn) {
|
||||||
|
btn.addEventListener('click', function() {
|
||||||
|
var url = btn.dataset.url;
|
||||||
|
var csrfToken = {{ csrf_token() | tojson }};
|
||||||
|
btn.disabled = true;
|
||||||
|
fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'X-CSRFToken': csrfToken, 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
|
body: 'csrf_token=' + encodeURIComponent(csrfToken),
|
||||||
|
})
|
||||||
|
.then(function(res) { return res.json(); })
|
||||||
|
.then(function(data) {
|
||||||
|
if (data.ok) {
|
||||||
|
var li = btn.closest('li');
|
||||||
|
li.classList.remove('list-group-item-light', 'border-start', 'border-primary', 'border-3');
|
||||||
|
var badge = li.querySelector('.badge.bg-primary');
|
||||||
|
if (badge) badge.remove();
|
||||||
|
btn.remove();
|
||||||
|
var unreadBadge = document.querySelector('.badge.bg-danger');
|
||||||
|
if (unreadBadge) {
|
||||||
|
var count = parseInt(unreadBadge.textContent) - 1;
|
||||||
|
if (count <= 0) {
|
||||||
|
unreadBadge.remove();
|
||||||
|
var markAllForm = document.querySelector('form[action*="mark-all-read"]');
|
||||||
|
if (markAllForm) markAllForm.closest('.col-auto') && markAllForm.remove();
|
||||||
|
} else {
|
||||||
|
unreadBadge.textContent = count + ' unread';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function() { btn.disabled = false; });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user