Make the "Save Changes" prompts in the query tool optional. Fixes #2845

pull/6/head
Harshal Dhumal 2017-11-23 09:20:59 +00:00 committed by Dave Page
parent 38f111d969
commit 05a00f4ac8
4 changed files with 52 additions and 20 deletions

View File

@ -216,6 +216,11 @@ def panel(trans_id, is_query_tool, editor_title):
else:
new_browser_tab = 'false'
if is_query_tool == 'true':
prompt_save_changes = pref.preference('prompt_save_query_changes').get()
else:
prompt_save_changes = pref.preference('prompt_save_data_changes').get()
# Fetch the server details
#
bgcolor = None
@ -243,7 +248,10 @@ def panel(trans_id, is_query_tool, editor_title):
server_type=server_type,
client_platform=user_agent.platform,
bgcolor=bgcolor,
fgcolor=fgcolor
fgcolor=fgcolor,
# convert python boolean value to equivalent js boolean literal before
# passing it to html template.
prompt_save_changes='true' if prompt_save_changes else 'false'
)

View File

@ -369,6 +369,6 @@
// Start the query tool.
sqlEditorController.start({{ is_query_tool }}, "{{ editor_title }}",
script_sql, {{ is_new_browser_tab }}, "{{ server_type }}");
script_sql, {{ is_new_browser_tab }}, "{{ server_type }}", {{ prompt_save_changes }});
});
{% endblock %}

View File

@ -235,6 +235,26 @@ class SqlEditorModule(PgAdminModule):
)
)
self.show_prompt_save_query_changes = self.preference.register(
'Options', 'prompt_save_query_changes',
gettext("Prompt to save unsaved query changes?"), 'boolean', True,
category_label=gettext('Options'),
help_str=gettext(
'Specifies whether or not to prompt user to save unsaved '
'query on query tool exit.'
)
)
self.show_prompt_save_data_changes = self.preference.register(
'Options', 'prompt_save_data_changes',
gettext("Prompt to save unsaved data changes?"), 'boolean', True,
category_label=gettext('Options'),
help_str=gettext(
'Specifies whether or not to prompt user to save unsaved '
'data on data grid exit.'
)
)
self.csv_quoting = self.preference.register(
'CSV_output', 'csv_quoting',
gettext("CSV quoting"), 'options', 'strings',

View File

@ -243,25 +243,28 @@ define('tools.querytool', [
// 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 (data_store && (_.size(data_store.added) ||
_.size(data_store.updated))) {
msg = gettext("The data has changed. Do you want to save changes?");
if(self.handler.prompt_save_changes) {
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 (data_store && (_.size(data_store.added) ||
_.size(data_store.updated))) {
msg = gettext("The data has changed. Do you want to save changes?");
notify = true;
}
} else if (self.handler.is_query_tool && self.handler.is_query_changed) {
msg = gettext("The text has changed. Do you want to save changes?");
notify = true;
}
} else if (self.handler.is_query_tool && self.handler.is_query_changed) {
msg = gettext("The text has changed. Do you want to save changes?");
notify = true;
}
if (notify) {
return self.user_confirmation(p, msg);
}
return 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')) {
@ -1578,7 +1581,7 @@ define('tools.querytool', [
* call the render method of the grid view to render the backgrid
* header and loading icon and start execution of the sql query.
*/
start: function (is_query_tool, editor_title, script_sql, is_new_browser_tab, server_type) {
start: function (is_query_tool, editor_title, script_sql, is_new_browser_tab, server_type, prompt_save_changes) {
var self = this;
self.is_query_tool = is_query_tool;
@ -1593,6 +1596,7 @@ define('tools.querytool', [
self.fetching_rows = false;
self.close_on_save = false;
self.server_type = server_type;
self.prompt_save_changes = prompt_save_changes;
// We do not allow to call the start multiple times.
if (self.gridView)