From b9571df4de14a72b2b102147c8981b6a77b20daa Mon Sep 17 00:00:00 2001 From: Murtuza Zabuawala Date: Tue, 18 Oct 2016 12:37:44 +0100 Subject: [PATCH] Don't append new objects to the wrong parent, if the correct one isn't loaded. Fixes #1838 --- .../browser/templates/browser/js/browser.js | 18 +++++++++++++++--- .../browser/templates/browser/js/node.js | 13 ++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/web/pgadmin/browser/templates/browser/js/browser.js b/web/pgadmin/browser/templates/browser/js/browser.js index 3652ec502..d11dc0fad 100644 --- a/web/pgadmin/browser/templates/browser/js/browser.js +++ b/web/pgadmin/browser/templates/browser/js/browser.js @@ -936,13 +936,25 @@ function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) { }); } else { var _append = function() { - var ctx = this; + var ctx = this, + is_parent_loaded_before = ctx.t.wasLoad(ctx.i), + _parent_data = ctx.t.itemData(ctx.i); + ctx.t.append(ctx.i, { itemData: _data, success: function(item, options) { var i = $(options.items[0]); - ctx.t.openPath(i); - ctx.t.select(i); + // Open the item path only if its parent is loaded + // or parent type is same as nodes + if(_parent_data._type.search(_data._type) > -1 || + is_parent_loaded_before) { + ctx.t.openPath(i); + ctx.t.select(i); + } else { + // Unload the parent node so that we'll get + // latest data when we try to expand it + ctx.t.unload(ctx.i); + } if ( ctx.o && ctx.o.success && typeof(ctx.o.success) == 'function' diff --git a/web/pgadmin/browser/templates/browser/js/node.js b/web/pgadmin/browser/templates/browser/js/node.js index 57b46e54a..f82f04b19 100644 --- a/web/pgadmin/browser/templates/browser/js/node.js +++ b/web/pgadmin/browser/templates/browser/js/node.js @@ -170,9 +170,16 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) { if (itemData.type == 'role' && parentData.server.user.can_create_role) { return true; - } else if (parentData.server.user.is_superuser || - parentData.server.user.can_create_db || - (parentData.schema && parentData.schema.can_create)) { + } else if ( + ( + parentData.server && ( + parentData.server.user.is_superuser || + parentData.server.user.can_create_db) + ) || + ( + parentData.schema && parentData.schema.can_create + ) + ) { return true; } else { return false;