pve-manager/www/manager6/form/IPRefSelector.js
Thomas Lamprecht 17cced50b7 ui: IPRef field: allow all valid IPs, even if not in the store
since commit 1ccb53ecdbd69a0e4c57a6d861da1918d3625e08 from widget
toolkit[0] we enforce by default that an entered value needs to be in
the backing data store, else the field is marked invalid.

But, for the firewall source/destination IP selector we do not care
if it's in the store, which is only loaded for convenience and to
allow selecting defined aliases/ipsets

[0]: https://git.proxmox.com/?p=proxmox-widget-toolkit.git;a=commit;h=1ccb53ecdbd69a0e4c57a6d861da1918d3625e08

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-08-30 18:55:58 +02:00

87 lines
1.6 KiB
JavaScript

Ext.define('PVE.form.IPRefSelector', {
extend: 'Proxmox.form.ComboGrid',
alias: ['widget.pveIPRefSelector'],
base_url: undefined,
preferredValue: '', // hack: else Form sets dirty flag?
ref_type: undefined, // undefined = any [undefined, 'ipset' or 'alias']
valueField: 'ref',
displayField: 'ref',
notFoundIsValid: true,
initComponent: function() {
var me = this;
if (!me.base_url) {
throw "no base_url specified";
}
var url = "/api2/json" + me.base_url;
if (me.ref_type) {
url += "?type=" + me.ref_type;
}
var store = Ext.create('Ext.data.Store', {
autoLoad: true,
fields: [ 'type', 'name', 'ref', 'comment' ],
idProperty: 'ref',
proxy: {
type: 'proxmox',
url: url
},
sorters: {
property: 'ref',
order: 'DESC'
}
});
var disable_query_for_ips = function(f, value) {
if (value === null ||
value.match(/^\d/)) { // IP address starts with \d
f.queryDelay = 9999999999; // hack: disable with long delay
} else {
f.queryDelay = 10;
}
};
var columns = [];
if (!me.ref_type) {
columns.push({
header: gettext('Type'),
dataIndex: 'type',
hideable: false,
width: 60
});
}
columns.push(
{
header: gettext('Name'),
dataIndex: 'ref',
hideable: false,
width: 140
},
{
header: gettext('Comment'),
dataIndex: 'comment',
renderer: Ext.String.htmlEncode,
flex: 1
}
);
Ext.apply(me, {
store: store,
listConfig: { columns: columns }
});
me.on('change', disable_query_for_ips);
me.callParent();
}
});