mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Ensure the query tool editor has focus when the tab is selected or when first shown so the user can immediately type/execute. Fixes #1581
This commit is contained in:
committed by
Dave Page
parent
35d3c396de
commit
f13de8b86b
@@ -268,34 +268,47 @@ define(
|
||||
|
||||
self.render_history_grid();
|
||||
|
||||
// Listen on the panel closed event and notify user to save modifications.
|
||||
_.each(window.top.pgAdmin.Browser.docker.findPanels('frm_datagrid'), function(p) {
|
||||
if(p.isVisible()) {
|
||||
p.on(wcDocker.EVENT.CLOSING, function() {
|
||||
// Only if we can edit data then perform this check
|
||||
var notify = false, msg;
|
||||
if(self.handler.can_edit) {
|
||||
var data_store = self.handler.data_store;
|
||||
if(_.size(data_store.added) ||
|
||||
_.size(data_store.updated)) {
|
||||
msg = '{{ _('The data has been modified, but not saved. Are you sure you wish to discard the changes?') }}';
|
||||
notify = true;
|
||||
}
|
||||
} else if(self.handler.is_query_tool) {
|
||||
// We will check for modified sql content
|
||||
var sql = self.handler.gridView.query_tool_obj.getValue();
|
||||
sql = sql.replace(/\s+/g, '');
|
||||
// If it is an empty query, do nothing.
|
||||
if (sql.length > 0) {
|
||||
msg = '{{ _('The query has been modified, but not saved. Are you sure you wish to discard the changes?') }}';
|
||||
notify = true;
|
||||
}
|
||||
}
|
||||
if(notify) {return self.user_confirmation(p, msg);}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
});
|
||||
// Listen on the panel closed event and notify user to save modifications.
|
||||
_.each(window.top.pgAdmin.Browser.docker.findPanels('frm_datagrid'), function(p) {
|
||||
if(p.isVisible()) {
|
||||
p.on(wcDocker.EVENT.CLOSING, function() {
|
||||
// Only if we can edit data then perform this check
|
||||
var notify = false, msg;
|
||||
if(self.handler.can_edit) {
|
||||
var data_store = self.handler.data_store;
|
||||
if(_.size(data_store.added) ||
|
||||
_.size(data_store.updated)) {
|
||||
msg = '{{ _('The data has been modified, but not saved. Are you sure you wish to discard the changes?') }}';
|
||||
notify = true;
|
||||
}
|
||||
} else if(self.handler.is_query_tool) {
|
||||
// We will check for modified sql content
|
||||
var sql = self.handler.gridView.query_tool_obj.getValue();
|
||||
sql = sql.replace(/\s+/g, '');
|
||||
// If it is an empty query, do nothing.
|
||||
if (sql.length > 0) {
|
||||
msg = '{{ _('The query has been modified, but not saved. Are you sure you wish to discard the changes?') }}';
|
||||
notify = true;
|
||||
}
|
||||
}
|
||||
if(notify) {return self.user_confirmation(p, msg);}
|
||||
return true;
|
||||
});
|
||||
// Set focus on query tool of active panel
|
||||
p.on(wcDocker.EVENT.GAIN_FOCUS, function() {
|
||||
if (!$(p.$container).hasClass('wcPanelTabContentHidden')) {
|
||||
setTimeout(function() {
|
||||
self.handler.gridView.query_tool_obj.focus();
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// set focus on query tool once loaded
|
||||
setTimeout(function() {
|
||||
self.query_tool_obj.focus();
|
||||
}, 500);
|
||||
|
||||
/* We have override/register the hint function of CodeMirror
|
||||
* to provide our own hint logic.
|
||||
@@ -401,8 +414,8 @@ define(
|
||||
|
||||
/* To prompt user for unsaved changes */
|
||||
user_confirmation: function(panel, msg) {
|
||||
// If there is anything to save then prompt user
|
||||
alertify.confirm('{{ _('Unsaved changes') }}', msg,
|
||||
// If there is anything to save then prompt user
|
||||
alertify.confirm('{{ _('Unsaved changes') }}', msg,
|
||||
function() {
|
||||
// Do nothing as user do not want to save, just continue
|
||||
window.onbeforeunload = null;
|
||||
|
||||
Reference in New Issue
Block a user