diff --git a/web/pgadmin/browser/templates/browser/js/node.js b/web/pgadmin/browser/templates/browser/js/node.js index a101460d9..544b560e1 100644 --- a/web/pgadmin/browser/templates/browser/js/node.js +++ b/web/pgadmin/browser/templates/browser/js/node.js @@ -243,13 +243,21 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, Backform) { if (!d) return; + var self = this, + isParent = (_.isArray(this.parent_type) ? + function(d) { + return (_.indexOf(self.parent_type, d._type) != -1); + } : function(d) { + return (self.parent_type == d._type); + }); + if (args.action == 'create') { // If we've parent, we will get the information of it for // proper object manipulation. // // You know - we're working with RDBMS, relation is everything // for us. - if (this.parent_type && this.parent_type != d._type) { + if (self.parent_type && !isParent(d._type)) { // In browser tree, I can be under any node, But - that // does not mean, it is my parent. // @@ -263,7 +271,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, Backform) { i = t.parent(i); pd = t.itemData(i); - if (this.parent_type == pd._type) { + if (isParent(pd._type)) { // Assign the data, this is my actual parent. d = pd; break; @@ -276,8 +284,7 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, Backform) { // The only node - which I know - who does not have parent // node, is the Server Group (and, comes directly under root // node - which has no parent.) - if (!d || (d._type != this.parent_type && - this.parent_type != null)) { + if (!d || (this.parent_type != null && !isParent(d._type))) { // It should never come here. // If it is here, that means - we do have some bug in code. return; diff --git a/web/pgadmin/static/js/backform.pgadmin.js b/web/pgadmin/static/js/backform.pgadmin.js index ba5b6693c..da3e0f348 100644 --- a/web/pgadmin/static/js/backform.pgadmin.js +++ b/web/pgadmin/static/js/backform.pgadmin.js @@ -156,6 +156,47 @@ }); }; + /* + * Overriding the render function of the control to allow us to eval the + * values properly. + */ + Backform.Control.prototype.render = function() { + render: function() { + var field = _.defaults(this.field.toJSON(), this.defaults), + attributes = this.model.toJSON(), + attrArr = field.name.split('.'), + name = attrArr.shift(), + path = attrArr.join('.'), + rawValue = this.keyPathAccessor(attributes[name], path), + data = _.extend(field, { + rawValue: rawValue, + value: this.formatter.fromRaw(rawValue, this.model), + attributes: attributes, + formatter: this.formatter + }), + evalF = function(f, d, m) { + return (_.isFunction(f) ? !!f.apply(d, [m]) : !!f); + }; + + // Evaluate the disabled, visible, and required option + _.extend(data, { + disabled: evalF(data.disabled, data, this.model), + visible: evalF(data.visible, data, this.model), + required: evalF(data.required, data, this.model) + }); + + // Clean up first + this.$el.removeClass(Backform.hiddenClassname); + + if (!data.visible) + this.$el.addClass(Backform.hiddenClassname); + + this.$el.html(this.template(data)).addClass(field.name); + this.updateInvalid(); + + return this; + }; + /* * Overriding the render function of the select control to allow us to use * options as function, which should return array in the format of