diff --git a/web/pgadmin/browser/templates/browser/js/browser.js b/web/pgadmin/browser/templates/browser/js/browser.js index a663ae8..28ee938 100644 --- a/web/pgadmin/browser/templates/browser/js/browser.js +++ b/web/pgadmin/browser/templates/browser/js/browser.js @@ -1084,7 +1084,8 @@ function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) { } }.bind(ctx), deleteNode = function() { - var pI = this.pI, + var self = this, + pI = this.pI, findParent = function() { if (pI.length) { pI.pop(); @@ -1110,30 +1111,111 @@ function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) { this.i && this.d && this.old._id == this.d._id && this.old._type == this.d._type ) { - this.t.remove(this.i); + var _parent = this.t.parent(this.i) || null; - // Find the parent - findParent(); - var _parentData = this.d; - // Find the grand-parent, or the collection node of parent. - findParent(); + // If there is no parent then just update the node + if(_parent.length == 0) { + updateNode(); + } else { + // If there is a parent then we can remove the node + this.t.remove(this.i, { + success: function() { + // If server group have no children then close it and set inode + // and unload it so it can fetch new data on next expand + if (self.new._type == 'server' + && self.d._type == 'server-group' + && _parent && self.t.children(_parent).length == 0) { + self.t.setInode(_parent, { + success: function() { + self.t.unload(_parent); + } + }); + } + }}); - if (this.i) { - this.load = true; + // Find the parent + findParent(); - this.success = function() { - addItemNode(); - }.bind(this); - // We can refresh the collection node, but - let's not bother about - // it right now. - this.notFound = errorOut; + // If this is Server node + if (this.new._type == 'server' && this.d._type == 'server-group') { + var parent = null; + // We need to search in all parent siblings (eg: server groups) + parents = this.t.siblings(this.i) || []; + parents.push(this.i[0]) + _.each(parents, function (p) { + var d = self.t.itemData($(p)); + // If new server group found then assign it parent + if(d._id == self.new._pid) { + parent = p; + self.pI.push({coll: true, item: parent, d: d}); + } + }); - // Find the new parent - this.b._findTreeChildNode( - this.i, {_id: this.new._pid, _type: _parentData._type}, this - ); + if (parent) { + this.load = true; + + this.success = function() { + addItemNode(); + }.bind(this); + // We can refresh the collection node, but - let's not bother about + // it right now. + this.notFound = errorOut; + + var _d = {_id: this.new._pid, _type: self.d._type} + parent = $(parent), + loaded = this.t.wasLoad(parent), + onLoad = function() { + self.i = parent; + self.d = self.d; + self.pI.push({coll: false, item: parent, d: self.d}); + self.success(); + return; + }; + + if (!loaded && self.load) { + self.t.open(parent, { + success: onLoad, + unanimated: true, + fail: function() { + var fail = self && self.o && self.o.fail; + + if ( + fail && typeof(fail) == 'function' + ) { + fail.apply(self.t, []); + } + } + }); + } else { + onLoad(); + } + } + return; + } else { + // This is for rest of the nodes + var _parentData = this.d; + // Find the grand-parent, or the collection node of parent. + findParent(); + + if (this.i) { + this.load = true; + + this.success = function() { + addItemNode(); + }.bind(this); + // We can refresh the collection node, but - let's not bother about + // it right now. + this.notFound = errorOut; + + // Find the new parent + this.b._findTreeChildNode( + this.i, {_id: this.new._pid, _type: _parentData._type}, this + ); + } + return; } - return; + } + } errorOut(); @@ -1198,22 +1280,13 @@ function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) { node_data._id = _id = this.new._id; } if (this.new._id == _id) { - // Found the currect + // Found the current _.extend(this.d, this.new._id); this.t.setLabel(ctx.i, {label: this.new.label}); this.t.addIcon(ctx.i, {icon: this.new.icon}); this.t.setId(ctx.id, {id: this.new.id}); - - // if label is different then we need to - // refresh parent so that node get properly - // placed in tree - if(this.d.label != this.new.label) { - var p = this.t.parent(this.i); - pgAdmin.Browser.onRefreshTreeNode(p); - } - - self.t.openPath(self.i); - self.t.deselect(self.i); + this.t.openPath(this.i); + this.t.deselect(this.i); // select tree item after few milliseconds setTimeout(function() { @@ -1283,7 +1356,7 @@ function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) { d = ctx.t.itemData(i); if ( pgAdmin.natural_sort( - d._label, _data._label + d._label, _new._label ) == 1 ) return true; @@ -1302,7 +1375,7 @@ function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) { d = ctx.t.itemData(i); if ( pgAdmin.natural_sort( - d._label, _data._label + d._label, _new._label ) != -1 ) return true; @@ -1310,14 +1383,14 @@ function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) { d = ctx.t.itemData(i); if ( pgAdmin.natural_sort( - d._label, _data._label + d._label, _new._label ) != 1 ) return true; m = s + Math.round((e - s) / 2); i = items.eq(m); d = ctx.t.itemData(i); - var res = pgAdmin.natural_sort(d._label, _data._label); + var res = pgAdmin.natural_sort(d._label, _new._label); if (res == 0) return true; @@ -1412,7 +1485,7 @@ function(require, $, _, S, Bootstrap, pgAdmin, Alertify, CodeMirror) { ctx.pI.push(_old); _new._label = _new.label; _new.label = _.escape(_new.label); - if (_old._pid != _new._pid) { + if (_old._pid != _new._pid || _old._label != _new._label) { ctx.op = 'RECREATE'; traversePath(); } else {