From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dcsapak@zita.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 7954362B01
 for <pbs-devel@lists.proxmox.com>; Thu,  1 Oct 2020 09:57:59 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 61DA41E9E1
 for <pbs-devel@lists.proxmox.com>; Thu,  1 Oct 2020 09:57:59 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 237BD1E9CC
 for <pbs-devel@lists.proxmox.com>; Thu,  1 Oct 2020 09:57:58 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id E062745B70
 for <pbs-devel@lists.proxmox.com>; Thu,  1 Oct 2020 09:57:57 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Thu,  1 Oct 2020 09:57:57 +0200
Message-Id: <20201001075757.26446-5-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20201001075757.26446-1-d.csapak@proxmox.com>
References: <20201001075757.26446-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.146 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery
 methods
 NO_DNS_FOR_FROM         0.379 Envelope sender has no MX or A DNS records
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_NONE                0.001 SPF: sender does not publish an SPF Record
Subject: [pbs-devel] [PATCH proxmox-backup 2/2] ui: RemoteEdit: remove port
 field and parse it from host field
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 01 Oct 2020 07:57:59 -0000

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