From 2b7e3ce64e10d5dff331270937f76501107f3c12 Mon Sep 17 00:00:00 2001 From: Nikhil Mohite Date: Mon, 12 Oct 2020 17:14:42 +0530 Subject: [PATCH] =?UTF-8?q?Fixed=20an=20issue=20on=20a=20new=20connection?= =?UTF-8?q?=20when=20the=20server=20is=20disconnected=20and=20we=20are=20t?= =?UTF-8?q?rying=20to=20connect=C2=A0it=20using=20the=20new=20connection?= =?UTF-8?q?=20model.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sqleditor/new_connection_dialog_model.js | 148 +++++++++--------- 1 file changed, 77 insertions(+), 71 deletions(-) diff --git a/web/pgadmin/static/js/sqleditor/new_connection_dialog_model.js b/web/pgadmin/static/js/sqleditor/new_connection_dialog_model.js index 9e0305142..09b29796f 100644 --- a/web/pgadmin/static/js/sqleditor/new_connection_dialog_model.js +++ b/web/pgadmin/static/js/sqleditor/new_connection_dialog_model.js @@ -95,79 +95,85 @@ export default function newConnectionDialogModel(response, sgid, sid) { control: Backform.Select2Control.extend({ connect: function(self) { let local_self = self; - if(!alertify.connectServer){ - alertify.dialog('connectServer', function factory() { - return { - main: function( - title, message, server_id, submit_password=true - ) { - this.set('title', title); - this.message = message; - this.server_id = server_id; - this.submit_password = submit_password; - }, - setup:function() { - return { - buttons:[{ - text: gettext('Cancel'), className: 'btn btn-secondary fa fa-times pg-alertify-button', - key: 27, - },{ - text: gettext('OK'), key: 13, className: 'btn btn-primary fa fa-check pg-alertify-button', - }], - focus: {element: '#password', select: true}, - options: { - modal: 0, resizable: false, maximizable: false, pinnable: false, - }, - }; - }, - build:function() { - }, - prepare:function() { - this.setContent(this.message); - }, - callback: function(closeEvent) { - if (closeEvent.button.text == gettext('OK')) { - if(this.submit_password) { - var _url = url_for('sqleditor.connect_server', {'sid': this.server_id}); - var loadingDiv = $('#show_filter_progress'); - loadingDiv.removeClass('d-none'); - $.ajax({ - type: 'POST', - timeout: 30000, - url: _url, - data: $('#frmPassword').serialize(), - }) - .done(function() { - local_self.model.attributes.database = null; - local_self.model.attributes.user = null; - local_self.model.attributes.role = null; - Backform.Select2Control.prototype.onChange.apply(local_self, arguments); - response.server_list.forEach(function(obj){ - if(obj.id==self.model.changed.server) { - response.server_name = obj.name; - } - }); - loadingDiv.addClass('d-none'); - }) - .fail(function(xhr) { - loadingDiv.addClass('d-none'); - alertify.connectServer('Connect to server', xhr.responseJSON.result, local_self.getValueFromDOM()); - }); - } else { - response.password = $('#password').val(); - } - } else { - local_self.model.attributes.database = null; - local_self.model.attributes.user = null; - local_self.model.attributes.role = null; - Backform.Select2Control.prototype.onChange.apply(local_self, arguments); - } - closeEvent.close = true; - }, - }; - }); + if(alertify.connectServer) { + delete alertify.connectServer; } + + alertify.dialog('connectServer', function factory() { + return { + main: function( + title, message, server_id, submit_password=true + ) { + this.set('title', title); + this.message = message; + this.server_id = server_id; + this.submit_password = submit_password; + }, + setup:function() { + return { + buttons:[{ + text: gettext('Cancel'), className: 'btn btn-secondary fa fa-times pg-alertify-button', + key: 27, + },{ + text: gettext('OK'), key: 13, className: 'btn btn-primary fa fa-check pg-alertify-button', + }], + focus: {element: '#password', select: true}, + options: { + modal: 0, resizable: false, maximizable: false, pinnable: false, + }, + }; + }, + build:function() { + }, + prepare:function() { + this.setContent(this.message); + }, + callback: function(closeEvent) { + + if (closeEvent.button.text == gettext('OK')) { + if(this.submit_password) { + var _url = url_for('sqleditor.connect_server', {'sid': this.server_id}); + var loadingDiv = $('#show_filter_progress'); + loadingDiv.removeClass('d-none'); + $.ajax({ + type: 'POST', + timeout: 30000, + url: _url, + data: $('#frmPassword').serialize(), + }) + .done(function() { + local_self.model.attributes.database = null; + local_self.model.attributes.user = null; + local_self.model.attributes.role = null; + Backform.Select2Control.prototype.onChange.apply(local_self, arguments); + response.server_list.forEach(function(obj){ + if(obj.id==self.model.changed.server) { + response.server_name = obj.name; + } + }); + loadingDiv.addClass('d-none'); + alertify.connectServer().destroy(); + }) + .fail(function(xhr) { + loadingDiv.addClass('d-none'); + alertify.connectServer().destroy(); + alertify.connectServer('Connect to server', xhr.responseJSON.result, local_self.getValueFromDOM()); + }); + } else { + response.password = $('#password').val(); + } + } else { + local_self.model.attributes.database = null; + local_self.model.attributes.user = null; + local_self.model.attributes.role = null; + Backform.Select2Control.prototype.onChange.apply(local_self, arguments); + alertify.connectServer().destroy(); + } + closeEvent.close = true; + }, + }; + }); }, render: function() { let self = this;