Hi, Please find attached patch to fix RM2845
-- *Harshal Dhumal* *Sr. Software Engineer* EnterpriseDB India: http://www.enterprisedb.com The Enterprise PostgreSQL Company
diff --git a/web/pgadmin/tools/datagrid/__init__.py b/web/pgadmin/tools/datagrid/__init__.py index c37e5d3..eaa1850 100644 --- a/web/pgadmin/tools/datagrid/__init__.py +++ b/web/pgadmin/tools/datagrid/__init__.py @@ -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' ) diff --git a/web/pgadmin/tools/datagrid/templates/datagrid/index.html b/web/pgadmin/tools/datagrid/templates/datagrid/index.html index 05e0986..ff4368d 100644 --- a/web/pgadmin/tools/datagrid/templates/datagrid/index.html +++ b/web/pgadmin/tools/datagrid/templates/datagrid/index.html @@ -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 %} diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index d360d91..a4b83d4 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -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', diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index ba0ce67..68f953a 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -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')) { @@ -1550,7 +1553,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; @@ -1565,6 +1568,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)