[pve-devel] [PATCH manager 2/5] Add audio device support to HardwareView

Aaron Lauterer a.lauterer at proxmox.com
Mon Jul 15 15:34:12 CEST 2019


Including:

* permission checks
* disable button to add a new audio device if one already exists

Signed-off-by: Aaron Lauterer <a.lauterer at proxmox.com>
---
 www/manager6/qemu/HardwareView.js | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/www/manager6/qemu/HardwareView.js b/www/manager6/qemu/HardwareView.js
index 20f54cbe..09d5d41f 100644
--- a/www/manager6/qemu/HardwareView.js
+++ b/www/manager6/qemu/HardwareView.js
@@ -270,6 +270,15 @@ Ext.define('PVE.qemu.HardwareView', {
 		header: gettext('Serial Port') + ' (' + confid + ')'
 	    };
 	}
+	rows.audio0 = {
+	    confid: "audio0",
+	    group: 40,
+	    tdCls: 'pve-itype-icon-audio',
+	    editor: caps.vms['VM.Config.HWType'] ? 'PVE.qemu.AudioEdit' : undefined,
+	    never_delete: caps.vms['VM.Config.HWType'] ? false : true,
+	    header: gettext('Audio Device'),
+	    renderer: PVE.Utils.render_audio_device
+	};
 	for (i = 0; i < 256; i++) {
 	    rows["unused" + i.toString()] = {
 		group: 99,
@@ -543,6 +552,7 @@ Ext.define('PVE.qemu.HardwareView', {
 	    // en/disable usb add button
 	    var usbcount = 0;
 	    var pcicount = 0;
+	    var audiocount = 0;
 	    var hasCloudInit = false;
 	    me.rstore.getData().items.forEach(function(item){
 		if (/^usb\d+/.test(item.id)) {
@@ -550,6 +560,9 @@ Ext.define('PVE.qemu.HardwareView', {
 		} else if (/^hostpci\d+/.test(item.id)) {
 		    pcicount++;
 		}
+		else if (/^audio\d+/.test(item.id)) {
+		    audiocount++;
+		}
 		if (!hasCloudInit && /vm-.*-cloudinit/.test(item.data.value)) {
 		    hasCloudInit = true;
 		}
@@ -557,9 +570,11 @@ Ext.define('PVE.qemu.HardwareView', {
 
 	    // heuristic only for disabling some stuff, the backend has the final word.
 	    var noSysConsolePerm = !caps.nodes['Sys.Console'];
+	    var noVMConfigHWTypePerm = !caps.vms['VM.Config.HWType'];
 
 	    me.down('#addusb').setDisabled(noSysConsolePerm || (usbcount >= 5));
 	    me.down('#addpci').setDisabled(noSysConsolePerm || (pcicount >= 4));
+	    me.down('#addaudio').setDisabled(noVMConfigHWTypePerm || (audiocount >= 1));
 	    me.down('#addci').setDisabled(noSysConsolePerm || hasCloudInit);
 
 	    if (!rec) {
@@ -704,6 +719,21 @@ Ext.define('PVE.qemu.HardwareView', {
 				    win.on('destroy', reload);
 				    win.show();
 				}
+			    },
+			    {
+				text: gettext('Audio Device'),
+				itemId: 'addaudio',
+				iconCls: 'pve-itype-icon-audio',
+				disabled: !caps.vms['VM.Config.HWType'],
+				handler: function() {
+				    var win = Ext.create('PVE.qemu.AudioEdit', {
+					url: '/api2/extjs/' + baseurl,
+					isCreate: true,
+					isAdd: true
+				    });
+				    win.on('destroy', reload);
+				    win.show();
+				}
 			    }
 			]
 		    })
-- 
2.20.1





More information about the pve-devel mailing list