17cced50b7
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>
87 lines
1.6 KiB
JavaScript
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();
|
|
}
|
|
});
|
|
|