all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/2] ui: RemoteEdit: remove port field and parse it from host field
Date: Thu,  1 Oct 2020 09:57:57 +0200	[thread overview]
Message-ID: <20201001075757.26446-5-d.csapak@proxmox.com> (raw)
In-Reply-To: <20201001075757.26446-1-d.csapak@proxmox.com>

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>
---
 www/window/RemoteEdit.js | 58 ++++++++++++++++++++++++++++++++++------
 1 file changed, 50 insertions(+), 8 deletions(-)

diff --git a/www/window/RemoteEdit.js b/www/window/RemoteEdit.js
index 7d0ea546..bf5c11fc 100644
--- a/www/window/RemoteEdit.js
+++ b/www/window/RemoteEdit.js
@@ -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);
-- 
2.20.1





      parent reply	other threads:[~2020-10-01  7:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-01  7:57 [pbs-devel] [PATCH widget-toolkit/proxmox-backup] improve ipv6/ports for remotes gui Dominik Csapak
2020-10-01  7:57 ` [pbs-devel] [PATCH widget-toolkit 1/2] Utils: improve matching groups of ip/host regexes Dominik Csapak
2020-10-01  8:10   ` [pbs-devel] applied: " Dietmar Maurer
2020-10-01  7:57 ` [pbs-devel] [PATCH widget-toolkit 2/2] Toolkit: add HostPort vtype Dominik Csapak
2020-10-01  7:57 ` [pbs-devel] [PATCH proxmox-backup 1/2] ui: RemoteView: improve host columns Dominik Csapak
2020-10-01  8:12   ` [pbs-devel] applied: " Dietmar Maurer
2020-10-01  7:57 ` Dominik Csapak [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201001075757.26446-5-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal