Ensure that confirmation dialog should be popped up before reload of query tool or debugger

if it is opened in a new browser tab. Fixes #4101
This commit is contained in:
Aditya Toshniwal
2019-04-18 15:39:36 +05:30
committed by Akshay Joshi
parent 4ac064de42
commit 49b318c39e
7 changed files with 52 additions and 20 deletions

View File

@@ -196,14 +196,14 @@ define([
let self = this;
let cacheIntervalId = setInterval(function() {
try {
self.preferences = window.top.pgAdmin.Browser;
if(pgBrowser.preference_version() > 0) {
self.preferences = pgBrowser.get_preferences_for_module('debugger');
clearInterval(cacheIntervalId);
}
catch(err) {
clearInterval(cacheIntervalId);
throw err;
}
},0);
pgBrowser.onPreferencesChange('debugger', function() {
self.preferences = pgBrowser.get_preferences_for_module('debugger');
});
},
// It will check weather the function is actually debuggable or not with pre-required condition.

View File

@@ -10,12 +10,26 @@ try {
var $ = pgDirectDebug.jquery;
pgDirectDebug.load({{ uniqueId }}, {{ debug_type }}, '{{ function_name_with_arguments }}', '{{layout|safe}}');
window.onbeforeunload = function(ev) {
$.ajax({
url: "{{ url_for('debugger.index') }}close/{{ uniqueId }}",
method: 'DELETE'
// Register unload event on window close.
/* If opened in new tab, close the connection only on tab/window close and
* not on refresh attempt because the user may cancel the reload
*/
if(window.opener) {
$(window).on('unload', function(ev) {
$.ajax({
method: 'DELETE',
url: "{{ url_for('debugger.index') }}close/{{ uniqueId }}"
});
});
};
} else {
$(window).on('beforeunload', function(ev) {
$.ajax({
method: 'DELETE',
url: "{{ url_for('debugger.index') }}close/{{ uniqueId }}"
});
});
}
},
function() {
console.log(arguments);