Allow a node to have two types of parents, modified the code to handle
such situation. This has been modified specifically for the children under the schema, and catalog nodes. Also, override the Backform.Control.prototype.render function to allow to provide the control data to the evaluable functions (i.e. disabled, visible, required).pull/3/head
parent
84843f8c37
commit
ec7e98e6a7
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue