[pve-devel] [PATCH manager 2/2] ui: vm/usbedit: refactor usb3 checkbox handling

Aaron Lauterer a.lauterer at proxmox.com
Wed Sep 25 14:30:55 CEST 2019


USB3 checkbox was always checked if the device / port supports USB3
even though USB3 was disabled on purpose.

The behaviour now is that for an existing configuration the checkbox
reflects what is set. When selecting a device or port that is not the
configured one the checkbox reflects the USB3 support of the selected
device / port.

Signed-off-by: Aaron Lauterer <a.lauterer at proxmox.com>
---

What started out to fix the problem discussed in the previous patch
series [0] turned into a refactoring of the controller.

I hope I got the regexes right.

Since we do not disable the USB3 checkbox anymore I am not sure why we
kept the whole if else clause around `savedVal`.


[0]: https://pve.proxmox.com/pipermail/pve-devel/2019-September/039111.html

 www/manager6/qemu/USBEdit.js | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/www/manager6/qemu/USBEdit.js b/www/manager6/qemu/USBEdit.js
index f41c3d21..73df7b30 100644
--- a/www/manager6/qemu/USBEdit.js
+++ b/www/manager6/qemu/USBEdit.js
@@ -17,19 +17,19 @@ Ext.define('PVE.qemu.USBInputPanel', {
 		change: function(field, newValue, oldValue) {
 		    var usb3field = this.lookupReference('usb3');
 		    var usbval = field.getUSBValue();
-		    var dev_is_usb3 = /usb3=1/.test(usbval);
-
-		    if (dev_is_usb3) {
-			usb3field.savedVal = usb3field.getValue();
-			usb3field.setValue(true);
+		    var confid = this.view.confid;
+		    var vmconfig = this.view.vmconfig[confid];
+		    var dev_is_usb3 = false;
+		    var hostregex = /host=([^,]*)/;
+
+		    if (/^host/.test(vmconfig) &&
+			vmconfig.match(hostregex)[1] === usbval.match(hostregex)[1]) {
+			dev_is_usb3 = /usb3=1/.test(vmconfig);
 		    } else {
-			if (usb3field.savedVal !== undefined) {
-			    usb3field.setValue(usb3field.savedVal);
-			} else {
-			    usb3field.setValue(usb3field.originalValue);
-			}
-			usb3field.setDisabled(false);
+			dev_is_usb3 = /usb3=1/.test(usbval);
 		    }
+
+		    usb3field.setValue(dev_is_usb3);
 		}
 	    }
 	}
-- 
2.20.1





More information about the pve-devel mailing list