mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Allow to make change the behaviour of backform control based on other
attribute value.
This commit is contained in:
parent
544284ba89
commit
6ef2384e7f
@ -14,6 +14,6 @@ wcDocker 1cd2466afb MIT https://github.com/WebCabin/wcDocker
|
|||||||
Require.js 2.1.18 BSD/MIT http://requirejs.org/
|
Require.js 2.1.18 BSD/MIT http://requirejs.org/
|
||||||
Underscore.js 1.8.3 MIT http://underscorejs.org/
|
Underscore.js 1.8.3 MIT http://underscorejs.org/
|
||||||
Underscore.string 387ab72d49 MIT http://epeli.github.io/underscore.string/
|
Underscore.string 387ab72d49 MIT http://epeli.github.io/underscore.string/
|
||||||
Backform.js 6270ec07e2 MIT https://github.com/AmiliaApp/backform
|
Backform.js 5859b4f9db MIT https://github.com/AmiliaApp/backform
|
||||||
font-Awesome 4.3 SIL OFL http://fortawesome.github.io/Font-Awesome/
|
font-Awesome 4.3 SIL OFL http://fortawesome.github.io/Font-Awesome/
|
||||||
font-mfizz 1.2 MIT http://fizzed.com/oss/font-mfizz
|
font-mfizz 1.2 MIT http://fizzed.com/oss/font-mfizz
|
||||||
|
@ -46,7 +46,7 @@ OWNER TO helpdesk;\n';
|
|||||||
|
|
||||||
if (this.isVisible()) {
|
if (this.isVisible()) {
|
||||||
var obj = pgAdmin.Browser,
|
var obj = pgAdmin.Browser,
|
||||||
i = obj.tree.selected(),
|
i = obj.tree ? obj.tree.selected() : undefined,
|
||||||
d = i && i.length == 1 ? obj.tree.itemData(i) : undefined;
|
d = i && i.length == 1 ? obj.tree.itemData(i) : undefined;
|
||||||
|
|
||||||
if (d && obj.Nodes[d._type].callbacks['selected'] &&
|
if (d && obj.Nodes[d._type].callbacks['selected'] &&
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
helpClassName: "help-block",
|
helpClassName: "help-block",
|
||||||
errorClassName: "has-error",
|
errorClassName: "has-error",
|
||||||
helpMessageClassName: "help-block",
|
helpMessageClassName: "help-block",
|
||||||
|
hiddenClassname: "hidden",
|
||||||
|
|
||||||
// Bootstrap 2.3 adapter
|
// Bootstrap 2.3 adapter
|
||||||
bootstrap2: function() {
|
bootstrap2: function() {
|
||||||
@ -183,18 +184,36 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Field model and collection
|
// Field model and collection
|
||||||
// A field maps a model attriute to a control for rendering and capturing user input
|
//
|
||||||
|
// A field maps a model attriute to a control for rendering and capturing
|
||||||
|
// user input.
|
||||||
var Field = Backform.Field = Backbone.Model.extend({
|
var Field = Backform.Field = Backbone.Model.extend({
|
||||||
defaults: {
|
defaults: {
|
||||||
name: "", // Name of the model attribute; accepts "." nested path (e.g. x.y.z)
|
// Name of the model attribute
|
||||||
|
// - It accepts "." nested path (e.g. x.y.z)
|
||||||
|
name: "",
|
||||||
|
// Placeholder for the input
|
||||||
placeholder: "",
|
placeholder: "",
|
||||||
|
// Disable the input control
|
||||||
|
// (Optional - true/false/function returning boolean)
|
||||||
|
// (Default Value: false)
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
// Visible
|
||||||
|
// (Optional - true/false/function returning boolean)
|
||||||
|
// (Default Value: true)
|
||||||
|
visible: true,
|
||||||
|
// Value Required (validation)
|
||||||
|
// (Optional - true/false/function returning boolean)
|
||||||
|
// (Default Value: true)
|
||||||
required: false,
|
required: false,
|
||||||
value: undefined, // Optional. Default value when model is empty.
|
// Default value for the field
|
||||||
control: undefined, // Control name or class
|
// (Optional)
|
||||||
|
value: undefined,
|
||||||
|
// Control or class name for the control representing this field
|
||||||
|
control: undefined,
|
||||||
formatter: undefined
|
formatter: undefined
|
||||||
},
|
},
|
||||||
initialize: function() {
|
initialize: function(attributes, options) {
|
||||||
var control = Backform.resolveNameToClass(this.get("control"), "Control");
|
var control = Backform.resolveNameToClass(this.get("control"), "Control");
|
||||||
this.set({control: control}, {silent: true});
|
this.set({control: control}, {silent: true});
|
||||||
}
|
}
|
||||||
@ -206,18 +225,22 @@
|
|||||||
|
|
||||||
// Base Control class
|
// Base Control class
|
||||||
var Control = Backform.Control = Backbone.View.extend({
|
var Control = Backform.Control = Backbone.View.extend({
|
||||||
defaults: {}, // Additional field defaults
|
// Additional field defaults
|
||||||
|
defaults: {},
|
||||||
className: function() {
|
className: function() {
|
||||||
return Backform.groupClassName;
|
return Backform.groupClassName;
|
||||||
},
|
},
|
||||||
template: _.template([
|
template: _.template([
|
||||||
'<label class="<%=Backform.controlLabelClassName%>"><%=label%></label>',
|
'<label class="<%=Backform.controlLabelClassName%>"><%=label%></label>',
|
||||||
'<div class="<%=Backform.controlsClassName%>">',
|
'<div class="<%=Backform.controlsClassName%>">',
|
||||||
' <span class="<%=Backform.controlClassName%> uneditable-input"><%=value%></span>',
|
' <span class="<%=Backform.controlClassName%> uneditable-input">',
|
||||||
|
' <%=value%>',
|
||||||
|
' </span>',
|
||||||
'</div>'
|
'</div>'
|
||||||
].join("\n")),
|
].join("\n")),
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
this.field = options.field; // Back-reference to the field
|
// Back-reference to the field
|
||||||
|
this.field = options.field;
|
||||||
|
|
||||||
var formatter = Backform.resolveNameToClass(this.field.get("formatter") || this.formatter, "Formatter");
|
var formatter = Backform.resolveNameToClass(this.field.get("formatter") || this.formatter, "Formatter");
|
||||||
if (!_.isFunction(formatter.fromRaw) && !_.isFunction(formatter.toRaw)) {
|
if (!_.isFunction(formatter.fromRaw) && !_.isFunction(formatter.toRaw)) {
|
||||||
@ -228,7 +251,10 @@
|
|||||||
var attrArr = this.field.get('name').split('.');
|
var attrArr = this.field.get('name').split('.');
|
||||||
var name = attrArr.shift();
|
var name = attrArr.shift();
|
||||||
|
|
||||||
|
// Listen to the field in the model for any change
|
||||||
this.listenTo(this.model, "change:" + name, this.render);
|
this.listenTo(this.model, "change:" + name, this.render);
|
||||||
|
|
||||||
|
// Listen for the field in the error model for any change
|
||||||
if (this.model.errorModel instanceof Backbone.Model)
|
if (this.model.errorModel instanceof Backbone.Model)
|
||||||
this.listenTo(this.model.errorModel, "change:" + name, this.updateInvalid);
|
this.listenTo(this.model.errorModel, "change:" + name, this.updateInvalid);
|
||||||
},
|
},
|
||||||
@ -276,10 +302,27 @@
|
|||||||
value: this.formatter.fromRaw(rawValue, this.model),
|
value: this.formatter.fromRaw(rawValue, this.model),
|
||||||
attributes: attributes,
|
attributes: attributes,
|
||||||
formatter: this.formatter
|
formatter: this.formatter
|
||||||
});
|
}),
|
||||||
|
evalF = function(f, m) {
|
||||||
|
return (_.isFunction(f) ? !!f(m) : !!f);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Evaluate the disabled, visible, and required option
|
||||||
|
_.extend(data, {
|
||||||
|
disabled: evalF(data.disabled, this.model),
|
||||||
|
visible: evalF(data.visible, this.model),
|
||||||
|
required: evalF(data.required, 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.$el.html(this.template(data)).addClass(field.name);
|
||||||
this.updateInvalid();
|
this.updateInvalid();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
clearInvalid: function() {
|
clearInvalid: function() {
|
||||||
|
@ -41,23 +41,22 @@
|
|||||||
setGroupContentClassName: "fieldset-content col-xs-12"
|
setGroupContentClassName: "fieldset-content col-xs-12"
|
||||||
});
|
});
|
||||||
|
|
||||||
_.extend(Backform.Field.prototype, {
|
// Override the Backform.Control to allow to track changes in dependencies,
|
||||||
defaults: {
|
// and rerender the View element
|
||||||
name: "", // Name of the model attribute; accepts "." nested path (e.g. x.y.z)
|
var BackformControlInit = Backform.Control.prototype.initialize;
|
||||||
placeholder: "",
|
Backform.Control.prototype.initialize = function() {
|
||||||
disabled: false,
|
BackformControlInit.apply(this, arguments);
|
||||||
required: false,
|
|
||||||
value: undefined, // Optional. Default value when model is empty.
|
|
||||||
control: undefined, // Control name or class
|
|
||||||
formatter: undefined,
|
|
||||||
fields: undefined,
|
|
||||||
},
|
|
||||||
initialize: function() {
|
|
||||||
var control = Backform.resolveNameToClass(this.get("control"), "Control");
|
|
||||||
this.set({control: control}, {silent: true});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
// Listen to the dependent fields in the model for any change
|
||||||
|
var deps = this.field.get('deps');
|
||||||
|
var that = this;
|
||||||
|
if (deps && _.isArray(deps))
|
||||||
|
_.each(deps, function(d) {
|
||||||
|
attrArr = d.split('.');
|
||||||
|
name = attrArr.shift();
|
||||||
|
that.listenTo(that.model, "change:" + name, that.render);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Backform Dialog view (in bootstrap tabbular form)
|
// Backform Dialog view (in bootstrap tabbular form)
|
||||||
// A collection of field models.
|
// A collection of field models.
|
||||||
@ -72,7 +71,7 @@
|
|||||||
var s = opts.schema;
|
var s = opts.schema;
|
||||||
if (s && _.isArray(s)) {
|
if (s && _.isArray(s)) {
|
||||||
this.schema = _.each(s, function(o) {
|
this.schema = _.each(s, function(o) {
|
||||||
if (!(o.fields instanceof Backbone.Collection))
|
if (o.fields && !(o.fields instanceof Backbone.Collection))
|
||||||
o.fields = new Backform.Fields(o.fields);
|
o.fields = new Backform.Fields(o.fields);
|
||||||
o.cId = o.cId || _.uniqueId('pgC_');
|
o.cId = o.cId || _.uniqueId('pgC_');
|
||||||
o.hId = o.hId || _.uniqueId('pgH_');
|
o.hId = o.hId || _.uniqueId('pgH_');
|
||||||
|
Loading…
Reference in New Issue
Block a user