mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Allow to use the url with/without the node id in the node ajax options
control, also - allow to specify the filter function in the nodes-by-id, and nodes-by-name control.
This commit is contained in:
parent
f451bd0a83
commit
aedf970748
@ -20,7 +20,8 @@ function($, _, pgAdmin, Backbone, Backform, Alertify, Node) {
|
|||||||
Backform.SelectControl.extend({
|
Backform.SelectControl.extend({
|
||||||
defaults: _.extend(Backform.SelectControl.prototype.defaults, {
|
defaults: _.extend(Backform.SelectControl.prototype.defaults, {
|
||||||
url: undefined,
|
url: undefined,
|
||||||
transform: undefined
|
transform: undefined,
|
||||||
|
url_with_id: false
|
||||||
}),
|
}),
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
/*
|
/*
|
||||||
@ -42,7 +43,7 @@ function($, _, pgAdmin, Backbone, Backform, Alertify, Node) {
|
|||||||
full_url = node.generate_url.apply(
|
full_url = node.generate_url.apply(
|
||||||
node, [
|
node, [
|
||||||
null, url, this.field.get('node_data'),
|
null, url, this.field.get('node_data'),
|
||||||
false, this.field.get('node_info')
|
this.field.get('url_with_id') || false, this.field.get('node_info')
|
||||||
]),
|
]),
|
||||||
/*
|
/*
|
||||||
* We needs to check, if we have already cached data for this url.
|
* We needs to check, if we have already cached data for this url.
|
||||||
@ -111,19 +112,26 @@ function($, _, pgAdmin, Backbone, Backform, Alertify, Node) {
|
|||||||
first_empty: true,
|
first_empty: true,
|
||||||
empty_value: '-- None --',
|
empty_value: '-- None --',
|
||||||
url: 'nodes',
|
url: 'nodes',
|
||||||
|
filter: undefined,
|
||||||
transform: function(rows) {
|
transform: function(rows) {
|
||||||
var self = this,
|
var self = this,
|
||||||
node = self.field.get('schema_node'),
|
node = self.field.get('schema_node'),
|
||||||
res = [];
|
res = [],
|
||||||
|
filter = self.field.get('filter') || function() { return true; };
|
||||||
|
|
||||||
_.each(rows, function(r) {
|
_.each(rows, function(r) {
|
||||||
|
if (filter(r)) {
|
||||||
|
var l = (_.isFunction(node['node_label']) ?
|
||||||
|
(node['node_label']).apply(node, [r, self.model, self]) :
|
||||||
|
r.label),
|
||||||
|
image: (_.isFunction(node['node_image']) ?
|
||||||
|
(node['node_image']).apply(node, [r, self.model, self]) : node.type);
|
||||||
res.push({
|
res.push({
|
||||||
'value': r._id,
|
'value': r._id,
|
||||||
'node': _.isFunction(node['node_image']) ? (node['node_image']).apply(node, [r, self.model]) : node.type,
|
'node': image,
|
||||||
'label': (_.isFunction(node['node_label']) ?
|
'label': l
|
||||||
(node['node_label']).apply(node, [r, self.model]) :
|
|
||||||
r.label)
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -137,17 +145,22 @@ function($, _, pgAdmin, Backbone, Backform, Alertify, Node) {
|
|||||||
transform: function(rows) {
|
transform: function(rows) {
|
||||||
var self = this,
|
var self = this,
|
||||||
node = self.field.get('schema_node'),
|
node = self.field.get('schema_node'),
|
||||||
res = [];
|
res = [],
|
||||||
|
filter = self.field.get('filter') || function() { return true; };
|
||||||
|
|
||||||
_.each(rows, function(r) {
|
_.each(rows, function(r) {
|
||||||
var l = _.isFunction(node['node_label']) ?
|
if (filter(r)) {
|
||||||
(node['node_label']).apply(node, [r, self.model]) :
|
var l = (_.isFunction(node['node_label']) ?
|
||||||
r.label;
|
(node['node_label']).apply(node, [r, self.model, self]) :
|
||||||
|
r.label),
|
||||||
|
image: (_.isFunction(node['node_image']) ?
|
||||||
|
(node['node_image']).apply(node, [r, self.model, self]) : node.type);
|
||||||
res.push({
|
res.push({
|
||||||
'value': l,
|
'value': l,
|
||||||
'node': _.isFunction(node['node_image']) ? (node['node_image']).apply(node, [r, self.model]) : node.type,
|
'node': image,
|
||||||
'label': l
|
'label': l
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user