diff --git a/web/pgadmin/browser/server_groups/servers/databases/templates/databases/js/databases.js b/web/pgadmin/browser/server_groups/servers/databases/templates/databases/js/databases.js index f9e75a2..b378a2b 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/templates/databases/js/databases.js +++ b/web/pgadmin/browser/server_groups/servers/databases/templates/databases/js/databases.js @@ -69,6 +69,11 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) { category: 'drop', priority: 5, label: '{{ _('Disconnect Database...') }}', icon: 'fa fa-chain-broken', enable : 'is_connected' }]); + + _.bindAll(this, 'connection_lost'); + pgBrowser.Events.on( + 'pgadmin:database:connection:lost', this.connection_lost + ); }, can_create_database: function(node, item) { var treeData = this.getTreeNodeHierarchy(item), @@ -82,6 +87,64 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) { is_connected: function(node) { return (node && node.connected == true && node.canDisconn == true); }, + connection_lost: function(i, resp) { + if (pgBrowser.tree) { + var t = pgBrowser.tree, + info = i && this.getTreeNodeHierarchy(i), + s = null, + d = i && t.itemData(i), + self = this, + _i = i; + + while (d && d._type != 'database') { + i = t.parent(i); + d = i && t.itemData(i); + } + + if (i && d) { + if (_.isUndefined(d.is_connecting) || !d.is_connecting) { + d.is_connecting = true; + + var disconnect = function(_i, _d) { + if (_d._id == d._id) { + d.is_connecting = false; + pgBrowser.Events.off( + 'pgadmin:database:connect:cancelled', disconnect + ); + _i = _i && t.parent(_i); + _d = _i && t.itemData(_i); + if (_i && _d) { + pgBrowser.Events.trigger( + 'pgadmin:server:disconnect', + {item: _i, data: _d}, false + ); + } + } + }; + + pgBrowser.Events.on( + 'pgadmin:database:connect:cancelled', disconnect + ); + Alertify.confirm( + '{{ _('Connection lost') }}', + '{{ _('Would you like to reconnect to the database?') }}', + function() { + connect(self, d, t, i); + }, + function() { + d.is_connecting = false; + t.unload(i); + t.setInode(i); + t.addIcon(i, {icon: 'icon-database-not-connected'}); + pgBrowser.Events.trigger( + 'pgadmin:database:connect:cancelled', i, d, self + ); + t.select(i); + }); + } + } + } + }, callbacks: { /* Connect the database */ connect_database: function(args){ @@ -356,58 +419,84 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) { return null; } }) - }); - function connect_to_database(obj, data, tree, item, interactive) { - connect(obj, data, tree, item) - }; - function connect(obj, data, tree, item) { - var onFailure = function(xhr, status, error, _model, _data, _tree, _item) { - - tree.setInode(_item); - tree.addIcon(_item, {icon: 'icon-database-not-connected'}); - - Alertify.pgNotifier('error', xhr, error, function(msg) { - setTimeout(function() { - Alertify.dlgServerPass( - '{{ _('Connect to database') }}', - msg, _model, _data, _tree, _item - ).resizeTo(); - }, 100); - }); - }, - onSuccess = function(res, model, data, tree, item) { - tree.deselect(item); - tree.setInode(item); - - if (res && res.data) { - if(typeof res.data.connected == 'boolean') { - data.connected = res.data.connected; - } - if (typeof res.data.icon == 'string') { - tree.removeIcon(item); - data.icon = res.data.icon; - tree.addIcon(item, {icon: data.icon}); - } + }); - Alertify.success(res.info); - setTimeout(function() {tree.select(item);}, 10); - setTimeout(function() {tree.open(item);}, 100); - } - }, - url = obj.generate_url(item, "connect", data, true); - $.post(url) - .done( - function(res) { - if (res.success == 1) { - return onSuccess(res, obj, data, tree, item); + function connect_to_database(obj, data, tree, item, interactive) { + connect(obj, data, tree, item) + } + + function connect(obj, data, tree, item) { + var wasConnected = data.connected, + onFailure = function( + xhr, status, error, _model, _data, _tree, _item, _status + ) { + if (!_status) { + tree.setInode(_item); + tree.addIcon(_item, {icon: 'icon-database-not-connected'}); + } + + Alertify.pgNotifier('error', xhr, error, function(msg) { + setTimeout(function() { + Alertify.dlgServerPass( + '{{ _('Connect to database') }}', + msg, _model, _data, _tree, _item, _status, + onSuccess, onFailure, onCancel + ).resizeTo(); + }, 100); + }); + }, + onSuccess = function( + res, model, data, tree, item, connected + ) { + data.is_connecting = false; + if (!connected) { + tree.deselect(item); + tree.setInode(item); } - }) - .fail( - function(xhr, status, error) { - return onFailure(xhr, status, error, obj, data, tree, item); - }); - } + if (res && res.data) { + if(typeof res.data.connected == 'boolean') { + data.connected = res.data.connected; + } + if (typeof res.data.icon == 'string') { + tree.removeIcon(item); + data.icon = res.data.icon; + tree.addIcon(item, {icon: data.icon}); + } + + Alertify.success(res.info); + obj.trigger('connected', obj, item, data); + pgBrowser.Events.trigger('pgadmin:database:connected', item, data); + + if (!connected) { + setTimeout(function() { + tree.select(item); tree.open(item); + }, 10); + } + } + }, + onCancel = function(_tree, _item, _data, _status) { + _data.is_connecting = false; + var server = _tree.parent(_item); + _tree.unload(_item); + _tree.setInode(_item); + _tree.removeIcon(_item); + _tree.addIcon(_item, {icon: 'icon-database-not-connected'}); + obj.trigger('connect:cancelled', obj, _item, _data); + pgBrowser.Events.trigger('pgadmin:database:connect:cancelled', _item, _data, obj); + _tree.select(server); + }; + + $.post( + obj.generate_url(item, "connect", data, true) + ).done(function(res) { + if (res.success == 1) { + return onSuccess(res, obj, data, tree, item); + } + }).fail(function(xhr, status, error) { + return onFailure(xhr, status, error, obj, data, tree, item); + }); + } } return pgBrowser.Nodes['coll-database']; diff --git a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js index ca0c269..0ce387c 100644 --- a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js +++ b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js @@ -102,6 +102,18 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { '{{ _('A grantee must be selected.') }}'; pgBrowser.messages['NO_PRIV_SELECTED'] = '{{ _('At least one privilege should be selected.') }}'; + + pgBrowser.Events.on( + 'pgadmin:server:disconnect', this.callbacks.disconnect_server + ); + pgBrowser.Events.on( + 'pgadmin:server:connect', this.callbacks.connect_server + ); + + _.bindAll(this, 'connection_lost'); + pgBrowser.Events.on( + 'pgadmin:server:connection:lost', this.connection_lost + ); }, is_not_connected: function(node) { return (node && node.connected != true); @@ -162,7 +174,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { return false; }, /* Disconnect the server */ - disconnect_server: function(args) { + disconnect_server: function(args, notify) { var input = args || {}, obj = this, t = pgBrowser.tree, @@ -172,48 +184,60 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { if (!d) return false; - alertify.confirm( - '{{ _('Disconnect server') }}', - S('{{ _('Are you sure you want to disconnect the server %s?') }}').sprintf(d.label).value(), - function(evt) { - $.ajax({ - url: obj.generate_url(i, 'connect', d, true), - type:'DELETE', - success: function(res) { - if (res.success == 1) { - alertify.success(res.info); - d = t.itemData(i); - t.removeIcon(i); - d.connected = false; - d.icon = 'icon-server-not-connected'; - t.addIcon(i, {icon: d.icon}); - obj.callbacks.refresh.apply(obj, [null, i]); - if (pgBrowser.serverInfo && d._id in pgBrowser.serverInfo) { - delete pgBrowser.serverInfo[d._id] - } - obj.trigger('server-disconnected', obj, i, d); - } - else { - try { - alertify.error(res.errormsg); - } catch (e) {} - t.unload(i); + notify = notify || _.isUndefined(notify) || _.isNull(notify); + + var disconnect = function() { + $.ajax({ + url: obj.generate_url(i, 'connect', d, true), + type:'DELETE', + success: function(res) { + if (res.success == 1) { + alertify.success(res.info); + d = t.itemData(i); + t.removeIcon(i); + d.connected = false; + d.icon = 'icon-server-not-connected'; + t.addIcon(i, {icon: d.icon}); + obj.callbacks.refresh.apply(obj, [null, i]); + if (pgBrowser.serverInfo && d._id in pgBrowser.serverInfo) { + delete pgBrowser.serverInfo[d._id] } - }, - error: function(xhr, status, error) { + obj.trigger('server-disconnected', obj, i, d); + } + else { try { - var err = $.parseJSON(xhr.responseText); - if (err.success == 0) { - alertify.error(err.errormsg); - } + alertify.error(res.errormsg); } catch (e) {} t.unload(i); } + }, + error: function(xhr, status, error) { + try { + var err = $.parseJSON(xhr.responseText); + if (err.success == 0) { + alertify.error(err.errormsg); + } + } catch (e) {} + t.unload(i); + } + }); + }; + + if (notify) { + alertify.confirm( + '{{ _('Disconnect server') }}', + S('{{ _('Are you sure you want to disconnect the server %s?') }}').sprintf( + d.label + ).value(), + function(evt) { + disconnect(); + }, + function(evt) { + return true; }); - }, - function(evt) { - return true; - }); + } else { + disconnect(); + } return false; }, @@ -409,7 +433,6 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { } }, prepare: function() { - //console.log(this.get('server').user.name); var self = this; // Disable Backup button until user provides Filename this.__internal.buttons[0].element.disabled = true; @@ -487,13 +510,14 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { alertify.changeServerPassword(d).resizeTo('40%','52%'); return false; }, + /* Pause WAL Replay */ pause_wal_replay: function(args) { - var input = args || {}; - obj = this, - t = pgBrowser.tree, - i = input.item || t.selected(), - d = i && i.length == 1 ? t.itemData(i) : undefined; + var input = args || {}, + obj = this, + t = pgBrowser.tree, + i = input.item || t.selected(), + d = i && i.length == 1 ? t.itemData(i) : undefined; if (!d) return false; @@ -528,13 +552,14 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { } }) }, + /* Resume WAL Replay */ resume_wal_replay: function(args) { - var input = args || {}; - obj = this, - t = pgBrowser.tree, - i = input.item || t.selected(), - d = i && i.length == 1 ? t.itemData(i) : undefined; + var input = args || {}, + obj = this, + t = pgBrowser.tree, + i = input.item || t.selected(), + d = i && i.length == 1 ? t.itemData(i) : undefined; if (!d) return false; @@ -709,66 +734,133 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { isConnected: function(model) { return model.get('connected'); } - }) - }); - function connect_to_server(obj, data, tree, item) { - var onFailure = function(xhr, status, error, _model, _data, _tree, _item) { - - tree.setInode(_item); - tree.addIcon(_item, {icon: 'icon-server-not-connected'}); - - alertify.pgNotifier('error', xhr, error, function(msg) { - setTimeout(function() { - alertify.dlgServerPass( - '{{ _('Connect to Server') }}', - msg, _model, _data, _tree, _item - ).resizeTo(); - }, 100); - }); - }, - onSuccess = function(res, model, data, tree, item) { - tree.deselect(item); - tree.setInode(item); - - if (res && res.data) { + }), + connection_lost: function(i, resp) { + if (pgBrowser.tree) { + var t = pgBrowser.tree, + info = i && this.getTreeNodeHierarchy(i), + s = null, + d = i && t.itemData(i), + self = this; - if (typeof res.data.icon == 'string') { - tree.removeIcon(item); - data.icon = res.data.icon; - tree.addIcon(item, {icon: data.icon}); + while (d && d._type != 'server') { + i = t.parent(i); + d = i && t.itemData(i); } - // Update 'in_recovery' and 'wal_pause' options at server node - tree.itemData(item).in_recovery=res.data.in_recovery; - tree.itemData(item).wal_pause=res.data.wal_pause; + if (i && d) { + if (_.isUndefined(d.is_connecting) || !d.is_connecting) { + d.is_connecting = true; + + var disconnect = function(_i, _d) { + if (_d._id == d._id) { + d.is_connecting = false; + pgBrowser.Events.off( + 'pgadmin:server:connect:cancelled', disconnect + ); + _i = _i && t.parent(_i); + _d = _i && t.itemData(_i); + if (_i && _d) { + pgBrowser.Events.trigger( + 'pgadmin:server:disconnect', + {item: _i, data: _d}, false + ); + } + } + }; - _.extend(data, res.data); + pgBrowser.Events.on( + 'pgadmin:server:connect:cancelled', disconnect + ); + alertify.confirm( + '{{ _('Connection lost') }}', + '{{ _('Would you like to reconnect to the database?') }}', + function() { + connect_to_server(self, d, t, i); + }, + function() { + d.is_connecting = false; + t.unload(i); + t.setInode(i); + t.addIcon(i, {icon: 'icon-database-not-connected'}); + pgBrowser.Events.trigger( + 'pgadmin:server:connect:cancelled', i, d, self + ); + t.select(i); + }); + } + } + } + } + }); + function connect_to_server(obj, data, tree, item) { + var wasConnected = data.connected, + onFailure = function( + xhr, status, error, _model, _data, _tree, _item, _wasConnected + ) { + data.connected = false; + + // It should be attempt to reconnect. + // Let's not change the status of the tree node now. + if (!_wasConnected) { + tree.setInode(_item); + tree.addIcon(_item, {icon: 'icon-server-not-connected'}); + } - var serverInfo = pgBrowser.serverInfo = pgBrowser.serverInfo || {}; - serverInfo[data._id] = _.extend({}, data); + alertify.pgNotifier('error', xhr, error, function(msg) { + setTimeout(function() { + alertify.dlgServerPass( + '{{ _('Connect to Server') }}', + msg, _model, _data, _tree, _item, _wasConnected + ).resizeTo(); + }, 100); + }); + }, + onSuccess = function(res, model, data, tree, item, _wasConnected) { + if (res && res.data) { + if (typeof res.data.icon == 'string') { + tree.removeIcon(item); + data.icon = res.data.icon; + tree.addIcon(item, {icon: data.icon}); + } - alertify.success(res.info); - obj.trigger('server-connected', obj, item, data); + _.extend(data, res.data); + data.is_connecting = false; - setTimeout(function() { - tree.select(item); - tree.open(item); - }, 10); + var serverInfo = pgBrowser.serverInfo = pgBrowser.serverInfo || {}; + serverInfo[data._id] = _.extend({}, data); - } - }; + alertify.success(res.info); + obj.trigger('connected', obj, item, data); + pgBrowser.Events.trigger('pgadmin:server:connected', item, data); + + tree.setInode(item); + tree.deselect(item); + setTimeout(function() { + tree.select(item); + tree.open(item); + }, 10); + } + }; // Ask Password and send it back to the connect server if (!alertify.dlgServerPass) { alertify.dialog('dlgServerPass', function factory() { return { - main: function(title, message, model, data, tree, item) { + main: function( + title, message, model, data, tree, item, + _status, _onSuccess, _onFailure, _onCancel + ) { this.set('title', title); this.message = message; this.tree = tree; this.nodeData = data; this.nodeItem = item; this.nodeModel = model; + this.connected = _status; + this.onSuccess = _onSuccess || onSuccess; + this.onFailure = _onFailure || onFailure; + this.onCancel = _onCancel || onCancel; }, setup:function() { return { @@ -791,18 +883,24 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { this.setContent(this.message); }, callback: function(closeEvent) { - var _sdata = this.nodeData, - _tree = this.tree, + var _tree = this.tree, _item = this.nodeItem, - _model = this.nodeModel; + _model = this.nodeModel, + _data = this.nodeData, + _status = this.connected, + _onSuccess = this.onSuccess, + _onFailure = this.onFailure, + _onCancel = this.onCancel; if (closeEvent.button.text == "{{ _('OK') }}") { - var _url = _model.generate_url(_item, 'connect', _sdata, true); + var _url = _model.generate_url(_item, 'connect', _data, true); - _tree.setLeaf(_item); - _tree.removeIcon(_item); - _tree.addIcon(_item, {icon: 'icon-server-connecting'}); + if (!_status) { + _tree.setLeaf(_item); + _tree.removeIcon(_item); + _tree.addIcon(_item, {icon: 'icon-server-connecting'}); + } $.ajax({ type: 'POST', @@ -810,38 +908,51 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { url: _url, data: $('#frmPassword').serialize(), success: function(res) { - return onSuccess( - res, _model, _sdata, _tree, _item + return _onSuccess( + res, _model, _data, _tree, _item, _status ); }, error: function(xhr, status, error) { - return onFailure( - xhr, status, error, _model, _sdata, _tree, _item + return _onFailure( + xhr, status, error, _model, _data, _tree, _item, _status ); } }); } else { - _tree.setInode(_item); - _tree.removeIcon(_item); - _tree.addIcon(_item, {icon: 'icon-server-not-connected'}); + this.onCancel && typeof(this.onCancel) == 'function' && + this.onCancel(_tree, _item, _data, _status); } } }; }); } + var onCancel = function(_tree, _item, _data, _status) { + _data.is_connecting = false; + _tree.unload(_item); + _tree.setInode(_item); + _tree.removeIcon(_item); + _tree.addIcon(_item, {icon: 'icon-server-not-connected'}); + obj.trigger('connect:cancelled', obj, _item, _data); + pgBrowser.Events.trigger('pgadmin:server:connect:cancelled', _item, _data, obj); + _tree.select(_item); + }; + + data.is_connecting = true; url = obj.generate_url(item, "connect", data, true); $.post(url) - .done( - function(res) { - if (res.success == 1) { - return onSuccess(res, obj, data, tree, item); - } - }) - .fail( - function(xhr, status, error) { - return onFailure(xhr, status, error, obj, data, tree, item); - }); + .done(function(res) { + if (res.success == 1) { + return onSuccess( + res, obj, data, tree, item, wasConnected + ); + } + }) + .fail(function(xhr, status, error) { + return onFailure( + xhr, status, error, obj, data, tree, item, wasConnected + ); + }); } /* Send PING to indicate that session is alive */ diff --git a/web/pgadmin/browser/templates/browser/js/collection.js b/web/pgadmin/browser/templates/browser/js/collection.js index 12c80b7d..487f23e 100644 --- a/web/pgadmin/browser/templates/browser/js/collection.js +++ b/web/pgadmin/browser/templates/browser/js/collection.js @@ -114,14 +114,24 @@ function($, _, S, pgAdmin, Backbone, Alertify, Backform) { // Fetch Data collection.fetch({reset: true}) - .error(function(jqxhr, error, message) { + .error(function(xhr, error, message) { + pgBrowser.Events.trigger( + 'pgadmin:collection:retrieval:error', 'properties', xhr, error, message, item, that + ); + if ( + !Alertify.pgHandleItemError(xhr, error, message, {item: item, info: info}) + ) { Alertify.pgNotifier( - error, jqxhr, + error, xhr, S( "{{ _("Error retrieving properties: %s.") }}" - ).sprintf(message).value() - ); - }); + ).sprintf(message).value(), + function() { + console.log(arguments); + } + ); + } + }); }, generate_url: function(item, type, d) { var url = pgAdmin.Browser.URL + '{TYPE}/{REDIRECT}{REF}', diff --git a/web/pgadmin/browser/templates/browser/js/messages.js b/web/pgadmin/browser/templates/browser/js/messages.js index cac7994..da71596 100644 --- a/web/pgadmin/browser/templates/browser/js/messages.js +++ b/web/pgadmin/browser/templates/browser/js/messages.js @@ -14,8 +14,8 @@ function(_, S, pgAdmin) { 'SQL_TAB': '{{ _('SQL') }}', 'SQL_INCOMPLETE': '{{ _('Incomplete definition') }}', 'SQL_NO_CHANGE': '{{ _('Nothing changed')|safe }}', - 'MUST_BE_INT' : "{{ _("'%s' must be an integer.")|safe }}", - 'MUST_BE_NUM' : "{{ _("'%s' must be a numeric.")|safe }}", + 'MUST_BE_INT' : "{{ _("'%s' must be an integer.") }}", + 'MUST_BE_NUM' : "{{ _("'%s' must be a numeric.") }}", 'MUST_GR_EQ' : "{{ _("'%s' must be greater than or equal to %d.")|safe }}", 'MUST_LESS_EQ' : "{{ _("'%s' must be less than or equal to %d.")|safe }}", 'STATISTICS_LABEL': "{{ _("Statistics") }}", @@ -24,12 +24,13 @@ function(_, S, pgAdmin) { 'NODE_HAS_NO_STATISTICS': "{{ _("No statistics are available for the selected object.") }}", 'TRUE': "{{ _("True") }}", 'FALSE': "{{ _("False") }}", - 'NOTE_CTRL_LABEL': "{{ _("Note") }}" + 'NOTE_CTRL_LABEL': "{{ _("Note") }}", + 'ERR_RETRIEVAL_INFO': "{{ _("Error retrieving the information:
%s") }}", + 'CONNECTION_LOST': "{{ _("Connection to the server has been lost!") }}" }; {% for key in current_app.messages.keys() %} - messages['{{ key|safe }}'] = '{{ current_app.messages[key]|safe }}'; - + messages['{{ key }}'] = '{{ current_app.messages[key] }}'; {% endfor %} return pgBrowser.messages; diff --git a/web/pgadmin/browser/templates/browser/js/node.js b/web/pgadmin/browser/templates/browser/js/node.js index 4cc8438..48c24bc 100644 --- a/web/pgadmin/browser/templates/browser/js/node.js +++ b/web/pgadmin/browser/templates/browser/js/node.js @@ -36,6 +36,14 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) { // Make sure - a child have all the callbacks of the parent. child.callbacks = _.extend({}, parent.callbacks, props.callbacks); + var bindToChild = function(cb) { + if (typeof(child.callbacks[cb]) == 'function') { + child.callbacks[cb] = child.callbacks[cb].bind(child); + } + }, + callbacks = _.keys(child.callbacks); + for(var idx = 0; idx < callbacks.length; idx++) bindToChild(callbacks[idx]); + // Registering the node by calling child.Init(...) function child.Init.apply(child); @@ -179,7 +187,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) { // // Used to generate view for the particular node properties, edit, // creation. - getView: function(item, type, el, node, formType, callback, ctx) { + getView: function(item, type, el, node, formType, callback, ctx, cancelFunc) { var that = this; if (!this.type || this.type == '') @@ -268,26 +276,48 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) { } if (!newModel.isNew()) { + var self = this; + // This is definetely not in create mode newModel.fetch() - .success(function(res, msg, xhr) { - // We got the latest attributes of the - // object. Render the view now. - view.render(); - if (type != 'properties') { - $(el).focus(); - } - newModel.startNewSession(); - }) - .error(function(jqxhr, error, message) { - // TODO:: We may not want to continue from here + .success(function(res, msg, xhr) { + // We got the latest attributes of the + // object. Render the view now. + view.render(); + if (type != 'properties') { + $(el).focus(); + } + newModel.startNewSession(); + }) + .error(function(xhr, error, message) { + pgBrowser.Events.trigger( + 'pgadmin:node:retrieval:error', 'properties', + xhr, error, message, item, that + ); + if ( + !Alertify.pgHandleItemError( + xhr, error, message, { + preHandleConnectionLost: function() { + if (cancelFunc) { + cancelFunc(); + } + }, + item: item, + info: info + } + ) + ) { Alertify.pgNotifier( - error, jqxhr, + error, xhr, S( "{{ _("Error retrieving properties: %s.") }}" - ).sprintf(message).value() - ); - }); + ).sprintf(message).value(), + function() { + console.log(arguments); + } + ); + } + }); } else { // Yay - render the view now! $(el).focus(); @@ -1028,7 +1058,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) { }; // Create a view to edit/create the properties in fieldsets - view = that.getView(item, action, content, data, 'dialog', updateButtons, j); + view = that.getView(item, action, content, data, 'dialog', updateButtons, j, onCancelFunc); if (view) { // Save it to release it later j.data('obj-view', view); @@ -1099,7 +1129,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) { if(pnlDependents) $(pnlDependents).removeData('node-prop'); }, - error: function(m, jqxhr) { + error: function(jqxhr) { Alertify.pgNotifier( "error", jqxhr, S( diff --git a/web/pgadmin/misc/depends/static/js/depends.js b/web/pgadmin/misc/depends/static/js/depends.js index 3acd309..648ae01 100644 --- a/web/pgadmin/misc/depends/static/js/depends.js +++ b/web/pgadmin/misc/depends/static/js/depends.js @@ -226,7 +226,29 @@ define( $gridContainer.removeClass('hidden'); // Set the url, fetch the data and update the collection collection.url = url; - collection.fetch({ reset: true }); + collection.fetch({ + reset: true, + error: function(xhr, status, error) { + pgBrowser.Events.trigger( + 'pgadmin:node:retrieval:error', 'depends', xhr, status, error, item, that + ); + if ( + !Alertify.pgHandleItemError(xhr, error, message, { + item: item, info: treeHierarchy + }) + ) { + Alertify.pgNotifier( + status, xhr, + S( + pgBrowser.messages['ERR_RETRIEVAL_INFO'] + ).sprintf(error).value(), + function() { + console.log(arguments); + } + ); + } + } + }); } } if (msg != '') { diff --git a/web/pgadmin/misc/sql/static/js/sql.js b/web/pgadmin/misc/sql/static/js/sql.js index a6db150..7bfcf52 100644 --- a/web/pgadmin/misc/sql/static/js/sql.js +++ b/web/pgadmin/misc/sql/static/js/sql.js @@ -1,6 +1,6 @@ define( - ['underscore', 'jquery', 'pgadmin.browser'], -function(_, $, pgBrowser) { + ['underscore', 'underscore.string', 'jquery', 'pgadmin.browser'], +function(_, S, $, pgBrowser) { pgBrowser.ShowNodeSQL = pgBrowser.ShowNodeSQL || {}; @@ -84,8 +84,25 @@ function(_, $, pgBrowser) { pgAdmin.Browser.editor.setValue(res); } }, - error: function() { - // TODO:: Report this + error: function(xhr, status, error) { + pgBrowser.Events.trigger( + 'pgadmin:node:retrieval:error', 'sql', xhr, status, error, item, that + ); + if ( + !Alertify.pgHandleItemError(xhr, error, message, { + item: item, info: treeHierarchy + }) + ) { + Alertify.pgNotifier( + status, xhr, + S( + pgBrowser.messages['ERR_RETRIEVAL_INFO'] + ).sprintf(error).value(), + function() { + console.log(arguments); + } + ); + } } }); } diff --git a/web/pgadmin/misc/statistics/static/js/statistics.js b/web/pgadmin/misc/statistics/static/js/statistics.js index c1a0327..0beeed3 100644 --- a/web/pgadmin/misc/statistics/static/js/statistics.js +++ b/web/pgadmin/misc/statistics/static/js/statistics.js @@ -1,6 +1,7 @@ -define( - ['underscore', 'jquery', 'pgadmin.browser', 'backgrid', 'wcdocker', 'pgadmin.backgrid'], -function(_, $, pgBrowser, Backgrid) { +define([ + 'underscore', 'underscore.string', 'jquery', 'pgadmin.browser', 'backgrid', + 'wcdocker', 'pgadmin.backgrid' +], function(_, S, $, pgBrowser, Backgrid) { if (pgBrowser.NodeStatistics) return pgBrowser.NodeStatistics; @@ -210,8 +211,25 @@ function(_, $, pgBrowser, Backgrid) { $msgContainer.removeClass('hidden'); } }, - error: function() { - // TODO:: Report this error. + error: function(xhr, status, error) { + pgBrowser.Events.trigger( + 'pgadmin:node:retrieval:error', 'statistics', xhr, status, error, item, that + ); + if ( + !Alertify.pgHandleItemError(xhr, error, message, { + item: item, info: treeHierarchy + }) + ) { + Alertify.pgNotifier( + status, xhr, + S( + pgBrowser.messages['ERR_RETRIEVAL_INFO'] + ).sprintf(error).value(), + function() { + console.log(arguments); + } + ); + } } }); } diff --git a/web/pgadmin/static/js/alertifyjs/pgadmin.defaults.js b/web/pgadmin/static/js/alertifyjs/pgadmin.defaults.js index f1b7472..ce2a677 100644 --- a/web/pgadmin/static/js/alertifyjs/pgadmin.defaults.js +++ b/web/pgadmin/static/js/alertifyjs/pgadmin.defaults.js @@ -185,4 +185,74 @@ function(alertify, S) { this.set('onrestored', alertifyDialogResized); }; + alertify.pgHandleItemError = function(xhr, error, message, args) { + var pgBrowser = window.pgAdmin.Browser; + + if (!xhr || !pgBrowser) { + return; + } + + if (xhr.status == 503) { + var msg = xhr.responseText, + contentType = xhr.getResponseHeader('Content-Type'); + + if (contentType && contentType.indexOf('text/json') == 0) { + try { + resp = $.parseJSON(msg); + + if (resp.info == 'CONNECTION_LOST' && 'server' in args.info) { + if ( + args.preHandleConnectionLost && + typeof(args.preHandleConnectionLost) == 'function' + ) { + args.preHandleConnectionLost.apply(this, arguments); + } + if ('database' in args.info) { + pgBrowser.Events.trigger( + 'pgadmin:database:connection:lost', args.item, resp + ); + } else { + pgBrowser.Events.trigger( + 'pgadmin:server:connection:lost', args.item, resp + ); + } + return true; + } + } catch (e) { + console.log('{{ _("Failed to handle the connection lost!") }}'); + console.log(e); + console.log(arguments); + } + } + } else if (xhr.status == 428) { + var msg = xhr.responseText, + contentType = xhr.getResponseHeader('Content-Type'); + + if (contentType && contentType.indexOf('text/json') == 0) { + try { + resp = $.parseJSON(msg); + + if (resp.errormsg && resp.errormsg == pgBrowser.messages.CONNECTION_LOST) { + if ( + args.preHandleConnectionLost && + typeof(args.preHandleConnectionLost) == 'function' + ) { + args.preHandleConnectionLost.apply(this, arguments); + } + pgBrowser.Events.trigger( + 'pgadmin:database:connection:lost', args.item, resp + ); + return true; + } + console.log(resp); + } catch (e) { + console.log('{{ _("Failed to handle the connection lost!") }}'); + console.log(e); + console.log(arguments); + } + } + } + return false; + }; + });