[pve-devel] [PATCH manager] change hotplugselector to checkboxes

Dominik Csapak d.csapak at proxmox.com
Wed May 11 11:40:31 CEST 2016


the hotplugselector was not good to use,
and the options were confusing (empty was the default value, etc)

now we have checkboxes for each value, and if none are selected,
hotplug is disabled

also fixes the renderer when hotplug is set to '1' which
just means the default of 'disk,network,usb'

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/Utils.js                       |  4 ++
 www/manager6/form/HotplugFeatureSelector.js | 76 ++++++++++++++---------------
 2 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index bc52af1..7fd0298 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -112,6 +112,10 @@ Ext.define('PVE.Utils', { statics: {
 	    return gettext('disabled');
 	}
 
+	if (value === '1') {
+	    value = 'disk,network,usb';
+	}
+
 	Ext.each(value.split(','), function(el) {
 	    if (el === 'disk') {
 		fa.push(gettext('Disk'));
diff --git a/www/manager6/form/HotplugFeatureSelector.js b/www/manager6/form/HotplugFeatureSelector.js
index 024471f..71187cf 100644
--- a/www/manager6/form/HotplugFeatureSelector.js
+++ b/www/manager6/form/HotplugFeatureSelector.js
@@ -1,51 +1,47 @@
 Ext.define('PVE.form.HotplugFeatureSelector', {
-    extend: 'PVE.form.KVComboBox',
-    alias: ['widget.pveHotplugFeatureSelector'],
+    extend: 'Ext.form.CheckboxGroup',
+    alias: 'widget.pveHotplugFeatureSelector',
 
-    multiSelect: true,
-    allowBlank: true,
-    deleteEmpty: false,
-    comboItems: [['disk', gettext('Disk')],
-	['network',  gettext('Network')],
-	['usb',  gettext('USB')],
-	['memory',  gettext('Memory')],
-	['cpu',  gettext('CPU')]],
+    columns: 1,
+    vertical: true,
+    items: [
+	{ boxLabel: gettext('Disk'),    name: 'hotplug', inputValue: 'disk',   submitValue: false, checked: true },
+	{ boxLabel: gettext('Network'), name: 'hotplug', inputValue: 'network',submitValue: false, checked: true },
+	{ boxLabel: gettext('USB'),     name: 'hotplug', inputValue: 'usb',    submitValue: false, checked: true },
+	{ boxLabel: gettext('Memory'),  name: 'hotplug', inputValue: 'memory', submitValue: false },
+	{ boxLabel: gettext('CPU'),     name: 'hotplug', inputValue: 'cpu',    submitValue: false }
+    ],
 
-    setValue: function(value, doSelect) {
+    setValue: function(value) {
 	var me = this;
-
-	if (me.multiSelect && Ext.isString(value)) {
-	    var newVal;
-	    if (value === '0') {
-		newVal = [];
-	    } else if (value === '1') {
-		newVal = ['disk', 'network', 'usb'];
-	    } else {
-		newVal = value.split(',');
-	    }
-	    me.callParent([newVal, doSelect]);
+	var newVal = [];
+	if (value === '1') {
+	    newVal = ['disk', 'network', 'usb'];
+	} else if (value !== '0') {
+	    newVal = value.split(',');
 	}
-
-	me.callParent([value, doSelect]);
+	me.callParent([{ hotplug: newVal }]);
     },
 
+    // overide framework function to
+    // assemble the hotplug value
     getSubmitData: function() {
-        var me = this,
-            data = null,
-            val;
-        if (!me.disabled && me.submitValue) {
-            val = me.getSubmitValue();
-	    if (Ext.isArray(val)) {
-		val = val.join(',') || '0';
-	    }
-            if (val !== null && val !== '') {
-                data = {};
-                data[me.getName()] = val;
-            } else if (me.deleteEmpty) {
-		data = {};
-                data['delete'] = me.getName();
+	var me = this,
+	boxes = me.getBoxes(),
+	data = [];
+	Ext.Array.forEach(boxes, function(box){
+	    if (box.getValue()) {
+		data.push(box.inputValue);
 	    }
-        }
-        return data;
+	});
+
+	/* because above is hotplug an array */
+	/*jslint confusion: true*/
+	if (data.length === 0) {
+	    return { 'hotplug':'0' };
+	} else {
+	    return { 'hotplug': data.join(',') };
+	}
     }
+
 });
-- 
2.1.4





More information about the pve-devel mailing list