Self hosted FLOSS fitness/workout, nutrition and weight tracker
Handle redirects in AJAX, update browser history accordingly
Roland Geider211e3b57c14a
diff --git a/manager/context_processor.py b/manager/context_processor.pyindex d7bed74a7..aef21605a 100644--- a/manager/context_processor.py+++ b/manager/context_processor.py@@ -27,5 +27,8 @@ def processor(request):'DNT': request.META.get('HTTP_DNT', False),# User language- 'language': load_language()+ 'language': load_language(),++ # The current request+ 'request': request}diff --git a/manager/static/js/workout-manager.js b/manager/static/js/workout-manager.jsindex e00c2a77d..87deb4258 100644--- a/manager/static/js/workout-manager.js+++ b/manager/static/js/workout-manager.js@@ -313,6 +313,16 @@ function modal_dialog_form_edit(){$("#ajax-info").dialog("close");+ // If there was a redirect we must change the URL of the browser. Otherwise+ // a reload would not change the adress bar, but the content would.+ // Since it is not possible to get this URL from the AJAX request, we read it out+ // from a hidden HTML DIV in the document...+ current_url = $(data).find("#current-url").html();+ if(document.URL.indexOf(current_url))+ {+ history.pushState({}, "", current_url);+ }+// Note: loading the new page like this executes all its JS code$('body').html(data);}diff --git a/manager/templates/base.html b/manager/templates/base.htmlindex c22cadd69..036850f11 100644--- a/manager/templates/base.html+++ b/manager/templates/base.html@@ -114,6 +114,10 @@<section class="ym-grid linearize-level-1"><article class="ym-g66 ym-gl content"><div class="ym-gbox-left ym-clearfix" id="main-content">+ <!--+ This is needed as a clutch for us to handle redirects with AJAX+ -->+ <div id="current-url" style="display:none;">{{request.get_full_path}}</div>{% block content %}{% endblock %}</div></article>