From 5715e42561be6cdc922820d6dfaeaefa8d63c17c Mon Sep 17 00:00:00 2001 From: Catalin Date: Mon, 12 Feb 2024 16:17:02 +0200 Subject: [PATCH] HDX-9420 display alert if user tries to go back to page b --- .../fanstatic/onboarding/prevent-back-button.js | 12 ++++++++++++ .../ckanext/hdx_theme/fanstatic/webassets.yml | 6 ++++++ .../templates/onboarding/signup/verify-email.html | 5 +++++ 3 files changed, 23 insertions(+) create mode 100644 ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/onboarding/prevent-back-button.js diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/onboarding/prevent-back-button.js b/ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/onboarding/prevent-back-button.js new file mode 100644 index 0000000000..52715b739d --- /dev/null +++ b/ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/onboarding/prevent-back-button.js @@ -0,0 +1,12 @@ +window.history.pushState({page: 2}, null, null); + +window.onpopstate = function (event) { + if (event) { + var r = confirm('Hold on! Your data has already been saved. Are you sure you want to go back to the previous page and reload the signup process?'); + if (r === true) { + history.back(); + } else { + window.history.pushState({page: 2}, '', ''); + } + } +} diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/webassets.yml b/ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/webassets.yml index b7abd7184d..b817dbda72 100644 --- a/ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/webassets.yml +++ b/ckanext-hdx_theme/ckanext/hdx_theme/fanstatic/webassets.yml @@ -126,6 +126,12 @@ hdx-onboarding-scripts: - onboarding/came-from-input.js - onboarding/confirm-page-leave.js +prevent-back-button: + <<: *common-js + output: ckanext-hdx_theme/%(version)s_prevent-back-button.js + contents: + - onboarding/prevent-back-button.js + search-scripts: <<: *common-js output: ckanext-hdx_theme/%(version)s_search-scripts.js diff --git a/ckanext-hdx_theme/ckanext/hdx_theme/templates/onboarding/signup/verify-email.html b/ckanext-hdx_theme/ckanext/hdx_theme/templates/onboarding/signup/verify-email.html index 9bfff85ed2..26be460931 100644 --- a/ckanext-hdx_theme/ckanext/hdx_theme/templates/onboarding/signup/verify-email.html +++ b/ckanext-hdx_theme/ckanext/hdx_theme/templates/onboarding/signup/verify-email.html @@ -1,5 +1,10 @@ {% extends "onboarding/base.html" %} +{% block scripts %} + {{ super() }} + {% asset 'hdx_theme/prevent-back-button' %} +{% endblock %} + {% set CONST = h.HDX_CONST('UI_CONSTANTS')['ONBOARDING']['VERIFY_EMAIL'] %} {% block subtitle %}{{ _('User info') }}{% endblock %}