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

@ -19,6 +19,7 @@ Bug fixes
| `Bug #3582 <https://redmine.postgresql.org/issues/3582>`_ - Ensure that JSON strings as comments should be added properly for all the objects.
| `Bug #3605 <https://redmine.postgresql.org/issues/3605>`_ - Fix an issue where Deleting N number of rows makes first N number of rows disable.
| `Bug #3938 <https://redmine.postgresql.org/issues/3938>`_ - Added support for Default Partition.
| `Bug #4101 <https://redmine.postgresql.org/issues/4101>`_ - Ensure that confirmation dialog should be popped up before reload of query tool or debugger if it is opened in a new browser tab.
| `Bug #4104 <https://redmine.postgresql.org/issues/4104>`_ - Ensure that record should be add/edited for root partition table with primary keys.
| `Bug #4121 <https://redmine.postgresql.org/issues/4121>`_ - Fixed alignment issue of columns in definition section of Index node.
| `Bug #4134 <https://redmine.postgresql.org/issues/4134>`_ - Fixed 'Location cannot be empty' error when open Tablespace properties.

View File

@ -1945,12 +1945,17 @@ define('pgadmin.browser', [
}
$(window).on('beforeunload', function(e) {
/* Can open you in new tab */
let openerBrowser = window.opener ?
window.opener.pgAdmin.Browser : window.top.pgAdmin.Browser;
let tree_save_interval = pgBrowser.get_preference('browser', 'browser_tree_state_save_interval'),
confirm_on_refresh_close = pgBrowser.get_preference('browser', 'confirm_on_refresh_close');
confirm_on_refresh_close = openerBrowser.get_preference('browser', 'confirm_on_refresh_close');
if (!_.isUndefined(tree_save_interval) && tree_save_interval.value !== -1)
pgAdmin.Browser.browserTreeState.save_state();
if(confirm_on_refresh_close.value) {
if(!_.isUndefined(confirm_on_refresh_close) && confirm_on_refresh_close.value) {
/* This message will not be displayed in Chrome, Firefox, Safari as they have disabled it*/
let msg = S(gettext('Are you sure you want to close the %s browser?')).sprintf(pgBrowser.utils.app_name).value();
e.originalEvent.returnValue = msg;

View File

@ -411,7 +411,7 @@ def initialize_query_tool(sgid, sid, did=None):
)
@blueprint.route('/close/<int:trans_id>', methods=["GET"], endpoint='close')
@blueprint.route('/close/<int:trans_id>', methods=["DELETE"], endpoint='close')
def close(trans_id):
"""
This method is used to close the asynchronous connection

View File

@ -505,7 +505,7 @@ define('pgadmin.datagrid', [
queryToolPanel.on(wcDocker.EVENT.CLOSED, function() {
$.ajax({
url: url_for('datagrid.close', {'trans_id': trans_obj.gridTransId}),
method: 'GET',
method: 'DELETE',
});
});

View File

@ -368,12 +368,24 @@
msgDiv = loadingDiv.find('.sql-editor-busy-text');
// Register unload event on window close.
window.onbeforeunload = function(ev) {
$.ajax({
url: "{{ url_for('datagrid.index') }}" + "close/" + {{ uniqueId }},
method: 'GET'
/* 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('datagrid.index') }}" + "close/" + {{ uniqueId }}
});
});
};
} else {
$(window).on('beforeunload', function(ev) {
$.ajax({
method: 'DELETE',
url: "{{ url_for('datagrid.index') }}" + "close/" + {{ uniqueId }}
});
});
}
// Get the controller object from pgAdmin.SqlEditor
var sqlEditorController = pgAdmin.SqlEditor.create(editorPanel);

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);