class AjaxController extends AbstractController
{
/**
- * Messages
+ * Messages as JSON array
*
* @param Request $request PSR Request
* @param Response $response PSR Response
*/
public function messages(Request $request, Response $response): Response
{
- $this->view->render(
- $response,
- 'elements/ajax_messages.html.twig'
- );
- return $response;
+ $messages = [];
+
+ $errors = $this->flash->getMessage('loginfault') ?? [];
+ $errors = array_merge($errors, $this->flash->getMessage('error_detected') ?? []);
+ $errors = array_merge($errors, $this->flash->getMessage('error') ?? []);
+
+ if (count($errors) > 0) {
+ $messages['error'] = [
+ 'title' => _T('- ERROR -'),
+ 'icon' => 'times',
+ 'messages' => $errors
+ ];
+ }
+
+ $warnings = $this->flash->getMessage('warning_detected') ?? [];
+ $warnings = array_merge($warnings, $this->flash->getMessage('warning') ?? []);
+
+ if (count($warnings) > 0) {
+ $messages['warning'] = [
+ 'title' => _T('- WARNING -'),
+ 'icon' => 'exclamation triangle',
+ 'messages' => $warnings
+ ];
+ }
+
+ $success = $this->flash->getMessage('success_detected') ?? [];
+ $success = array_merge($success, $this->flash->getMessage('succes') ?? []);
+
+ if (count($success) > 0) {
+ $messages['success'] = [
+ 'title' => '',
+ 'icon' => 'check circle outline',
+ 'messages' => $success
+ ];
+ }
+
+ return $this->withJson($response, $messages);
}
/**
+++ /dev/null
-{% extends 'ajax.html.twig' %}
-
-{% block content %}
- {% include 'elements/messages_inline.html.twig' %}
-{% endblock %}
$('body')
.toast({
displayTime: 'auto',
- position: 'bottom right',
+ minDisplayTime: 5000,
+ wordsPerMinute: 80,
+ position: 'top right',
message: '{{ success|e('js') }}',
showIcon: 'check circle outline',
class: 'success'
{% endfor %}
{% endif %}
+{# Let's see if there are loginfault messages to show #}
+{% set loginfaults = flash.getMessage('loginfault') %}
+{% if loginfault_detected is defined and loginfault_detected is iterable %}
+ {% for l in loginfault_detected %}
+ {% set loginfaults = loginfaults|merge([l]) %}
+ {% endfor %}
+{% endif %}
+
+{# Let's see if there are error messages to show #}
+{% set errors = flash.getMessage('error_detected') ?? []|merge(flash.getMessage('error') ?? [])|merge(loginfaults ?? []) %}
+{% if error_detected is defined and error_detected is iterable %}
+ {% for e in error_detected %}
+ {% set errors = errors|merge([e]) %}
+ {% endfor %}
+{% endif %}
+{% if errors is iterable and errors|length > 0 %}
+ {% for error in errors %}
+ $('body')
+ .toast({
+ displayTime: 0,
+ position: 'top right',
+ message: '{{ error|e('js') }}',
+ showIcon: 'times',
+ class: 'error'
+ })
+ ;
+ {% endfor %}
+{% endif %}
+
+{# Let's see if there are warning messages to show #}
+{% set warnings = flash.getMessage('warning_detected') ?? []|merge(flash.getMessage('warning') ?? []) %}
+{% if warning_detected is defined and warning_detected is iterable %}
+ {% for w in warning_detected %}
+ {% set warnings = warnings|merge([w]) %}
+ {% endfor %}
+{% endif %}
+{% if warnings is iterable and warnings|length > 0 %}
+ {% for warning in warnings %}
+ $('body')
+ .toast({
+ displayTime: 0,
+ position: 'top right',
+ message: '{{ warning|e('js') }}',
+ showIcon: 'exclamation triangle',
+ class: 'warning'
+ })
+ ;
+ {% endfor %}
+{% endif %}
+
{# Renew telemetry #}
{% if renew_telemetry is defined and renew_telemetry %}
$('body')
$.ajax({
url: '{{ url_for("ajaxMessages") }}',
method: "GET",
- success: function (message) {
- $('.main-content .message').remove();
- $('.main-content').prepend(message);
+ success: function (values) {
+ for (var type in values) {
+ var dtime = 0;
+ if (type == 'success') {
+ dtime = 'auto';
+ }
+ $('body')
+ .toast({
+ displayTime: dtime,
+ minDisplayTime: 5000,
+ wordsPerMinute: 80,
+ position: 'top right',
+ title: values[type]['title'],
+ message: values[type]['messages'].join('<br/>'),
+ showIcon: values[type]['icon'],
+ class: type
+ })
+ ;
+ }
}
});
}
{% endfor %}
{% endif %}
{% if errors is iterable and errors|length > 0 %}
- <div class="ui error icon message with-transition">
- <i class="times icon" aria-hidden="true"></i>
- <i class="window close outline icon" aria-hidden="true"></i>
- <div class="content">
- <div class="header">{{ _T("- ERROR -") }}</div>
- {% if errors|length > 1 %}
- <ul class="list">
- {% for error in errors %}
- <li>{{ error|raw }}</li>
- {% endfor %}
- </ul>
- {% else %}
- {% for error in errors %}
- <p>{{ error|raw }}</p>
- {% endfor %}
- {% endif %}
+ <noscript>
+ <div class="ui error icon message">
+ <i class="times icon" aria-hidden="true"></i>
+ <div class="content">
+ <div class="header">{{ _T("- ERROR -") }}</div>
+ {% if errors|length > 1 %}
+ <ul class="list">
+ {% for error in errors %}
+ <li>{{ error|raw }}</li>
+ {% endfor %}
+ </ul>
+ {% else %}
+ {% for error in errors %}
+ <p>{{ error|raw }}</p>
+ {% endfor %}
+ {% endif %}
+ </div>
</div>
- </div>
+ </noscript>
{% endif %}
{# Let's see if there are warning messages to show #}
{% endfor %}
{% endif %}
{% if warnings is iterable and warnings|length > 0 %}
- <div class="ui warning icon message with-transition">
- <i class="exclamation triangle icon" aria-hidden="true"></i>
- <i class="window close outline icon" aria-hidden="true"></i>
- <div class="content">
- <div class="header">{{ _T("- WARNING -") }}</div>
- {% if warnings|length > 1 %}
- <ul class="list">
- {% for warning in warnings %}
- <li>{{ warning|raw }}</li>
- {% endfor %}
- </ul>
- {% else %}
- {% for warning in warnings %}
- <p>{{ warning|raw }}</p>
- {% endfor %}
- {% endif %}
+ <noscript>
+ <div class="ui warning icon message">
+ <i class="exclamation triangle icon" aria-hidden="true"></i>
+ <div class="content">
+ <div class="header">{{ _T("- WARNING -") }}</div>
+ {% if warnings|length > 1 %}
+ <ul class="list">
+ {% for warning in warnings %}
+ <li>{{ warning|raw }}</li>
+ {% endfor %}
+ </ul>
+ {% else %}
+ {% for warning in warnings %}
+ <p>{{ warning|raw }}</p>
+ {% endfor %}
+ {% endif %}
+ </div>
</div>
- </div>
+ </noscript>
{% endif %}
{# Let's see if there are success messages to show #}
$.ajax({
url: '{{ url_for('ajaxMessages') }}',
method: "GET",
- success: function (message) {
- $('#asso_name').after(message);
+ success: function (values) {
+ for (var type in values) {
+ var dtime = 0;
+ if (type == 'success') {
+ dtime = 'auto';
+ }
+ $('body')
+ .toast({
+ displayTime: dtime,
+ minDisplayTime: 5000,
+ wordsPerMinute: 80,
+ position: 'top right',
+ title: values[type]['title'],
+ message: values[type]['messages'].join('<br/>'),
+ showIcon: values[type]['icon'],
+ class: type
+ })
+ ;
+ }
}
});
}
$.ajax({
url: '{{ url_for('ajaxMessages') }}',
method: "GET",
- success: function(message) {
- var message_inline = new DOMParser().parseFromString(message, 'text/html');
- var message_content = message_inline.body.querySelectorAll('div.content');
- $('body').toast({
- position: 'bottom right',
- message: message_content,
- showIcon: 'check circle outline',
- class: 'success'
- });
+ success: function (values) {
+ for (var type in values) {
+ var dtime = 0;
+ if (type == 'success') {
+ dtime = 'auto';
+ }
+ $('body')
+ .toast({
+ displayTime: dtime,
+ minDisplayTime: 5000,
+ wordsPerMinute: 80,
+ position: 'top right',
+ title: values[type]['title'],
+ message: values[type]['messages'].join('<br/>'),
+ showIcon: values[type]['icon'],
+ class: type
+ })
+ ;
+ }
}
});
},