now refreshing the page when previous browser button is hit. fixes #29

This commit is contained in:
neil 2021-04-14 22:49:31 +02:00
parent ade36cf053
commit b45e65d427
2 changed files with 33 additions and 8 deletions

View File

@ -1,11 +1,36 @@
// on clicking Previous button in browser, reset the page
// needed to get another CSRF token and remove the spinning wheel
window.onpageshow = function() {
if (performance.getEntriesByType("navigation")[0].type == "back_forward") {
location.reload(false);
}
}
let browse_forms_button = get('browse_forms_button');
let new_link_button = get('new_link_button');
// csrf_token is retrieved from server-side template
document.getElementById('new_link_button').addEventListener('click', function () {
new_link(csrf_token);
new_link_button.addEventListener('click', function() {
get("csrf_token").value = csrf_token;
get("new_link").submit();
hideButtonsAndSpin();
});
function new_link(csrf) {
document.getElementById("csrf_token").value = csrf;
document.getElementById('new_link').submit();
document.getElementById('new_link_button').classList.add("hidden");
document.getElementById('loading_ring').classList.remove("hidden");
if (browse_forms_button != undefined) {
browse_forms_button.addEventListener('click', function () {
hideButtonsAndSpin();
});
}
function hideButtonsAndSpin() {
new_link_button.classList.add("hidden");
// hide the access forms button if it exists
if (browse_forms_button != undefined) {
browse_forms_button.classList.add("hidden");
}
get('loading_ring').classList.remove("hidden");
}
function get(elemId) {
return document.getElementById(elemId);
}

View File

@ -31,7 +31,7 @@
<a class="ncstyle-button margin-bottom">{{ "index_nojs"|tr(lang) }}</a>
</noscript>
{% if sncf_admin_token.is_some() %}
<a href="/admin/{{ sncf_admin_token.as_ref().unwrap() }}" class="ncstyle-button margin-bottom">{{ "index_continueform_button"|tr(lang) }}</a>
<a id="browse_forms_button" href="/admin/{{ sncf_admin_token.as_ref().unwrap() }}" class="ncstyle-button margin-bottom">{{ "index_continueform_button"|tr(lang) }}</a>
{% endif %}
<form id="new_link" action="/link" method="post">
<input id="csrf_token" name="csrf_token" type="text" class="hidden">