From cd360d7279f3b792f9755578a632045e529968ad Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Tue, 25 Oct 2016 18:12:29 +0200 Subject: [PATCH 1/2] Fix the save report alert() bug Closes SCI-616 --- app/assets/javascripts/reports/new.js.erb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/reports/new.js.erb b/app/assets/javascripts/reports/new.js.erb index 48ebd470f..fdaf4e9e3 100644 --- a/app/assets/javascripts/reports/new.js.erb +++ b/app/assets/javascripts/reports/new.js.erb @@ -317,7 +317,12 @@ function initializeSaveReport() { .on("ajax:success", function(e, xhr, opts, data) { if (data.status == 200) { // Redirect back to index + + // Turn off all hooks related to alert window ignoreUnsavedWorkAlert = true; + $(window).off('beforeunload'); + $(document).off('page:before-change'); + $(location).attr("href", xhr.url); } }) @@ -439,9 +444,6 @@ function initializeUnsavedWorkDialog() { var alertText = dh.attr('data-unsaved-work-text'); ignoreUnsavedWorkAlert = false; - if ( ignoreUnsavedWorkAlert ) { - return; - } $(window).on("beforeunload", function() { $(window).off('beforeunload'); @@ -451,7 +453,13 @@ function initializeUnsavedWorkDialog() { $(document).on("page:before-change", function() { var exit; - exit = confirm(alertText); + if (ignoreUnsavedWorkAlert) { + console.log('TRUE'); + exit = true; + } else { + console.log('FALSE'); + exit = confirm(alertText); + } if ( exit ) { // We leave the page so remove all listeners $(window).off('beforeunload'); From b4685b0a40d557f60ab3f6ac995b69fba177dbb2 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Tue, 25 Oct 2016 18:13:29 +0200 Subject: [PATCH 2/2] Remove console.log() --- app/assets/javascripts/reports/new.js.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/assets/javascripts/reports/new.js.erb b/app/assets/javascripts/reports/new.js.erb index fdaf4e9e3..feb28df16 100644 --- a/app/assets/javascripts/reports/new.js.erb +++ b/app/assets/javascripts/reports/new.js.erb @@ -454,10 +454,8 @@ function initializeUnsavedWorkDialog() { $(document).on("page:before-change", function() { var exit; if (ignoreUnsavedWorkAlert) { - console.log('TRUE'); exit = true; } else { - console.log('FALSE'); exit = confirm(alertText); } if ( exit ) {