]> git.agnieray.net Git - galette.git/commitdiff
Display all messages the same way
authorJohan Cwiklinski <johan@x-tnd.be>
Sat, 17 Feb 2024 09:56:57 +0000 (10:56 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Sun, 18 Feb 2024 07:07:50 +0000 (08:07 +0100)
closes #1786

galette/lib/Galette/Controllers/AjaxController.php
galette/templates/default/elements/ajax_messages.html.twig [deleted file]
galette/templates/default/elements/js/messages.js.twig
galette/templates/default/elements/js/removal.js.twig
galette/templates/default/elements/messages_inline.html.twig
galette/templates/default/pages/members_list.html.twig
galette/templates/default/pages/preferences.html.twig

index 504e710a665013ca7745dda1c2990f1c4b856689..b60603c05e7839240fcfed803691be5db2dc393c 100644 (file)
@@ -63,7 +63,7 @@ use Throwable;
 class AjaxController extends AbstractController
 {
     /**
-     * Messages
+     * Messages as JSON array
      *
      * @param Request  $request  PSR Request
      * @param Response $response PSR Response
@@ -72,11 +72,43 @@ class AjaxController extends AbstractController
      */
     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);
     }
 
     /**
diff --git a/galette/templates/default/elements/ajax_messages.html.twig b/galette/templates/default/elements/ajax_messages.html.twig
deleted file mode 100644 (file)
index 61b940f..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-{% extends 'ajax.html.twig' %}
-
-{% block content %}
-    {% include 'elements/messages_inline.html.twig' %}
-{% endblock %}
index ffd0cc36d4ae7dfe7f1a83386fb5dbec5a4d42de..4ee8632365a2478192833bc7fd6e1ed24b2c4610 100644 (file)
@@ -25,7 +25,9 @@ $('.message.with-transition')
         $('body')
           .toast({
             displayTime: 'auto',
-            position: 'bottom right',
+            minDisplayTime: 5000,
+            wordsPerMinute: 80,
+            position: 'top right',
             message: '{{ success|e('js') }}',
             showIcon: 'check circle outline',
             class: 'success'
@@ -34,6 +36,56 @@ $('.message.with-transition')
     {% 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')
index 59d12ead7b4dd07bbfcd75ae518bcd1fc2f88cb5..7d655bd69f79b5cc52116a902f40face8aa4916b 100644 (file)
                                     $.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
+                                                    })
+                                                ;
+                                            }
                                         }
                                     });
                                 }
index 8645aef37cdaa612a692b1cd0b2ef39d9dae3911..a7e64bf15c3edd70e66878ce953a1dcfdf24163a 100644 (file)
     {% 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 #}
index 605d336c7d88c2193213f932b9b6e26df40fbe8a..98458ec30af21c0e5bb1a40047e89d79f155ae35 100644 (file)
                                 $.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
+                                                })
+                                            ;
+                                        }
                                     }
                                 });
                             }
index 5a8eef96bc56a06d5edcaab4067460a487290dd1..5c0df85f072a1e91e72a35dd3e50da6adc91ba90 100644 (file)
                                     $.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
+                                                    })
+                                                ;
+                                            }
                                         }
                                     });
                                 },