From 79910d31411a92568478d9a52be266cb5662826d Mon Sep 17 00:00:00 2001 From: Gregor Lasnibat Date: Mon, 26 Feb 2024 08:31:31 +0100 Subject: [PATCH] (fix) Add warning for unsaved changes when leaving Task workflow edit mode (Canvas view) [SCI-10004] --- app/assets/javascripts/projects/canvas.js.erb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/assets/javascripts/projects/canvas.js.erb b/app/assets/javascripts/projects/canvas.js.erb index b18f66542..b001627b5 100644 --- a/app/assets/javascripts/projects/canvas.js.erb +++ b/app/assets/javascripts/projects/canvas.js.erb @@ -545,6 +545,35 @@ function bindTouchDropdowns(selector) { }); } +function handleAnchorClick(event) { + event.preventDefault(); + + // check if the clicked element is an anchor tag with an href + if (event.target.tagName === 'A' && event.target.href) { + const targetUrl = event.target.href; + + const alertText = $("#update-canvas").attr("data-unsaved-work-text"); + const exit = confirm(alertText); + + if (exit) { + // remove unload listeners and navigate to location + $(window).off("beforeunload"); + $(document).off("page:before-change"); + + window.location.href = targetUrl; + } + } +}; + +// listen to clicks on links in navigator and leftMenuContainer +$(document).ready(function() { + const navigatorEl = $('.sci--layout-navigation-navigator'); + const leftMenuContainerEl = $('.sci--layout--left-menu-container'); + + navigatorEl.on('click', 'a', handleAnchorClick); + leftMenuContainerEl.on('click', 'a', handleAnchorClick); +}); + function bindEditModeCloseWindow() { var alertText = $("#update-canvas").attr("data-unsaved-work-text");