From b6c31780525ffc96ad557ca7586d22a52ef31277 Mon Sep 17 00:00:00 2001
From: Yohann D'ANELLO <yohann.danello@gmail.com>
Date: Thu, 12 Mar 2020 10:53:06 +0100
Subject: [PATCH] Dynamic page

---
 templates/base.html            |  3 ++-
 templates/note/conso_form.html | 34 ++++++++++++++--------------------
 2 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/templates/base.html b/templates/base.html
index d57dab89..43f1ae5f 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -86,7 +86,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
                 {% if user.is_authenticated %}
                     <li class="dropdown">
                         <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
-                            <i class="fa fa-user"></i> {{ user.username }} ({{ user.note.balance | pretty_money }})
+                            <i class="fa fa-user"></i>
+                            <span id="user_balance">{{ user.username }} ({{ user.note.balance | pretty_money }})</span>
                         </a>
                         <div class="dropdown-menu dropdown-menu-right"
                              aria-labelledby="navbarDropdownMenuLink">
diff --git a/templates/note/conso_form.html b/templates/note/conso_form.html
index 35c2ab82..10b6e25f 100644
--- a/templates/note/conso_form.html
+++ b/templates/note/conso_form.html
@@ -108,7 +108,7 @@
         </div>
     </div>
 
-    <div class="card shadow mb-4">
+    <div class="card shadow mb-4" id="history">
         <div class="card-header">
             <p class="card-text font-weight-bold">
                 Historique des transactions récentes
@@ -279,31 +279,25 @@
                                 "destination": {{ button.destination.pk }},
                                 "category": {{ button.category.id }},
                                 "template": {{ button.id }}
-                            }, reloadWithTurbolinks);
+                            }, function () {
+                                consos = [];
+                                $("#note_list").html("");
+                                $("#alias_matched").html("");
+                                refreshHistory();
+                                refreshBalance();
+                            });
                         });
-
-                        reloadWithTurbolinks();
                     });
                 {% endif %}
             {% endfor %}
         });
 
-        var reloadWithTurbolinks = (function () {
-            var scrollPosition;
-
-            function reload () {
-                scrollPosition = [window.scrollX, window.scrollY];
-                Turbolinks.visit(window.location.toString(), { action: 'replace' })
-            }
-
-            document.addEventListener('turbolinks:load', function () {
-                if (scrollPosition) {
-                    window.scrollTo.apply(window, scrollPosition);
-                    scrollPosition = null;
-                }
-            });
+        function refreshBalance() {
+            $("#user_balance").load("/ #user_balance");
+        }
 
-            return reload;
-        })();
+        function refreshHistory() {
+            $("#history").load("/note/consos/ #history");
+        }
     </script>
 {% endblock %}
-- 
GitLab