ui: RemoteEdit: remove port field and parse it from host field

use our hostport regexes to parse out a potential port from the host field
and send it individually

this makes for a simpler and cleaner ui

this additionally checks the field for valid input before sending it to
the backend

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-10-01 09:57:57 +02:00 committed by Dietmar Maurer
parent 3784dbf029
commit 0f22f53b36

View File

@ -45,18 +45,45 @@ Ext.define('PBS.window.RemoteEdit', {
{
xtype: 'proxmoxtextfield',
allowBlank: false,
name: 'host',
name: 'hostport',
submitValue: false,
vtype: 'HostPort',
fieldLabel: gettext('Host'),
listeners: {
change: function(field, newvalue) {
let host = newvalue;
let port;
let match = Proxmox.Utils.HostPort_match.exec(newvalue);
if (match === null) {
match = Proxmox.Utils.HostPortBrackets_match.exec(newvalue);
if (match === null) {
match = Proxmox.Utils.IP6_dotnotation_match.exec(newvalue);
}
}
if (match !== null) {
host = match[1];
if (match[2] !== undefined) {
port = match[2];
}
}
field.up('inputpanel').down('field[name=host]').setValue(host);
field.up('inputpanel').down('field[name=port]').setValue(port);
}
}
},
{
xtype: 'proxmoxintegerfield',
allowBlank: true,
minValue: 1,
maxValue: 2**16,
name: 'port',
emptyText: 8007,
xtype: 'proxmoxtextfield',
hidden: true,
name: 'host',
},
{
xtype: 'proxmoxtextfield',
hidden: true,
deleteEmpty: true,
fieldLabel: gettext('Port'),
name: 'port',
},
],
@ -95,6 +122,21 @@ Ext.define('PBS.window.RemoteEdit', {
],
},
setValues: function(values) {
let me = this;
let host = values.host;
if (values.port !== undefined) {
if (Proxmox.Utils.IP6_match.test(host)) {
host = `[${host}]`;
}
host += `:${values.port}`;
}
values.hostport = host;
return me.callParent([values]);
},
getValues: function() {
let me = this;
let values = me.callParent(arguments);