diff --git a/templates/assets/index.js b/templates/assets/index.js index 7aed787..a91953e 100644 --- a/templates/assets/index.js +++ b/templates/assets/index.js @@ -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); } diff --git a/templates/index.html b/templates/index.html index 154189a..a64dfcf 100644 --- a/templates/index.html +++ b/templates/index.html @@ -31,7 +31,7 @@ {{ "index_nojs"|tr(lang) }} {% if sncf_admin_token.is_some() %} - {{ "index_continueform_button"|tr(lang) }} + {{ "index_continueform_button"|tr(lang) }} {% endif %}