diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js index 30a7932..3e0e938 100644 --- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js @@ -305,7 +305,7 @@ define( 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) { + } else if(self.handler.is_query_tool && self.handler.is_query_changed) { // We will check for modified sql content var sql = self.handler.gridView.query_tool_obj.getValue(); sql = sql.replace(/\s+/g, ''); @@ -1334,17 +1334,24 @@ define( // If there is nothing to save, clear it. if (!sql.length) { self.query_tool_obj.setValue(''); return; } - alertify.confirm( - '{{ _('Unsaved changes') }}', - '{{ _('Are you sure you wish to discard the current changes?') }}', - function() { - // Do nothing as user do not want to save, just continue - self.query_tool_obj.setValue(''); - }, - function() { - return true; - } - ).set('labels', {ok:'Yes', cancel:'No'}); + /* If is_query_changed flag is set to false then no need to + * confirm with the user for unsaved changes. + */ + if (self.handler.is_query_changed) { + alertify.confirm( + '{{ _('Unsaved changes') }}', + '{{ _('Are you sure you wish to discard the current changes?') }}', + function() { + // Do nothing as user do not want to save, just continue + self.query_tool_obj.setValue(''); + }, + function() { + return true; + } + ).set('labels', {ok:'Yes', cancel:'No'}); + } else { + self.query_tool_obj.setValue(''); + } }, // Callback function for the clear history button click. @@ -2244,7 +2251,6 @@ define( // Open save file dialog if query tool if (self.is_query_tool) { - var current_file = self.gridView.current_file; if (!_.isUndefined(current_file) && !save_as) { self._save_file_handler(current_file); @@ -2432,16 +2438,24 @@ define( // If there is nothing to save, open file manager. if (!sql.length) { self._open_select_file_manager(); return; } - alertify.confirm('{{ _('Unsaved changes') }}', - '{{ _('Are you sure you wish to discard the current changes?') }}', - function() { - // User do not want to save, just continue - self._open_select_file_manager(); - }, - function() { - return true; - } - ).set('labels', {ok:'Yes', cancel:'No'}); + /* If is_query_changed flag is set to false then no need to + * confirm with the user for unsaved changes. + */ + if (self.is_query_changed) { + alertify.confirm('{{ _('Unsaved changes') }}', + '{{ _('Are you sure you wish to discard the current changes?') }}', + function() { + // User do not want to save, just continue + self._open_select_file_manager(); + }, + function() { + return true; + } + ).set('labels', {ok:'Yes', cancel:'No'}); + } else { + self._open_select_file_manager(); + } + }, // Open FileManager @@ -2484,6 +2498,13 @@ define( self.trigger('pgadmin-sqleditor:loading-icon:hide'); // hide cursor $busy_icon_div.removeClass('show_progress'); + + // disable save button on file save + $("#btn-save").prop('disabled', true); + $("#btn-file-menu-save").css('display', 'none'); + + // Update the flag as new content is just loaded. + self.is_query_changed = false; }, error: function(e) { var errmsg = $.parseJSON(e.responseText).errormsg; @@ -2521,6 +2542,9 @@ define( // disable save button on file save $("#btn-save").prop('disabled', true); $("#btn-file-menu-save").css('display', 'none'); + + // Update the flag as query is already saved. + self.is_query_changed = false; } self.trigger('pgadmin-sqleditor:loading-icon:hide'); }, @@ -2540,6 +2564,10 @@ define( // codemirror text change event _on_query_change: function(query_tool_obj) { var self = this; + + // Update the flag as query is changed. + self.is_query_changed = true; + if(query_tool_obj.getValue().length == 0) { $("#btn-save").prop('disabled', true); $("#btn-file-menu-save").css('display', 'none');